Importing vSphere Networks into Aria Automation – Part 1 – Export Networks with Missing IP Info
If you are standing up a new Aria Automation environment and have a large number of vSphere Networks (aka Port Groups), it could take a very long time to enter this information manually. I have written a few scripts that can make Importing vSphere networks into Aria Automation fairly easy!
This blog article is the 1st in a 4-part series that discusses how you can import vSphere Networks into Aria Automation. The environment these scripts were written for has multiple vCenter Server instances – each with multiple clusters. The network infrastructure is using Layer 2 stretched VLANs. As a result the same VLAN can exist in multiple locations. The vSphere Port Groups are all named the same, and have the same characteristics.
Blog Series Overview – Importing vSphere Networks into Aria Automation
- Export Networks with Missing IP Info – This will export a file that can be used to determine which networks need updated. This will be the basis for the other 3 sections as an input file to target updates. This file will need updated with the pertinent IP information.
- Update Network IP Info – This script will use the file created in step 1 to update the IP Information for vSphere networks discovered by Aria Automation
- Update IP Ranges – This script will use the file created in step 1 and define IP Ranges for the subnets used by the discovered vSphere Networks
- Update Network Profiles – The final step is to take the results from the prior 3 steps and create Network Profiles that can be used by Aria Automation for workload deployment
Export Networks with Missing IP Info
Aria Automation will discover vSphere Port Groups that exist in any Cloud Accounts that have been configured. This will create definitions in Infrastructure -> Resources -> Networks -> Networks; but does not necessarily populate the necessary IP Information.
In order to deploy workloads to these environments using Aria Automation, a Network Profile needs to be created. This profile requires Network IP Information and IP Ranges to be defined for each vSphere Network.
The first step is to identify all discovered vSphere Networks that need to have this information updated. While you can certainly click through the GUI and manually update each one, this does not scale well in environments with large numbers of vSphere Port Groups. Manual data entry at this scale also dramatically increases the likelihood of inadvertent errors.
The script below will create a CSV file listing the discovered vSphere Networks in Aria Automation that is missing the basic IP Information required.
- Domain
- IPv4 CIDR
- IPv4 Default Gateway
- DNS Servers
- DNS Search Domains
There are more fields available for each network. If you require these in your environment, it should be a pretty easy task to extend the script to add support for these (IPv6, tags, checkboxes for Public IP/Default for Zone).
The Script
Requirements
- Powershell – written and tested using 7.3.8
- PowervRA – This script was written and tested with Power vRA 6.0. Make sure to use PowervRA 4.x and above. Earlier versions were compatible with vRealize Automation 7.x. The APIs in Aria Automation 8.x are completely different
Usage
You will need to edit the script and enter a few details about your environment:
- $vRAServer – FQDN of the Aria Automation Server
- $vRAUser – name of the user used for authentication to Aria Automation
- $ImportFile – path the the CSV input file
- $RunLog – path the log file
When executed, the script will prompt you to choose a Cloud Account to export from. It can export all; but I have found that working with one Cloud Account at a time is easier.
- The script assumes that all Networks with the same name have the same characteristics. It will update all discovered networks regardless of Cloud Account. For example, if you have 3 Cloud Accounts that all have the same network (VLAN101); but you run through the process in this blog series for 1 Cloud Account and include information on VLAN101 in the input file – All 3 instances of VLAN101 will be updated.
- If you start with the largest cloud account first and run through the entire process with it, you can follow up with other cloud accounts and clean up any one-off networks that exist
Output
The script will create a file with a list of networks that do not have IP information configured in Aria Automation.
For the next steps, you will need to take that data and create an input file with the following column names (exactly as shown). The file should be in the CSV format. This is a manual process and should be validated before proceeding.
- PortGroup (VLAN315)
- Gateway
- SubnetMask
- NetworkAddress
- CIDR
- StartAddr
- LastAddr
If you are new to using APIs with PowerShell, check out my article on Using Aria Automation APIs with PowerShell.
Getting the Code
TipsTest environments are your friend. Make sure your Aria Automation environment is backed up and take snapshots to save yourself time and agony
You can download the script from GitHub.
<# Export-Networks-Empty-CIDR.ps1 This script will export a list of vSphere Networks that have been discovered by Aria Automation which have not been configured with IP Information. The script provides a prompt to allow a choice of all networks or networks associated with a specific Cloud Account. Disclaimer: This script was obtained from https://github.com/cybersylum * You are free to use or modify this code for your own purposes. * No warranty or support for this code is provided or implied. * Use this at your own risk. * Testing is highly recommended. #> # define vars for environment $vRAServer = "vra8.domain.com" $vRAUser = "[email protected]" $DateStamp=Get-Date -format "yyyyMMdd" $TimeStamp=Get-Date -format "hhmmss" $ExportFile = "empty-cidr-networks-$DateStamp-$TimeStamp.csv" #QueryLimit is used to control the max rows returned by invoke-restmethod (which has a default of 100) $QueryLimit=9999 $Error.clear() Write-Host "Connecting to Aria Automation - $vRAServer as $vRAUser" $vRA=connect-vraserver -server $vRAServer -Username "$vRAUser" -IgnoreCertRequirements if ($null -eq $vRA) { write-host "Unable to connect to vRA Server '$vRAServer'..." exit } #Grab the bearer token for use with invoke-restmethod (which is needed for queries with more than 100 results) $APItoken= $vRA.token | ConvertTo-SecureString -AsPlainText -Force $Body = @{ '$top' = $QueryLimit } $APIparams = @{ Method = "GET" Uri = "https://$vRAServer/iaas/api/cloud-accounts" Authentication = "Bearer" Token = $APItoken Body = $Body } try{ $CloudAccounts = (Invoke-RestMethod @APIparams -SkipCertificateCheck).Content } catch { Write-Host $(" Unable to get Cloud Accounts from Aria Automation") Write-Host $Error Write-Host $Error[0].Exception.GetType().FullName } Write-Host "Cloud Accounts found - " $CloudAccounts.Count Write-Host "" Write-Host "Choose a Cloud Account to use for Network Export:" $Index=0 foreach ($Account in $CloudAccounts) { Write-Host " " $Index " - " $Account.Name " ("$Account.id")" $Index++ } Write-Host " 99 - All Cloud Accounts" write-host "" $Choice= Read-host -Prompt 'Enter selection and hit &amp;amp;lt;ENTER&amp;amp;gt; or just &amp;amp;lt;ENTER&amp;amp;gt; to quit' if ($Choice.length -eq 0) { exit } try { $Selection = [int]$Choice } catch { write-host "$Choice is not a valid selection- exiting..." exit } if ($Selection -ne 99) { $InRange = $Selection -In 0..($Index-1) if (-Not $InRange) { write-host "$Choice is not a valid selection- exiting..." exit } } if ($Selection -eq 99) { $DisplayCloudAccountName = "All Cloud Accounts" $CloudAccountID = "" } else { $DisplayCloudAccountName = $CloudAccounts[$Selection].name $CloudAccountID = $CloudAccounts[$Selection].id } #Get All Networks Discovered by vRA - so we can filter later if necessary $Body = @{ '$top' = $QueryLimit } $APIparams = @{ Method = "GET" Uri = "https://$vRAServer/iaas/api/fabric-networks-vsphere" Authentication = "Bearer" Token = $APItoken Body = $Body } try { $Networks = (Invoke-RestMethod @APIparams -SkipCertificateCheck).content } catch { Write-Host $(" Unable to get networks from vRA") Write-Host $Error Write-Host $Error[0].Exception.GetType().FullName } write-host "Networks discovered by vRA - " $Networks.count if ($CloudAccountID -eq "") { #Use All Networks discovered by vRA $FilteredNetworks = $Networks } else { #Filter to matching CloudAccount $FilteredNetworks = $Networks | where-object -Property cloudAccountIds -eq $CloudAccountID } $EmptyNetworks = @() Write-Host "Scanning networks in $DisplayCloudAccountName for missing IP Info - " $FilteredNetworks.Count foreach ($ThisNetwork in $FilteredNetworks) { #write-host $ThisNetwork.name " - " $ThisNetwork.cidr if ($ThisNetwork.cidr.length -eq "") { #write-host $ThisNetwork.name $EmptyNetworks += $ThisNetwork.name } } Write-host "Networks with missing IP info - " $EmptyNetworks.count $EmptyNetworks | out-file -filepath $ExportFile # Clean up write-host "list exported to $ExportFile" Disconnect-vRAServer -Confirm:$false
Next Steps
The next article in the series is Update Network Info on vSphere Networks. It will discuss how to take this information and use it to Update the Network definitions in Aria Automation.