VMware Cloud Community
vMarkusK1985
Expert
Expert
Jump to solution

Report EdgeGateway IP Allocations and SubAllocations

Hello,

I need to report all my EdgeGateway IP Allocations and SubAllocations for a specific Network.

I found some information in the "Get-ExternalNetwork" PowerCLI cmdlet:

(Get-ExternalNetwork -Name myNet).ExtensionData.Configuration.IpScopes.Ipscope.SubAllocations.Suballocation

But I am not able to match them to a EdgeGateway.

Has someone already done something like that before with PowerCLI?

Any hints for me?

In the API I was able to report that:

vCD-Edges.png

If there is no PowerCLI way I will create a REST based PowerShell Function...

Kind Regards,

Markus

https://mycloudrevolution.com | https://twitter.com/vMarkus_K | https://github.com/vMarkusK
Reply
0 Kudos
1 Solution

Accepted Solutions
vMarkusK1985
Expert
Expert
Jump to solution

Thanks AdamRushUK​,

you hint was very useful!

Thanks the Report I need:

## IP range Functins

function Get-IPrange

{

<#

  .SYNOPSIS 

    Get the IP addresses in a range

  .EXAMPLE

   Get-IPrange -start 192.168.8.2 -end 192.168.8.20

  .EXAMPLE

   Get-IPrange -ip 192.168.8.2 -mask 255.255.255.0

  .EXAMPLE

   Get-IPrange -ip 192.168.8.3 -cidr 24

#>

param

(

  [string]$start,

  [string]$end,

  [string]$ip,

  [string]$mask,

  [int]$cidr

)

function IP-toINT64 () {

  param ($ip)

  $octets = $ip.split(".")

  return [int64]([int64]$octets[0]*16777216 +[int64]$octets[1]*65536 +[int64]$octets[2]*256 +[int64]$octets[3])

}

function INT64-toIP() {

  param ([int64]$int)

  return (([math]::truncate($int/16777216)).tostring()+"."+([math]::truncate(($int%16777216)/65536)).tostring()+"."+([math]::truncate(($int%65536)/256)).tostring()+"."+([math]::truncate($int%256)).tostring() )

}

if ($ip) {$ipaddr = [Net.IPAddress]::Parse($ip)}

if ($cidr) {$maskaddr = [Net.IPAddress]::Parse((INT64-toIP -int ([convert]::ToInt64(("1"*$cidr+"0"*(32-$cidr)),2)))) }

if ($mask) {$maskaddr = [Net.IPAddress]::Parse($mask)}

if ($ip) {$networkaddr = new-object net.ipaddress ($maskaddr.address -band $ipaddr.address)}

if ($ip) {$broadcastaddr = new-object net.ipaddress (([system.net.ipaddress]::parse("255.255.255.255").address -bxor $maskaddr.address -bor $networkaddr.address))}

if ($ip) {

  $startaddr = IP-toINT64 -ip $networkaddr.ipaddresstostring

  $endaddr = IP-toINT64 -ip $broadcastaddr.ipaddresstostring

} else {

  $startaddr = IP-toINT64 -ip $start

  $endaddr = IP-toINT64 -ip $end

}

for ($i = $startaddr; $i -le $endaddr; $i++)

{

  INT64-toIP -int $i

}

}

# Get Edge CIView object

$EdgeName = '*'

$EdgeView = Search-Cloud -QueryType EdgeGateway -Name $EdgeName | Get-CIView

$EdgeReport = @()

foreach ($Edge in $EdgeView) {

    [Array]$GatewayInterfaces = $Edge.Configuration.GatewayInterfaces

    foreach($GatewayInterface in $GatewayInterfaces.GatewayInterface){

                $obj = "" | Select-Object EdgeName, NetworkName, IP, IPRanges             

                $obj.EdgeName = $Edge.Name

                $obj.NetworkName = $GatewayInterface.Name

                $obj.IP = $GatewayInterface.SubnetParticipation.IpAddress

                [Array] $RangeReport = @()

                foreach ($IPRange in $GatewayInterface.SubnetParticipation.IpRanges.IpRange) {

                    [Array] $Range = Get-IPrange -start $IPRange.StartAddress -end $IPRange.EndAddress

                    foreach($IP in $Range){ 

                        $RangeReport += $IP

                        }

                    }

                   

                $obj.IPRanges = $RangeReport -join ","

                $EdgeReport += $obj    

                }

               

              

    }

    #$EdgeReport | Export-Csv C:\test.csv -Delimiter ";"

    $EdgeReport | Sort EdgeName, NetworkName | Format-Table -AutoSize

edgeView.png

https://mycloudrevolution.com | https://twitter.com/vMarkus_K | https://github.com/vMarkusK

View solution in original post

Reply
0 Kudos
3 Replies
AdamRushUK
Enthusiast
Enthusiast
Jump to solution

Hi Markus,

Try this PowerCLI:

# Get Edge CIView object

$EdgeName = 'EDGENAME'

$EdgeView = Search-Cloud -QueryType EdgeGateway -Name $EdgeName | Get-CIView


# Display Edge network info

$EdgeView.Configuration.GatewayInterfaces.GatewayInterface | ForEach-Object {$_.SubnetParticipation}

Example output:

Screenshot - 25_03_2017.png

Is that what you were after?

VCP-Cloud | VCP5-DCV | MCITP:EA | MCSE | CCNA | CCAA LinkedIn: https://www.linkedin.com/in/adamrushuk | Twitter : @adamrushuk
vMarkusK1985
Expert
Expert
Jump to solution

Thanks AdamRushUK​,

you hint was very useful!

Thanks the Report I need:

## IP range Functins

function Get-IPrange

{

<#

  .SYNOPSIS 

    Get the IP addresses in a range

  .EXAMPLE

   Get-IPrange -start 192.168.8.2 -end 192.168.8.20

  .EXAMPLE

   Get-IPrange -ip 192.168.8.2 -mask 255.255.255.0

  .EXAMPLE

   Get-IPrange -ip 192.168.8.3 -cidr 24

#>

param

(

  [string]$start,

  [string]$end,

  [string]$ip,

  [string]$mask,

  [int]$cidr

)

function IP-toINT64 () {

  param ($ip)

  $octets = $ip.split(".")

  return [int64]([int64]$octets[0]*16777216 +[int64]$octets[1]*65536 +[int64]$octets[2]*256 +[int64]$octets[3])

}

function INT64-toIP() {

  param ([int64]$int)

  return (([math]::truncate($int/16777216)).tostring()+"."+([math]::truncate(($int%16777216)/65536)).tostring()+"."+([math]::truncate(($int%65536)/256)).tostring()+"."+([math]::truncate($int%256)).tostring() )

}

if ($ip) {$ipaddr = [Net.IPAddress]::Parse($ip)}

if ($cidr) {$maskaddr = [Net.IPAddress]::Parse((INT64-toIP -int ([convert]::ToInt64(("1"*$cidr+"0"*(32-$cidr)),2)))) }

if ($mask) {$maskaddr = [Net.IPAddress]::Parse($mask)}

if ($ip) {$networkaddr = new-object net.ipaddress ($maskaddr.address -band $ipaddr.address)}

if ($ip) {$broadcastaddr = new-object net.ipaddress (([system.net.ipaddress]::parse("255.255.255.255").address -bxor $maskaddr.address -bor $networkaddr.address))}

if ($ip) {

  $startaddr = IP-toINT64 -ip $networkaddr.ipaddresstostring

  $endaddr = IP-toINT64 -ip $broadcastaddr.ipaddresstostring

} else {

  $startaddr = IP-toINT64 -ip $start

  $endaddr = IP-toINT64 -ip $end

}

for ($i = $startaddr; $i -le $endaddr; $i++)

{

  INT64-toIP -int $i

}

}

# Get Edge CIView object

$EdgeName = '*'

$EdgeView = Search-Cloud -QueryType EdgeGateway -Name $EdgeName | Get-CIView

$EdgeReport = @()

foreach ($Edge in $EdgeView) {

    [Array]$GatewayInterfaces = $Edge.Configuration.GatewayInterfaces

    foreach($GatewayInterface in $GatewayInterfaces.GatewayInterface){

                $obj = "" | Select-Object EdgeName, NetworkName, IP, IPRanges             

                $obj.EdgeName = $Edge.Name

                $obj.NetworkName = $GatewayInterface.Name

                $obj.IP = $GatewayInterface.SubnetParticipation.IpAddress

                [Array] $RangeReport = @()

                foreach ($IPRange in $GatewayInterface.SubnetParticipation.IpRanges.IpRange) {

                    [Array] $Range = Get-IPrange -start $IPRange.StartAddress -end $IPRange.EndAddress

                    foreach($IP in $Range){ 

                        $RangeReport += $IP

                        }

                    }

                   

                $obj.IPRanges = $RangeReport -join ","

                $EdgeReport += $obj    

                }

               

              

    }

    #$EdgeReport | Export-Csv C:\test.csv -Delimiter ";"

    $EdgeReport | Sort EdgeName, NetworkName | Format-Table -AutoSize

edgeView.png

https://mycloudrevolution.com | https://twitter.com/vMarkus_K | https://github.com/vMarkusK
Reply
0 Kudos
AdamRushUK
Enthusiast
Enthusiast
Jump to solution

Glad it helped Smiley Happy

VCP-Cloud | VCP5-DCV | MCITP:EA | MCSE | CCNA | CCAA LinkedIn: https://www.linkedin.com/in/adamrushuk | Twitter : @adamrushuk
Reply
0 Kudos