A few months ago a client asked me to create an NSX application load-balancer programmatically, and then make it available to their vRealize Automation consumers in through the self-service catalog. In building-block fashion, they requested that this wasn’t a composite blueprint, but rather through XaaS. While the former would definitely take less time, the latter was not that difficult either once I got started.
From the outset, I knew I would be building this using the NSX REST API, as I’ve had more success with that than with the NSX plugin for vRO. The first step would be to create an NSX Edge appliance, and then in a follow-up workflow apply the load-balancer settings.
The biggest challenge I faced was that once I’d collated the necessary information (datastore, network portgroup etc), how do I insert it into the XML body for the API call?
The solution was to store the XML as a resource element. In the XML where the values would normally be placed, I inserted the name of the attributes which would then later be populated.
The XML template looks like this:
As part of our workflow, we need to populate values for the following attributes:
The following also need to be supplied, but they will be defined as configuration elements:
With further work, it would be better to extract the last two from an enterprise secret store, such as HashiCorp Vault.
So far our workflow has defined the values, we now need to merge them into the XML:
To do that we will first define a new Properties object, replace our values, and then cycle through the XML inserting the property keys. To do this, use the following code:
Now that we have a complete XML body, we can submit this as a REST API request to provision our NSX Edge. If you’re looking for an excellent example on how to do this, I suggest you take a look at Gavin Stephens blog at https://www.simplygeek.co.uk/2019/05/16/vrealize-orchestrator-http-rest-client.