API Creation of VRA Network profiles with Infoblox Endpoint

PowerVRA cmdlets for creating external network profiles don’t directly allow for creation of Infoblox connected network profiles. You can still make use of the Invoke-VraRestMethod, but you will need to source some of the required information yourself.

Firstly you will need to get the provider ID for the IPAM endpoint. An easy way to do this is to look at an example network profile that has been connected to the target Infoblox.

$sampleNetworkName = "testnetwork"
$EndpointId = (Get-vRAExternalNetworkProfile -Name $sampleNetworkName).IPAMEndpointId

Now you need to draw back a list of all the Possible ranges from Infoblox

$ranges = Invoke-vRARestMethod -Method GET -URI "/ipam-service/api/providers/$EndpointId/ip-ranges?limit=1000"
$ranges = $ranges.content | select-object name, description,externalId

Personally I then filter the list for only what is needed

You can obviously filter the list to whatever is required, but for this scenario, just going to create a new network profile for each range.

The entire code base together is as follow

$URI = "/iaas-proxy-provider/api/network/profiles"

$sampleNetworkName = "testnetwork"

$EndpointId = (Get-vRAExternalNetworkProfile -Name $sampleNetworkName).IPAMEndpointId

$ranges = Invoke-vRARestMethod -Method GET -URI "/ipam-service/api/providers/$EndpointId/ip-ranges?limit=1000"
$ranges = $ranges.content | select-object name, description,externalId


$Template = @"
    {
        "profileType" : "EXTERNAL",
        "id" : null,
        "@type" : "ExternalNetworkProfile",
        "name" : "External IPAM",
        "IPAMEndpointId" : "f55e372a-0b6e-46a7-9243-4fd8526e3566",
        "addressSpaceExternalId" : "",
        "description" : "my description",
        "definedRanges" : [{
			"externalId" : "network-1",
			"name" : "192.168.1.0/24",
			"description" : "Created by vRO package stub workflow",
			"state" : "UNALLOCATED",
			"beginIPv4Address" : null,
			"endIPv4Address" : null
		}
	]
    }
"@

$Template = $Template | ConvertFrom-Json

$Template.IPAMEndpointId = $EndpointId

foreach ($range in $ranges){
    $Template.name = $range.name
    $Template.description = $range.description
    $Template.definedRanges[0].externalId = $range.externalId
    $Template.definedRanges[0].name = $range.name
    $Template.definedRanges[0].description = $range.description
    
    Invoke-vRARestMethod -Method POST -URI $URI -Body ($Template | ConvertTo-Json)
}

This creates a network profile for every available range in Infoblox

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s