{"id":1832,"date":"2023-08-29T10:17:38","date_gmt":"2023-08-29T14:17:38","guid":{"rendered":"https:\/\/enterpriseadmins.org\/blog\/?p=1832"},"modified":"2023-08-29T10:17:38","modified_gmt":"2023-08-29T14:17:38","slug":"aria-automation-internal-ipam-reserve-release-api","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/aria-automation-internal-ipam-reserve-release-api\/","title":{"rendered":"Aria Automation Internal IPAM reserve \/ release API"},"content":{"rendered":"\n<p>In the May 2023\/8.12.1 release notes for Aria Automation, one of the what&#8217;s new items was the ability to reserve\/unreserve an IP address to make it unavailable\/available for deployment.  In this release the functionality is supported via API only.  This post will cover how to connect to and consume this API<\/p>\n\n\n\n<p>The first thing we&#8217;ll look at is the network elements from the web interface to show which object we&#8217;ll be interacting with from the API.  Under Assembler > Infrastructure > Network Profiles we see various networks.  In this case we&#8217;ll use VLAN40, which in my lab contains physical network devices.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"390\" height=\"308\" src=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-1.png\" alt=\"\" class=\"wp-image-1833\" srcset=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-1.png 390w, https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-1-300x237.png 300w\" sizes=\"auto, (max-width: 390px) 100vw, 390px\" \/><\/a><\/figure>\n\n\n\n<p>We will open this tile, then select the Networks tab.  From here we can see the 192.168.40.0\/24 network.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"694\" height=\"325\" src=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-2.png\" alt=\"\" class=\"wp-image-1834\" srcset=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-2.png 694w, https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-2-300x140.png 300w\" sizes=\"auto, (max-width: 694px) 100vw, 694px\" \/><\/a><\/figure>\n\n\n\n<p>We will select the Network and then click Manage IP Ranges.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"210\" src=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-3-1024x210.png\" alt=\"\" class=\"wp-image-1835\" srcset=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-3-1024x210.png 1024w, https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-3-300x61.png 300w, https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-3-768x157.png 768w, https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-3.png 1127w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>This &#8216;VLAN40 &#8211; Network Devices&#8217; name (which I intentionally set different that the network profile name above) is the one we see when calling the API for a list of network-ranges.  I defined the range as being 192.168.40.10 through 192.168.40.199, for a total of 190 usable addresses.  Now that we&#8217;ve seen the elements in the web interface, we will interact with them using this new API.<\/p>\n\n\n\n<p>Our first task will be logging into the API.  We will provide a username\/password to obtain a refresh token, then we&#8217;ll use that token to obtain a bearer token.  This is based on the postman example from this KB article: <a href=\"https:\/\/kb.vmware.com\/s\/article\/89129\">https:\/\/kb.vmware.com\/s\/article\/89129<\/a>. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$vraHost = 'https:\/\/cm-vra-01.lab.enterpriseadmins.org'\r\n\r\n$restBody = @{\r\n  username='configadmin'\r\n  password='VMware1!'\r\n  domain='System Domain'\r\n} | Convertto-Json\r\n\r\n$refreshToken = Invoke-RestMethod -Uri \"$($vraHost)\/csp\/gateway\/am\/api\/login?access_token\" -Method 'POST' -Body $restBody -ContentType 'application\/json'\r\n$bearerToken = Invoke-RestMethod -Uri \"$($vraHost)\/iaas\/api\/login\" -Method 'POST' -Body $(@{refreshToken=$($refreshToken.'refresh_token')}|ConvertTo-Json) -ContentType 'application\/json'\r<\/code><\/pre>\n\n\n\n<p>Once we have our bearer token, we can use it as a header in our future posts.  For example, to obtain a list of <code>network-ip-ranages<\/code>, we&#8217;ll use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$networkIpRanges = Invoke-RestMethod -Uri \"$($vraHost)\/iaas\/api\/network-ip-ranges\" -Method 'GET' -ContentType 'application\/json' -Headers @{Authorization=\"Bearer $($bearerToken.token)\"}<\/code><\/pre>\n\n\n\n<p>We know from the web interface that the name of our network range is &#8216;VLAN40 &#8211; Network Devices&#8217;.  We will use a <code>where-object<\/code> (using the question mark alias) to find the ID of this network.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$thisNetId=($networkIpRanges.content | ?{$_.Name -match 'vlan40'}).id\r\n\n$networkIpRequest = Invoke-RestMethod -Uri \"$($vraHost)\/iaas\/api\/network-ip-ranges\/$thisNetId\/ip-addresses\/allocate\" -Method 'POST' -body $(@{description='I need some IPs for the demo app'; numberOfIps=2}|ConvertTo-Json) -ContentType 'application\/json' -Headers @{Authorization=\"Bearer $($bearerToken.token)\"}\r\n\r\n# wait a few seconds for the request to complete, then ask for results\r\n$reqId = $networkIpRequest.id\r\nforeach ($thisResource in (Invoke-RestMethod -Uri \"$($vraHost)\/iaas\/api\/request-tracker\/$reqId\" -Method 'GET' -ContentType 'application\/json' -Headers @{Authorization=\"Bearer $($bearerToken.token)\"}).Resources) {\r\n  Invoke-RestMethod -Uri \"$($vraHost)$($thisResource)?apiVersion=2021-07-15\" -Method 'GET' -ContentType 'application\/json' -Headers @{Authorization=\"Bearer $($bearerToken.token)\"}\r\n}<\/code><\/pre>\n\n\n\n<p>The <code>networkIpRequest<\/code> object that results will have an ID property to identify that specific network.  In the codeblock below, we will use that ID to get the status of that request.  Since we specified that we needed 2 addresses, the Resources property will be a collection of resource IDs.  We will loop through the addresses and get more details on each item<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$reqId = $networkIpRequest.id\nforeach ($thisResource in (Invoke-RestMethod -Uri \"$($vraHost)\/iaas\/api\/request-tracker\/$reqId\" -Method 'GET' -ContentType 'application\/json' -Headers @{Authorization=\"Bearer $($bearerToken.token)\"}).Resources) {\n  Invoke-RestMethod -Uri \"$($vraHost)$($thisResource)?apiVersion=2021-07-15\" -Method 'GET' -ContentType 'application\/json' -Headers @{Authorization=\"Bearer $($bearerToken.token)\"}\n}<\/code><\/pre>\n\n\n\n<p>The above code will return the details of the two IP addresses that were allocated, results below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ipAddress             : 192.168.40.10\r\nipAddressDecimalValue : 3232245770\r\nipVersion             : IPv4\r\nipAddressStatus       : ALLOCATED\r\nipAllocationType      : USER\r\ndescription           : I need some IPs for the demo app\r\nid                    : 3f025212-e50a-430e-a8f2-baf0e53deb8f\r\ncreatedAt             : 2023-08-28\r\nupdatedAt             : 2023-08-28\r\norgId                 : e142c6b9-379b-4754-9790-00b4f4373ca4\r\n_links                : @{network-ip-range=; self=}\r\n\r\nipAddress             : 192.168.40.11\r\nipAddressDecimalValue : 3232245771\r\nipVersion             : IPv4\r\nipAddressStatus       : ALLOCATED\r\nipAllocationType      : USER\r\ndescription           : I need some IPs for the demo app\r\nid                    : 32416121-39b5-4462-8d51-2bf6743368fa\r\ncreatedAt             : 2023-08-28\r\nupdatedAt             : 2023-08-28\r\norgId                 : e142c6b9-379b-4754-9790-00b4f4373ca4\r\n_links                : @{network-ip-range=; self=}\r<\/code><\/pre>\n\n\n\n<p>As you can see, <code>192.168.40.10<\/code> and <code>192.168.40.11<\/code> are the first two addresses in the pool and those are the ones given to us for our demo app.<\/p>\n\n\n\n<p>Lets assume that we ended up only needing one of those addresses and now want to return \/ release one to the pool.  We can do this with the API as well.  The following code needs the Network ID from above, as well as the specific address we want to release.  In this example we will return <code>192.168.40.11<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Invoke-RestMethod -Uri \"$($vraHost)\/iaas\/api\/network-ip-ranges\/$thisNetId\/ip-addresses\/release\"  -Method 'POST' -body $(@{ipAddresses=@('192.168.40.11')}|ConvertTo-Json) -ContentType 'application\/json' -Headers @{Authorization=\"Bearer $($bearerToken.token)\"}\r\r<\/code><\/pre>\n\n\n\n<p>This will again return a task ID which looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>progress : 1\nstatus   : INPROGRESS\nname     : IP Address Release Task\nid       : ad5dc112-3dfc-4f7c-836a-6808084bcd56\nselfLink : \/iaas\/api\/request-tracker\/ad5dc112-3dfc-4f7c-836a-6808084bcd56<\/code><\/pre>\n\n\n\n<p>To confirm this completed, we could post to the <code>'selfLink'<\/code> to get a status, but instead we will look at our <code>network-ip-ranage<\/code> and see which addresses are in use.  In this case we would only expect 1 address, the <code>192.168.40.10<\/code> IP.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(Invoke-RestMethod -Uri \"$($vraHost)\/iaas\/api\/network-ip-ranges\/$thisNetId\/ip-addresses?apiVersion=2021-07-15\" -Method 'GET' -ContentType 'application\/json' -Headers @{Authorization=\"Bearer $($bearerToken.token)\"}).content\r\n\r\n\r\nipAddress             : 192.168.40.10\r\nipAddressDecimalValue : 3232245770\r\nipVersion             : IPv4\r\nipAddressStatus       : ALLOCATED\r\nipAllocationType      : USER\r\ndescription           : I need some IPs for the demo app\r\nid                    : 3f025212-e50a-430e-a8f2-baf0e53deb8f\r\ncreatedAt             : 2023-08-28\r\nupdatedAt             : 2023-08-28\r\norgId                 : e142c6b9-379b-4754-9790-00b4f4373ca4\r\n_links                : @{network-ip-range=; self=}\r\n\r\nipAddress             : 192.168.40.11\r\nipAddressDecimalValue : 3232245771\r\nipVersion             : IPv4\r\nipAddressStatus       : RELEASED\r\nipAllocationType      : NONE\r\ndescription           :\r\nid                    : 32416121-39b5-4462-8d51-2bf6743368fa\r\ncreatedAt             : 2023-08-28\r\nupdatedAt             : 2023-08-28\r\norgId                 : e142c6b9-379b-4754-9790-00b4f4373ca4\r\n_links                : @{network-ip-range=; self=}<\/code><\/pre>\n\n\n\n<p>As we can see above, the <code>192.168.40.10<\/code> address is allocated, while the <code>192.168.40.11<\/code> address has been released.  In this case we can see that only 1 address is in use. If we are in the web interface (Assembler > Infrastructure > Network Profiles > <em>specific tile<\/em> > Networks > Manage IP Ranges) we can see the same &#8212; only 1 address is currently used.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-4.png\"><img loading=\"lazy\" decoding=\"async\" width=\"308\" height=\"178\" src=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-4.png\" alt=\"\" class=\"wp-image-1837\" srcset=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-4.png 308w, https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2023\/08\/image-4-300x173.png 300w\" sizes=\"auto, (max-width: 308px) 100vw, 308px\" \/><\/a><\/figure>\n\n\n\n<p>I hope this walkthrough shows how to consume this new API to manage Aria Automation (formerly known as vRealize Automation) internal IPAM.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the May 2023\/8.12.1 release notes for Aria Automation, one of the what&#8217;s new items was the ability to reserve\/unreserve an IP address to make it unavailable\/available for deployment. In this release the functionality is supported via API only. This &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/aria-automation-internal-ipam-reserve-release-api\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[9,3,4],"tags":[],"class_list":["post-1832","post","type-post","status-publish","format-standard","hentry","category-lab-infrastructure","category-scripting","category-virtualization"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1832","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=1832"}],"version-history":[{"count":3,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1832\/revisions"}],"predecessor-version":[{"id":1839,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1832\/revisions\/1839"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=1832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=1832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=1832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}