Publish IaaS Blueprint in vRO via the vRA REST API
There is an excellent post over at Automate-IT.today which details how to create a vRA IaaS Blueprint from vRO. Once you have used the workflow from that site to create a Blueprint it still needs to be published before it can be used as a vRA Catalog Item, added to a Service etc.
Note that even updating Christiaan Roeleveld’s code to set the property IsPublished to true, doesn’t actually publish the Blueprint. Although in the screenshot above it appears to be published, it doesn’t actually show up in Administration / Catalog Items yet.
I needed to be able to do this and found that it is possible via the vRA REST API. Check out PUT request to “Register a ProviderCatalogItem or update an already registered one.”
1) Get an authentication token
To achieve this in vRO you will first of all need to obtain an authentication token, I detailed how to do that in a previous post.
2) Create a REST operation for Register a ProviderCatalogItem
Run the Add a REST operation workflow and populate with the REST host and PUT request details, using the URL from the above documentation: /catalog-service/api/provider/providers/{providerId}/catalogItems/{bindingId}
3) Generate a workflow for Register a ProviderCatalogItem
Run the Generate a new workflow from a REST operation workflow. Populate with the REST operation created above and set the Content type to application/json .
Give it a name and select a folder to store it in.
4) Update the generated workflow with a token input and additional headers
You’ll need to edit the Scriptable Task in the generated workflow. Add an extra input parameter of token, type string.
On the Scripting tag, add the following lines of code to include the authentication token and an Accept header:
[code language=“javascript”]
var authorizationToken = “Bearer " + token
request.setHeader(“Accept”, “application/json”); request.setHeader(“Authorization”, authorizationToken);
[/code]
5) Get the IaaS Provider ID
The observant among you will have noticed that from the PUT URL, /catalog-service/api/provider/providers/{providerId}/catalogItems/{bindingId}, we need to supply a providerId and a bindingId. The providerId for our example is the ID of the IaaS provider. This can be determined via a separate REST call.
6) Create a REST operation for Get Providers
Run the Add a REST operation workflow and populate with the REST host and GET request details for this URL: /catalog-service/api/providers
7) Generate a workflow for Get Providers
Run the Generate a new workflow from a REST operation workflow. Populate with the REST operation created above.
Give it a name and select a folder to store it in.
8) Update the generated workflow with a token input and additional headers
You’ll need to edit the Scriptable Task in the generated workflow. Add an extra input parameter of token, type string.
On the Scripting tag, add the following lines of code to include the authentication token and an Accept header:
[code language=“javascript”]
var authorizationToken = “Bearer " + token
request.setHeader(“Accept”, “application/json”); request.setHeader(“Authorization”, authorizationToken);
[/code]
Note: the response you will receive to GET providers will be something like the following. We are interested in the iaas-service id property:
[code language=“javascript”]
{ “links”: [], “content”: [ { “@type”: “Provider”, “id”: “934c88ec-607e-415b-ad38-1290c30d8610”, “name”: “iaas-service”, “providerTypeId”: “com.vmware.csp.iaas.blueprint.service” }, { “@type”: “Provider”, “id”: “0dd55fd2-2b1a-432e-89af-b77cb6f41b15”, “name”: “Advanced Designer Service”, “providerTypeId”: “com.vmware.csp.core.designer.service” } ], “metadata”: { “size”: 20, “totalElements”: 2, “totalPages”: 1, “number”: 1, “offset”: 0 } }
[/code]
9) Get the Binding ID
The other item we will need to provide is the Binding ID. Thanks to Christiaan for pointing out that this is the virtualMachineTemplateId property of the IaaS Blueprint.
10) Publishing the Blueprint
Armed with the following info, we are now able to run the New-ProviderCatalogItem workflow:
- Authentication token
- ProviderId
- BindingID
We also need to send the following JSON text with the PUT request as detailed here. Replace the following values:
- id - virtualMachineTemplateId / BindingID
- name - Catalog Item name
- description - Catalog Item description
- tenantRef - vRA Tenant name
- tenantLabel - vRA Tenant name
[code language=“javascript”]
{ “id”: “357b9240-62bd-4201-9be0-b3c6180643b9”, “name”: “Centos-Small”, “description”: “Centos-Small”, “iconId”: “cafe_default_icon_genericCatalogItem”, “catalogItemTypeId”: “Infrastructure.Virtual”, “organization”: { “tenantRef”: “Tenant10”, “tenantLabel”: “Tenant10”, “subtenantRef”: null, “subtenantLabel”: null }, “outputResourceTypeId”: “Infrastructure.Virtual”, “forms”: null }
[/code]
Run the workflow and enter these details:
A successful workflow run will see the blueprint published to a catalog item.