Update Network Fabric IP Info in Aria Automation using APIs
I needed to update a few bits of information for the networks in my on-prem Aria Automation deployment (IPv4 CIDR, default gateway, domain, and DNS Info). It would have been pretty easy to update via the GUI. I thought learning to update Network Fabric IP Info in Aria Automation using APIs would be a great opportunity to learn.
I thought I would share what I found to hopefully help someone new to APIs. This could also be useful if someone needed to make these changes in bulk. Let’s take a look!
Figuring things out
I started by reviewing the Aria Automation API Documentation (also known as the Swagger UI) built into each vRA install (in your environment go to https://your-vra-fqdn.com/automation-us/api/docs). Under the Infrastructure As A Service category, I found some APIs for Network Profiles and vSphere Fabric Networks.
The Swagger UI will help describe how to use the APIs and even provides an interface to test them out. I like using Postman for modeling and testing. It gives me the ability to save collections of API calls and has very useful features which make the process of learning and using APIs much easier.
It took me a little time in Postman to understand how to properly interact with the the APIs to get the results I was looking for.
TipsTest environments are your friend. Back them up and take snapshots to save yourself time and agony
The Script
This script will update Network Fabrics for a specific Network Profile based on input from a CSV file.
Requirements
- Powershell
- PowerVRA – No cmdlet for this operation directly; but the Invoke-VRARestMethod makes this easier than using the generic Invoke-RestMethod built into PowerShell
- CSV with input data (show above)
- Update the script to fill in the specifics for your environment
- Networks in Network profile tagged with VLAN ID. The tag looks like (VLAN:101). I found a great blog describing how to dynamically populate a network selection box on a cloud template. That technique requires the networks be tagged. It was also convenient to use this to link the input file to the right network.
You can download the script from GitHub.
#imports IP information into vSphere network fabrics in vRA # define vars for environment $ImportFile = "fabric-ip-info.csv" $vRAServer = "vra8.domain.com" $NetworkProfileID = "d33d9120-1b57-4e7e-3B8d-e75e35228078" # ProfileID to be updated $vRAUser = "[email protected]" # Load input file if (-not(Test-Path -Path $ImportFile -PathType Leaf)) { write-host "Input file '$ImportFile' not found..." exit } else { $ImportFabricData = import-csv $ImportFile } $vRA=connect-vraserver -server $vRAServer -Username "$vRAUser" if ($null -eq $vRA) { write-host "Unable to connect to vRA Server '$vRAServer'..." exit } # Get Network Profile info and HREFs to it's defined fabrics $NetworkProfile = Invoke-vRARestMethod -Method GET -URI "/iaas/api/network-profiles/$NetworkProfileID" -WebRequest $NetworkFabrics =($NetworkProfile.content | ConvertFrom-Json -AsHashtable)._links.'fabric-networks'.hrefs # Build FabricLookup hashtable based on key details from each defined Fabric # keyed on VLAN ID (from tag on fabric) with HREF to allow update of fabric $FabricLookup = @{} write-host "Building Fabric Lookup table..." $ImportPauseCount = 10 #Execute this many updates and then pause briefly to avoid overloading $Counter=0 # don't change foreach ($FabricRef in $NetworkFabrics) { $FabricInfo = (Invoke-vRARestMethod -method GET -URI "$FabricRef" -webrequest).content | ConvertFrom-Json -AsHashtable $VLAN = $FabricInfo.tags.value $FabricLookup.add($VLAN, $FabricRef) } foreach ($ImportItem in $ImportFabricData) { $FabricURI="" $TargetVLAN = $ImportItem.VLAN_ID $FabricURI=$FabricLookup[$TargetVLAN] if ($null -eq $FabricURI) { write-host Cannot find vRA Network Fabric for import item - VLAN $TargetVLAN } else { write-host "Found vRA Network fabric for import VLAN $TargetVLAN - updating..." #Build out separate vars for each update item $CIDR = $ImportItem.IP_SUBNET $IPGateway = $ImportItem.IP_GATEWAY #following could be hard-coded or calculated $DNS1 = $ImportItem.DNS1 $DNS2 = $ImportItem.DNS2 $DNSSearch = $ImportItem.DNS_SEARCH $Domain = $ImportItem.DOMAIN #build JSON payload - seems to have syntax requirements to be at line position 1 $json = @" { "domain": "$Domain", "defaultGateway": "$IPGateway", "dnsServerAddresses": [ "$DNS1", "$DNS2" ], "dnsSearchDomains": [ "$DNSSearch" ], "cidr": "$CIDR" } "@ #Call Update API - use fabric-networks-vsphere for update $FabricURI = $FabricURI.replace("fabric-networks","fabric-networks-vsphere") $Results=Invoke-vRARestMethod -Method PATCH -URI "$FabricURI" -Body $json #take a quick break every few imports to avoid overload $Counter++ if ($Counter -gt $ImportPauseCount) { write-host "allowing vRA to process (sleeping for 2)" sleep 2 $Counter=0 } } } # Clean up Disconnect-vRAServer -Confirm:$false