Skip to content

Commit

Permalink
Merge pull request #171 from Azure/dns-script
Browse files Browse the repository at this point in the history
Update Script To Identify Changes
  • Loading branch information
jbjordan committed Feb 13, 2024
2 parents 9011fd2 + a767e5b commit c9c814b
Showing 1 changed file with 61 additions and 11 deletions.
72 changes: 61 additions & 11 deletions tools/GetNamespaceInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function Get-SBNamespaceInfo
[string]$ns
)
{
$future = "FUTURE"
if (!$ns.Contains("."))
{
$ns = $ns + ".servicebus.windows.net"
Expand All @@ -26,15 +27,20 @@ function Get-SBNamespaceInfo
{
$Deployment = $Deployment.Substring(7)
}
if ($Deployment.StartsWith("NS-"))
if ($Deployment.StartsWith("NS-"))
{
$Deployment = $Deployment.Substring(3)
}
if (!($Deployment -like "*-v*")){
$checkForNewNodes = $True
}

$DirectAddresses = @()
$GvDirectAddresses = @()
$instances = 0..127
$ParentDomain = $ns.Substring($ns.IndexOf('.') + 1)
$GatewayDnsFormat = ("g{{0}}-{0}-sb.{1}" -f $Deployment.ToLowerInvariant(), $ParentDomain)
$newNodesAdded = $false
Foreach ($index in $instances)
{
$address = ($GatewayDnsFormat -f $index)
Expand All @@ -44,20 +50,42 @@ function Get-SBNamespaceInfo
$DirectAddress = ($result | Select-Object Name,IPAddress)
$DirectAddresses += $DirectAddress
}
else
{
$temp = New-Object -TypeName PSObject
Add-Member -InputObject $temp -MemberType NoteProperty -Name Name -Value $address
Add-Member -InputObject $temp -MemberType NoteProperty -Name IPAddress -Value $future
$DirectAddress = $temp
$DirectAddresses += $DirectAddress
}
}
$GatewayDnsFormat = ("gv{{0}}-{0}-sb.{1}" -f $Deployment.ToLowerInvariant(), $ParentDomain)
Foreach ($index in $instances)
$oldGatewayDnsFormat = $GatewayDnsFormat
$GatewayDnsFormat = ("gv{{0}}-{0}-sb.{1}" -f $Deployment.ToLowerInvariant(), $ParentDomain)
if($checkForNewNodes)
{
Foreach ($index in $instances)
{
$address = ($GatewayDnsFormat -f $index)
$result = Resolve-DnsName $address -EA SilentlyContinue
if ($result -ne $null)
{
$DirectAddress = ($result | Select-Object Name,IPAddress)
$DirectAddresses += $DirectAddress
if ($result -ne $null)
{
$GvDirectAddress = ($result | Select-Object Name,IPAddress)
$GvDirectAddresses += $GvDirectAddress
}
else
{
$temp = New-Object -TypeName PSObject
Add-Member -InputObject $temp -MemberType NoteProperty -Name Name -Value $address
Add-Member -InputObject $temp -MemberType NoteProperty -Name IPAddress -Value $future
$GvDirectAddress = $temp
$GvDirectAddresses += $GvDirectAddress
}
}
}

$PropertyBag = @{Namespace=$ns;CloudServiceDNS=$CloudServiceDNS;Deployment=$Deployment;CloudServiceVIP=$CloudServiceVIP;GatewayDnsFormat=$GatewayDnsFormat;DirectAddresses=$DirectAddresses}

$Disclaimer = "Entries with 'FUTURE' IPAddress may be added at a later time as needed"

$PropertyBag = @{Namespace=$ns;CloudServiceDNS=$CloudServiceDNS;Deployment=$Deployment;CloudServiceVIP=$CloudServiceVIP;GatewayDnsFormat=$oldGatewayDnsFormat;NewGatewayDnsFormat=$GatewayDnsFormat;DirectAddresses=$DirectAddresses;GvDirectAddresses=$GvDirectAddresses;Notes=$Disclaimer;CheckForNewNodes=$checkForNewNodes}
}

$details = New-Object PSObject -Property $PropertyBag
Expand All @@ -66,11 +94,33 @@ function Get-SBNamespaceInfo

$SBDetails = Get-SBNamespaceInfo $Namespace

$checkForNewNodes = $SBDetails | Select-Object -Property CheckForNewNodes

#Display Summary Info
$SBDetails | Select-Object -Property Namespace,Deployment,CloudServiceDNS,CloudServiceVIP,GatewayDnsFormat | Format-List
if($checkForNewNodes.checkForNewNodes)
{
$SBDetails | Select-Object -Property Namespace,Deployment,CloudServiceDNS,CloudServiceVIP,GatewayDnsFormat,NewGatewayDnsFormat,Notes | Format-List
} else
{
$SBDetails | Select-Object -Property Namespace,Deployment,CloudServiceDNS,CloudServiceVIP,GatewayDnsFormat,Notes | Format-List
}

$newNodesWarning = $SBDetails | Select-Object -Property newNodesAdded

if($checkForNewNodes.checkForNewNodes){
#Update
Write-Host "ATTENTION: New Gateway DNS Format Starting With 'gv...' Detected" -ForegroundColor Yellow
}

if (!$NoIPs.IsPresent)
{
#Dump the list of Direct IP Addresses
$SBDetails.DirectAddresses | Format-Table
}

if($checkForNewNodes.checkForNewNodes){
#Update
Write-Host "ATTENTION: New Gateway DNS Format Starting With 'gv...' Detected" -ForegroundColor Yellow
$SBDetails.GvDirectAddresses | Format-Table
}

}

0 comments on commit c9c814b

Please sign in to comment.