• Home
  • VMware QuickDocs
    • VMware General
    • vSphere
    • Skyline Advisor
    • vSAN
    • Horizon
    • NSX
    • vRealize Suite
      • vRealize Operations
      • Aria Operations for Logs
      • vRealize Automation
      • vRealize Orchestrator
    • VMware Cloud Services
    • Podcasts
  • Home Lab
  • VMware Stickers
  • mac OS Tips
  • About Me
    • Privacy Policy
    • Cookie policy
Cybersylum

Cybersylum

  • Home
  • VMware QuickDocs
    • VMware General
    • vSphere
    • Skyline Advisor
    • vSAN
    • Horizon
    • NSX
    • vRealize Suite
      • vRealize Operations
      • Aria Operations for Logs
      • vRealize Automation
      • vRealize Orchestrator
    • VMware Cloud Services
    • Podcasts
  • Home Lab
  • VMware Stickers
  • mac OS Tips
  • About Me
    • Privacy Policy
    • Cookie policy

Update Network Fabric IP Info in Aria Automation using APIs

byArron King 05.22.2023 Aria Automation PowerCLI

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.

New to this?
Most APIs tend to mirror the organizational constructs you see in VMware products.  In this case, login to vRA Cloud Assembly and go to Infrastructure -> Network Profiles.  When you open a profile, you will see a Networks tab.  This contains the Network Fabrics/vSphere Network Fabrics defined for this profile

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.

Tips
Test 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 directly; but the Invoke-VRARestMethod makes this easier than using REST alone
  • 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

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)

Log Insight Custom SSL Cert Upgrade Issue

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Disclaimer

The content and opinions on this site belong to me - not my employer.

You are welcome to use any ideas or code from this site. You have the responsiblity to test these before using in a production environment.

Upcoming Events

  • Mon
    21
    Aug
    2023
    Thu
    24
    Aug
    2023

    VMware Explore 2023 - US

    The dates for THE big virtualization conference has been announced and VMware Explore is back in Las Vegas for 2023!

  • Tue
    14
    Nov
    2023

    Cincinnati VMUG UserCON

    Your digital transformation is a journey you shouldn’t have to embark on alone.  Join us at the Sharonville Convention Center for an opportunity to learn from experts and each other!

    Register

Categories

Aria Automation Aria Operations for Logs Before I Forget Certificates Education Home Lab Horizon View MacOS Networking PowerCLI Professional Development Scripting TechBITS Update Manager VCSA VMUG VMware VMware Cloud on AWS VMware Portal VMware Tools VMworld vSphere vToolBelt Windows 10

Archives

Category

Aria Automation Aria Operations for Logs Before I Forget Certificates Education Home Lab Horizon View MacOS Networking PowerCLI Professional Development Scripting TechBITS Update Manager VCSA VMUG VMware VMware Cloud on AWS VMware Portal VMware Tools VMworld vSphere vToolBelt Windows 10

Twitter: Follow Me

My Tweets
Proudly powered by WordPress | Theme: Showme by NEThemes.
 

Loading Comments...