53 lines
1.5 KiB
PowerShell
53 lines
1.5 KiB
PowerShell
|
function New-VIPsHostFileEntries {
|
||
|
<#
|
||
|
.SYNOPSIS
|
||
|
Creates Host File Entries for the Application VIPs using the Supplied IP Prefix
|
||
|
#>
|
||
|
|
||
|
[CmdletBinding()]
|
||
|
Param(
|
||
|
[Parameter(Mandatory = $true)]
|
||
|
[string]$appTierVipPrefix
|
||
|
)
|
||
|
|
||
|
$logLead = (Get-LogLeadName);
|
||
|
$hostsContent = Get-HostsFileContent
|
||
|
$hostsToAdd = @()
|
||
|
|
||
|
foreach ($app in $appTierApplications) {
|
||
|
# First try to resolve by name to see if DNS is handling
|
||
|
# We may be using this approach in AWS
|
||
|
try {
|
||
|
$addresses = Get-IPAddressesForName $app.Name
|
||
|
}
|
||
|
catch {
|
||
|
# No action needed, check is below
|
||
|
$addresses = $null
|
||
|
}
|
||
|
|
||
|
if (!(Test-IsCollectionNullOrEmpty $addresses)) {
|
||
|
Write-Output ("$logLead : IP Address for App {0} Resolved" -f $app.Name)
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
$hostsString = "{0}.{1}{2}{3}"
|
||
|
|
||
|
# This is a redundant check since we're already checking DNS for the Service Name, but it doesn't hurt
|
||
|
if (($hostsContent | Where-Object {$_ -like ($hostsString -f "*", $app.Name)}).Count -gt 0) {
|
||
|
Write-Output ("$logLead : HostsEntry for {0} Already Exists" -f $app.Name)
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
$hostsToAdd += ($hostsString -f $appTierVipPrefix, $app.VIPSuffix, "`t`t", $app.Name)
|
||
|
}
|
||
|
|
||
|
if ($hostsToAdd.Count -gt 0) {
|
||
|
Add-HostsFileContent $hostsToAdd
|
||
|
}
|
||
|
else {
|
||
|
Write-Output "$logLead : No Host File Updates Required"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Set-Alias -name Create-VIPsHostFileEntries -value New-VIPsHostFileEntries;
|