Rename Azure NIC in vRA8

Share on:

How to configure network interface name using event broker subscription

Subject

vRA8 (up current version 8.5) does not support to set the name of network inteface in Azure, the default naming scheme apply (subnetname-). It is hard to see by name which NIC belongs to which virtual machine:

New IaaS API

vRealize Automation 8.5 Release Notes mentions an IaaS API addition that allows us to change selected parameters via /iaas/api/machines/{id}/network-interfaces/{nicId}.

Changing the name is supported, but only before provisioning, we need to call the API in Compute provision (compute.provision.pre) phase. We'll use an extensibility EBS to trigger a vRO workflow. This workflow calls the IaaS API to change the name attribute. Here is a sample payload available via inputProperties:

 1{
 2  "addresses": [
 3    [
 4      null
 5    ]
 6  ],
 7  "componentId": "cloudvm[0]",
 8  "endpointId": "277a3feb-ec8e-4de3-82e7-60b7024ae9c7",
 9  "externalIds": [
10    "cloudvm-34"
11  ],
12  "blueprintId": "43449016-b9a7-4640-bdb8-4520ce6a86e1",
13  "tags": {},
14  "resourceNames": [
15    "cloudvm-34"
16  ],
17  "customProperties": {
18    "flavor": "small",
19    "azureManagedDiskType": "Standard_LRS",
20    "image": "az_rhel7",
21    "resourceGroupName": "testRG",
22    "countIndex": "0",
23    "count": "1",
24    "project": "a0ca29a2-4594-4281-b473-a490a16b92f8",
25    "flavorMappingName": "small"
26  },
27  "componentTypeId": "Cloud.Azure.Machine",
28  "requestId": "fe924e4a-8cd8-4921-8790-4446045683e5",
29  "macAddresses": [
30    [
31      null
32    ]
33  ],
34  "deploymentId": "992dea79-d0e1-41bd-a716-4fa017b04496",
35  "zoneId": "5e31fcab-e8d5-433c-8c6f-9a1816054600",
36  "projectId": "a0ca29a2-4594-4281-b473-a490a16b92f8",
37  "subnetIds": [
38    [
39      "0f54c3f8-25ab-45bd-8dfb-6ce24eaacd4d"
40    ]
41  ],
42  "resourceIds": [
43    "f47b4051-f000-43de-963b-d9a5acbac495"
44  ]
45}

The resourceIds array contains the VM id. We need to identify the network interface id, the IaaS API can provide it:

1curl -s -k -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" \
2'https://vra8.corp.local/iaas/api/machines/f47b4051-f000-43de-963b-d9a5acbac495' | jq '._links["network-interfaces"]'

In the output we have the path of the NIC wee need to use:

1{
2  "hrefs": [
3    "/iaas/api/machines/f47b4051-f000-43de-963b-d9a5acbac495/network-interfaces/6ab905bc-7ff1-4639-981f-dbbec4a93949"
4  ]
5}

Extensibility: vRO workflow

For vRA REST API we use the Orchestrator Plug-in for vRealize Automation:

The following sample workflow will modify the NIC name to -nic. The inputProperties contains the EBS payload, and vraHost is the VRA:Host endpoint. We need to specify the new API version 2021-07-15 to enable this functionality.

 1var restClient = vraHost.createRestClient();
 2var request = restClient.createRequest("GET", "/iaas/api/machines/" + inputProperties.resourceIds[0]);
 3var response = restClient.execute(request);
 4System.log("GET statusCode: " + response.statusCode);
 5
 6var content = JSON.parse(response.contentAsString);
 7content._links["network-interfaces"].hrefs.forEach(
 8    function (nic_link) {
 9        request = restClient.createRequest("PATCH", nic_link + "?apiVersion=2021-07-15", 
10            '{"name":"' + inputProperties.resourceNames[0] + '-nic"}');
11        response = restClient.execute(request);
12        System.log("PATCH statusCode: " + response.statusCode);
13    }
14)

You can download the com.azure.utils package containing the workflow from GitHub: https://github.com/kuklis/vro8-packages

vRA Event Broker Subscription

Now we create an EBS for the workflow:

It is important to make the EBS blocking so that vRA waits for the workflow run and the change made.

Check the result

After deploying a new Azure VM, the NIC name matches the VM name: