Tag Archives: javascript

Change the MIME Type of a vRO Resource Element

When a file is imported into vRO to be used as a Resource Element, a MIME type is automatically set depending on what has been imported. For instance, in the below example a shell script has been imported, the contents of which will be used as part of some vRO automation – notice the MIME type has been set to application/x-sh.

mimetype01

This doesn’t really cause a problem in itself when using the Resource Element in a workflow, however vRO doesn’t display the content of all MIME types when looking at the file in the Viewer tab and may display the message “cannot display this kind of element” instead – *.sh is one of those :

mimetype03

 

 

It is possible to change the MIME type of an existing Resource Element with the following code:

Drop that into a workflow and you can use it like this – supply inputs for which Resource Element and what MIME type to change it to. In this example we’ll use text/plain:

mimetype02

Upon successful completion of the workflow, the type should have changed:

mimetype04

and now the contents are viewable on the Viewer tab:

mimetype05

Create Blueprints in vRA 7 via REST and via vRO

A significant pain point on a recent project of mine was automating the creation of blueprints in vRA 6.2 with vRO. There was very little information around on how this could be achieved and even with the method that we eventually came up with still required some manual effort and was not always the most reliable.

Enter vRA 7 and some hope that things may have gotten better.

First of all I looked through the vRA 7 Programming Guide and found some examples on exporting content from vRA 7. I’d heard in some of the conversations around the release of version 7 that blueprints would be able to be manipulated in YAML files, so the first thing to do was to create a blueprint through the new Design interface and then get it exported out into a YAML file.

Create a Blueprint through the Design Interface

Here’s my Centos-Small blueprint created through the Blueprint Designer. A simple vCenter template clone connected to a single network and basic resource values (make sure to publish the blueprint):

CreateBlueprint02

Get an Authentication Token for vRA REST Queries

Using the Postman REST client, I first of all need to get an authentication token. I have previously detailed how to do this from vRO, however from Postman I need to set the following:

URL: https://vraapliance.fqdn/identity/api/tokens

Type: POST

Headers: Accept: application/json and Content-Type: application/json

Body:


{
"username":"[email protected]",
"password":"[email protected]",
"tenant":"Tenant01"
}

CreateBlueprint03

 

CreateBlueprint04

Sending that request should give me a response with a token to use which is valid for up to 8 hours; it will look something like this:


{
"expires": "2016-01-19T18:37:42.000Z",
"id": "MTQ1MzE5OTg2MjYzMTo3MThjNGFiNDVmMjE4MjZiMzgxNjp0ZW5hbnQ6VGVuYW50MDF1c2VybmFtZTp0ZW5hbnRhZG1pbjAxQHZyYWRlbW8ubG9jYWxleHBpcmF0aW9uOjE0NTMyMjg2NjIwMDA6ZmJmZjU2ZmNjOTFkMDE3ODhkNjJmMzM3ZGMwMzM3NjRhMjQxNjJlMjhjMGU3YjU0YzNlZjUwYTlkYWFjNDAxYTBkODVlYzVkYWQ1YzY4ZDc0MTQ3NjBlM2Q3MDk1OGU5OTg1NjNiMTI4OWQwMGMzMzExMDAxNmEyOGY0M2MxYTk=",
"tenant": "Tenant01"
}

 

CreateBlueprint05

Get a List of Blueprints

Now we can use that token to get a list of available blueprints that token has permission to view:

URL: https://vraapliance.fqdn/content-management-service/api/contents

Type: GET

Headers: Accept: application/json and Authorization: Bearer MTQ1MzE5OTg2MjYzMTo3MThjNGFiNDVmMjE4MjZiMzgxNjp0ZW5hbnQ6VGVuYW50MDF1c2VybmFtZTp0ZW5hbnRhZG1pbjAxQHZyYWRlbW8ubG9jYWxleHBpcmF0aW9uOjE0NTMyMjg2NjIwMDA6ZmJmZjU2ZmNjOTFkMDE3ODhkNjJmMzM3ZGMwMzM3NjRhMjQxNjJlMjhjMGU3YjU0YzNlZjUwYTlkYWFjNDAxYTBkODVlYzVkYWQ1YzY4ZDc0MTQ3NjBlM2Q3MDk1OGU5OTg1NjNiMTI4OWQwMGMzMzExMDAxNmEyOGY0M2MxYTk=

CreateBlueprint06

 

This will give us a JSON response, including some details of our Centos-Small Blueprint:


{
"links": [],
"content": [
{
"@type": "Content",
"id": "78f27bc8-dd51-4c10-97cf-fb5770f0836b",
"contentId": "cfa3b28a-6a59-4a85-8355-ff70c6fd3332",
"name": "IaaS VC VirtualMachine",
"description": null,
"contentTypeId": "xaas-resource-mapping",
"mimeType": null,
"tenantId": "_internal",
"subtenantId": null,
"dependencies": [],
"createdDate": "2016-01-05T11:05:21.673Z",
"lastUpdated": "2016-01-05T11:05:21.673Z",
"version": 0
},
{
"@type": "Content",
"id": "3ac8d4ed-1bc0-45d7-a54a-edb44a2fdeae",
"contentId": "9fd01109-c9ab-4ce7-9b9d-4d1c06bccdb9",
"name": "IaaS vCD VM",
"description": null,
"contentTypeId": "xaas-resource-mapping",
"mimeType": null,
"tenantId": "_internal",
"subtenantId": null,
"dependencies": [],
"createdDate": "2016-01-05T11:05:21.868Z",
"lastUpdated": "2016-01-05T11:05:21.868Z",
"version": 0
},
{
"@type": "Content",
"id": "2359c8c9-1ec1-4162-a9e0-aa2c5121815d",
"contentId": "CentosSmall-12345",
"name": "Centos - Small",
"description": "Centos - Small",
"contentTypeId": "composite-blueprint",
"mimeType": null,
"tenantId": "Tenant01",
"subtenantId": null,
"dependencies": [],
"createdDate": "2016-01-19T10:56:14.398Z",
"lastUpdated": "2016-01-19T10:56:14.398Z",
"version": 0
}
],
"metadata": {
"size": 20,
"totalElements": 3,
"totalPages": 1,
"number": 1,
"offset": 0
}
}

Create a Content Package Containing our Blueprint

Now we need to create a Content Package containing our Blueprint, so that it can be exported. We will only add a single item, but multiple items can be added to the Package. The id of the Blueprint retrieved above needs to be used in the JSON body as ‘contents’ .

URL: https://vraapliance.fqdn/content-management-service/api/packages

Type: POST

Headers: Accept: application/json, Content-Type: application/json and Authorization: Bearer MTQ1MzE5OTg2MjYzMTo3MThjNGFiNDVmMjE4MjZiMzgxNjp0ZW5hbnQ6VGVuYW50MDF1c2VybmFtZTp0ZW5hbnRhZG1pbjAxQHZyYWRlbW8ubG9jYWxleHBpcmF0aW9uOjE0NTMyMjg2NjIwMDA6ZmJmZjU2ZmNjOTFkMDE3ODhkNjJmMzM3ZGMwMzM3NjRhMjQxNjJlMjhjMGU3YjU0YzNlZjUwYTlkYWFjNDAxYTBkODVlYzVkYWQ1YzY4ZDc0MTQ3NjBlM2Q3MDk1OGU5OTg1NjNiMTI4OWQwMGMzMzExMDAxNmEyOGY0M2MxYTk=

Body:


{
"name":"Test package",
"description":"Test package for export",
"contents":[ "2359c8c9-1ec1-4162-a9e0-aa2c5121815d" ]
}

CreateBlueprint07

 

CreateBlueprint08

All being well, we should receive a 201 Created response:

CreateBlueprint09

 

Listing Existing Content Packages

We can see what Content Packages are available with:

URL: https://vraapliance.fqdn/content-management-service/api/packages

Type: GET

Headers: Accept: application/json and Authorization: Bearer MTQ1MzE5OTg2MjYzMTo3MThjNGFiNDVmMjE4MjZiMzgxNjp0ZW5hbnQ6VGVuYW50MDF1c2VybmFtZTp0ZW5hbnRhZG1pbjAxQHZyYWRlbW8ubG9jYWxleHBpcmF0aW9uOjE0NTMyMjg2NjIwMDA6ZmJmZjU2ZmNjOTFkMDE3ODhkNjJmMzM3ZGMwMzM3NjRhMjQxNjJlMjhjMGU3YjU0YzNlZjUwYTlkYWFjNDAxYTBkODVlYzVkYWQ1YzY4ZDc0MTQ3NjBlM2Q3MDk1OGU5OTg1NjNiMTI4OWQwMGMzMzExMDAxNmEyOGY0M2MxYTk=

CreateBlueprint10

 

which should give us a response like the following, including our newly created ‘Test package’:


{
"links": [],
"content": [
{
"@type": "Package",
"id": "736562b2-c991-449a-999d-6d25f2ff05c5",
"name": "demo package",
"description": "this is the description",
"tenantId": "Tenant01",
"subtenantId": null,
"contents": [
"7e9bf69c-a4ec-44dd-98f5-6408f074a1db"
],
"createdDate": "2016-01-14T15:28:26.323Z",
"lastUpdated": "2016-01-14T15:28:26.323Z",
"version": 0
},
{
"@type": "Package",
"id": "339aeb0d-a15a-4ee1-84b7-87389d05c428",
"name": "demo package 2",
"description": "demo package 2",
"tenantId": "Tenant01",
"subtenantId": null,
"contents": [
"241fe601-5f15-4749-a6cb-f0bfdb9c97b9",
"7e9bf69c-a4ec-44dd-98f5-6408f074a1db"
],
"createdDate": "2016-01-14T17:05:47.458Z",
"lastUpdated": "2016-01-14T17:05:47.458Z",
"version": 0
},
{
"@type": "Package",
"id": "04fb81ce-9da1-46f6-b98f-fd48e8ce0e2c",
"name": "Test package",
"description": "Test package for export",
"tenantId": "Tenant01",
"subtenantId": null,
"contents": [
"2359c8c9-1ec1-4162-a9e0-aa2c5121815d"
],
"createdDate": "2016-01-19T11:28:30.507Z",
"lastUpdated": "2016-01-19T11:28:30.507Z",
"version": 0
}
],
"metadata": {
"size": 20,
"totalElements": 3,
"totalPages": 1,
"number": 1,
"offset": 0
}
}

CreateBlueprint11

 

Export the Content Package to a Zip File

Now we want to export the Content Package to a zip file so that we can have a look at the YAML file that details the blueprint:

URL: https://vraapliance.fqdn/content-management-service/api/packages/packageid

Type: GET

Headers: Accept: application/zip and Authorization: Bearer MTQ1MzE5OTg2MjYzMTo3MThjNGFiNDVmMjE4MjZiMzgxNjp0ZW5hbnQ6VGVuYW50MDF1c2VybmFtZTp0ZW5hbnRhZG1pbjAxQHZyYWRlbW8ubG9jYWxleHBpcmF0aW9uOjE0NTMyMjg2NjIwMDA6ZmJmZjU2ZmNjOTFkMDE3ODhkNjJmMzM3ZGMwMzM3NjRhMjQxNjJlMjhjMGU3YjU0YzNlZjUwYTlkYWFjNDAxYTBkODVlYzVkYWQ1YzY4ZDc0MTQ3NjBlM2Q3MDk1OGU5OTg1NjNiMTI4OWQwMGMzMzExMDAxNmEyOGY0M2MxYTk=

CreateBlueprint12

This time in Postman click on Send and download

CreateBlueprint13

This will prompt us where to save the package and what to call it; make sure you create a zip file…

CreateBlueprint14

Have a look inside the zip file and you will see the following structure; a metadata.yaml file and a composite-blueprint folder containing individual yaml files for each blueprint that was part of the package:

CreateBlueprint15

CreateBlueprint16

The contents of each YAML file are listed here for reference:

metadata.yaml


name: "Test package"
productVersion: "7.0.0-SNAPSHOT"
data:
- locator: "composite-blueprint/CentosSmall-12345.yaml"
name: "Centos - Small"
description: "Centos - Small"
exportTime: "2016-01-19T11:46:13.614Z"

CentosSmall-12345.yaml


id: CentosSmall-12345
name: Centos - Small
description: Centos Small - 1 vCPU - 1GB RAM
status: PUBLISHED
components:
Tenant01:
type: Infrastructure.Network.Network.Existing
data:
name:
fixed: Tenant01
network_profile:
fixed: Tenant01
vSphere_Machine_1:
type: Infrastructure.CatalogItem.Machine.Virtual.vSphere
data:
_cluster:
fixed: 1
min: 1
action:
fixed: FullClone
allow_storage_policies:
fixed: false
blueprint_type:
fixed: '1'
cpu:
fixed: 1
min: 1
disks:
- capacity: 16
id: 1452533069864
initial_location: ''
is_clone: true
label: Hard disk 1
storage_reservation_policy: ''
userCreated: false
volumeId: 0
display_location:
fixed: false
machine_prefix:
fixed:
id: Tenant01
max_network_adapters: {}
max_volumes: {}
memory:
default: 1024
max: 1024
min: 1024
nics:
- address: ''
assignment_type: Static
id: 0
load_balancing: ''
network: ${_resource~Tenant01}
network_profile: Tenant01
provisioning_workflow:
fixed:
id: CloneWorkflow
label: CloneWorkflow
security_groups: []
security_tags: []
source_machine:
fixed:
id: 51784cf9-fc3a-4939-abf7-2e2965523036
label: template-centos06b
source_machine_name:
fixed: template-centos06b
storage:
default: 16
max: 40
min: 16
layout:
Tenant01: 0,0
vSphere_Machine_1: 1,0

 

Create Blueprints from Postman

We can now manipulate the YAML files to create Blueprints back in vRA. Say for instance we want to add Centos-Medium and Centos-Large Blueprints. All we need to do is create additional YAML files for those two templates, update the metadata.yaml file and send back to vRA.

So the composite-blueprint folder now looks like this:

CreateBlueprint17

And the metadata.yaml file has been updated to contain the new files:


name: "Test package"
productVersion: "7.0.0-SNAPSHOT"
data:
- locator: "composite-blueprint/CentosSmall-12345.yaml"
name: "Centos - Small"
description: "Centos - Small"
- locator: "composite-blueprint/CentosMedium-12345.yaml"
name: "Centos - Medium"
description: "Centos - Medium"
- locator: "composite-blueprint/CentosLarge-12345.yaml"
name: "Centos -Large"
description: "Centos - Large"
exportTime: "2016-01-19T11:46:13.614Z"

We then create a new zip file with the updated content:

CreateBlueprint18

To create the Blueprints in vRA we send the following REST request via Postman:

URL: https://vraapliance.fqdn/content-management-service/api/packages

Type: POST

Headers: Accept: application/zip,  and Authorization: Bearer MTQ1MzE5OTg2MjYzMTo3MThjNGFiNDVmMjE4MjZiMzgxNjp0ZW5hbnQ6VGVuYW50MDF1c2VybmFtZTp0ZW5hbnRhZG1pbjAxQHZyYWRlbW8ubG9jYWxleHBpcmF0aW9uOjE0NTMyMjg2NjIwMDA6ZmJmZjU2ZmNjOTFkMDE3ODhkNjJmMzM3ZGMwMzM3NjRhMjQxNjJlMjhjMGU3YjU0YzNlZjUwYTlkYWFjNDAxYTBkODVlYzVkYWQ1YzY4ZDc0MTQ3NjBlM2Q3MDk1OGU5OTg1NjNiMTI4OWQwMGMzMzExMDAxNmEyOGY0M2MxYTk=

Body: set to form data and select the TestPackageUpdated.zip file

CreateBlueprint19

CreateBlueprint20

We should receive a 200 OK response with details of Blueprints created:


{
"operationType": "IMPORT",
"operationStatus": "WARNING",
"operationResults": [
{
"contentId": "CentosMedium-12345",
"contentName": "Centos - Medium",
"contentTypeId": "composite-blueprint",
"operationStatus": "SUCCESS",
"messages": null,
"operationErrors": null
},
{
"contentId": "CentosLarge-12345",
"contentName": "Centos -Large",
"contentTypeId": "composite-blueprint",
"operationStatus": "SUCCESS",
"messages": null,
"operationErrors": null
},
{
"contentId": "CentosSmall-12345",
"contentName": "Centos - Small",
"contentTypeId": "composite-blueprint",
"operationStatus": "WARNING",
"messages": [
"Found matching content, import will overwrite this content."
],
"operationErrors": null
}
]
}

CreateBlueprint21

Now login to vRA and you will see the three Blueprints:

CreateBlueprint22

and if we look at the details of the medium template it is showing additional vCPU and RAM resource that were specified in the YAML file:

CreateBlueprint23

Obviously, there are many other changes that could be made within the YAML file to make different templates.

Create Blueprints from vRO

While researching this topic I initially looked at a similar approach to the above with Postman when moving on to do the same for vRO. However, looking at the updated vRA 7 plugin for vRO showed a folder of workflows for working with Composite Blueprints:

CreateBlueprint24

Rather than try and re-invent the wheel I decided to see what these could do, specifically the Import a composite blueprint workflow. It has inputs of a vCACCAFE:VCACHost and a MimeAttachement, so is pretty straightforward to use:

CreateBlueprint25

Thinking slightly further ahead, rather than just run this single workflow, I would more likely use this as part of a vRA Tenant Creation workflow and would store multiple YAML files within Resource Elements and possibly update them on the fly before using them to create Blueprints. For this example though I have stored one for CentosXLarge in a Resource Element to illustrate the possibility. This is exactly the same type of YAML file for a Blueprint used in the above example with Postman, just has different values for id, name, vCPU and memory to make it XLarge:

CreateBlueprint26

So we then make a top-level workflow with two elements; a scriptable task to retrieve the YAML file from a resource element and the built-in Import a composite blueprint workflow:

CreateBlueprint27The scriptable task has an input of a Resource Element and outputs a MimeAttachment (in a more realistic example we would take and input of maybe a folder of Resource Elements and output an array of MimeAttachments). Then a simple one-liner to convert between the two object types:


var yamlMimeAttachment = yamlResourceElement.getContentAsMimeAttachment()

CreateBlueprint28

CreateBlueprint29

CreateBlueprint30

Now we can pass this MimeAttachement into the Import a composite blueprint workflow and set the vCACHost to be the host for the required vRA Tenant. From this workflow it will output the BlueprintId:

CreateBlueprint31

CreateBlueprint32

So we are ready to run the top level workflow. Specify a vCACHost and a YAML file in a ResourceElement and run the workflow:

CreateBlueprint33

Hopefully a successful run:

CreateBlueprint34

and here’s the Centos – XLarge Blueprint:

CreateBlueprint35

CreateBlueprint36

 

 

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.

PublishIaasBlueprint01

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}

PublishIaasBlueprint02

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 .

PublishIaasBlueprint03

Give it a name and select a folder to store it in.

PublishIaasBlueprint04

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.

PublishIaasBlueprint05

 

On the Scripting tag, add the following lines of code to include the authentication token and an Accept header:


var authorizationToken = "Bearer " + token

request.setHeader("Accept", "application/json");
request.setHeader("Authorization", authorizationToken);

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

PublishIaasBlueprint07

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.

PublishIaasBlueprint08

Give it a name and select a folder to store it in.

PublishIaasBlueprint09

 

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.

PublishIaasBlueprint10

On the Scripting tag, add the following lines of code to include the authentication token and an Accept header:


var authorizationToken = "Bearer " + token

request.setHeader("Accept", "application/json");
request.setHeader("Authorization", authorizationToken);

Note: the response you will receive to GET providers will be something like the following. We are interested in the iaas-service id property:


{
 "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
 }
}

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.

PublishIaasBlueprint12

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

{
 "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
}

Run the workflow and enter these details:

PublishIaasBlueprint13

PublishIaasBlueprint14

PublishIaasBlueprint15

A successful workflow run will see the blueprint published to a catalog item.

PublishIaasBlueprint16

 

vRA: Returning a Catalog Item from a Blueprint ID in vRO

After creating a Blueprint in vRA it is necessary to publish the Blueprint into the Catalog so that it can be consumed by the appropriate set of users. This creates a link between the two different items since the Catalog Item is part of the vRA appliance and the Blueprint can be found in the Windows appliance.

Here’s the Blueprint details from the Inventory tab of vRO, with the virtualMachineTemplateID, a.k.a the Blueprint ID.

BlueprintID03

 

Now look at the Binding id on the Catalog Item in vRO to see matching IDs.

BlueprintID04

Say you now have the BlueprintID and need to return the Catalog Item, how would you do it? The following JavaScript code from a vRO Action I created for this shows you how:


var vCACAdminCatalogItems = Server.findAllForType("vCACCAFE:AdminCatalogItem");

for each (var vCACAdminCatalogItem in vCACAdminCatalogItems) {

try {

var providerBinding = vCACAdminCatalogItem.providerBinding;
var bindingId = providerBinding.getBindingId().toString();

if (bindingId == blueprintId) {

var adminCatalogItem = vCACAdminCatalogItem;
break;
}
} catch(ex) {

}
}
return adminCatalogItem

The getCatalogItemByBlueprintID Action can be downloaded from GitHub.

I put the action into a Test Workflow to demonstrate how it works. This is the Scripting Tab of the action.

BlueprintID03a

Schema of the test workflow:

BlueprintID03b

The Action will output an item of type vCACCAFE:AdminCatalogItem:

BlueprintID03c

The Scriptable Task in the workflow will simply write the ID of the Catalog Item to the system log. We know we should be expecting to see 4e5fe6ee-e8c6-4fcb-8458-9cdbf2cfd465, the ID of the Catalog Item:

BlueprintID05

BlueprintID06

 

Success 🙂

 

vRO: Missing Line Breaks in SOAP Request

While working in vRealize Orchestrator with an external SOAP based system I was having issues with line breaks being removed from text sent across as part of a reasonably large SOAP request containing multiple items.

Say we have the following text strings and want to pass them into the SOAP request with line breaks in-between each one:


text1 = 'This is text1';
text2 = 'This is text2';
text3 = 'This is text3';

textToSend = '\n' + text1 + '\n' + text2 + '\n' + text3;

Place that code into a scriptable task in a workflow, output textToSend to the vRO SystemLog and you will observe the text with line breaks in them, placing each one onto its own line:

LineBreak01

However, when textToSend is sent through to the SOAP request, the line breaks have been removed and the text appears in the interface all on one line, displaying it like so:

LineBreak02

Turns out in this instance the SOAP request would support HTML tags for the text, so using ‘<br />’ instead of ‘\n’ would give the line break.


text1 = 'This is text1';
text2 = 'This is text2';
text3 = 'This is text3';

textToSend = '<br />' + text1 + '<br />' + text2 + '<br />' + text3;

The SystemLog now looks like this:

LineBreak03b

However, we don’t really care what it looks like in there, the important thing is how it translates through in the SOAP request. It is now displayed as desired:

LineBreak04

This also means that any HTML formatting tag could potentially be used if say the text needed to be made Bold or a different size.

 

 

Presenting a Password Confirmation Form in vCO / vRO

Requirement:

Present a vCO / vRO form which contains two password entry fields using SecureStrings and a field which displays whether the two entered passwords match.

Using an if statement to test whether two SecureStrings are equal will fail even if the text entered is identical. As mentioned in this communities post, in a workflow it is possible to take the SecureStrings into a scriptable task and output them as Strings. However, in the presentation of the workflow this method is not possible.

Solution:

Create an action which converts a SecureString to a String. Call that action from another action that is used to display whether the two entered passwords match. Here are the details of how I did it.

Create an action secureStringToString


outputText = text;

return outputText

PasswordForm01

 

Create an action testPasswords

 


var passwordTest1 = System.getModule("com.jm-test").secureStringToString(password1);
var passwordTest2 = System.getModule("com.jm-test").secureStringToString(password2);

if (passwordTest1 == passwordTest2){

return "Matching Passwords"
}
else {

return "Non-Matching Passwords"
}

PasswordForm02

Create a workflow with the following inputs:

PasswordForm03

Set the presentation for the first three inputs to be mandatory and the displayConfirmation input to use the testPasswords action:

username mandatory

PasswordForm04

displayConfirmation Data binding

PasswordForm05

displayConfirmation Data binding testPasswords action

PasswordForm06

Run the workflow and observe the text changes in displayConfirmation dependent on the passwords matching:

PasswordForm07

 

PasswordForm08

I’d be interested to hear if anyone has a better way to do this because I reckon there might be one 🙂

Automating vCAC Tenant Creation with vCO: Part 6 Adding Administrators

In this series we will see how to automate the creation of a tenant in vCAC using vCO. There are multiple tasks to provision a tenant in vCAC, so even though it is an automation product itself, there’s no reason why you shouldn’t look at automating parts of it too.

In part 6 we look at adding Administrators to a Tenant in vCAC.

1) Add the ‘Add administrators’ workflow

Drag the Add administrators workflow from the vCloud Automation Center section of the workflow library

vCOvCACPlugin18

vCOvCACPlugin48

Add the inputs. (This is why we created Array based outputs for the administrator groups earlier in the series – we could add multiple groups here)

vCOvCACPlugin49

There are no outputs to add for this workflow.

Now run the workflow to test all functionality.

vCOvCACPlugin43

vCOvCACPlugin50

 

vCOvCACPlugin51

You can download exports of these workflows below:

 

 

 

Automating vCAC Tenant Creation with vCO: Part 1 AD SSL
Automating vCAC Tenant Creation with vCO: Part 2 AD Users, Groups and OUs
Automating vCAC Tenant Creation with vCO: Part 3 Install the vCAC plugin for vCO
Automating vCAC Tenant Creation with vCO: Part 4 Creating a Tenant
Automating vCAC Tenant Creation with vCO: Part 5 Creating an Identity Store
Automating vCAC Tenant Creation with vCO: Part 6 Adding Administrators
Automating vCAC Tenant Creation with vCO: Part 7 Creating a vCAC Catalog Item

Automating vCAC Tenant Creation with vCO: Part 5 Creating an Identity Store

In this series we will see how to automate the creation of a tenant in vCAC using vCO. There are multiple tasks to provision a tenant in vCAC, so even though it is an automation product itself, there’s no reason why you shouldn’t look at automating parts of it too.

In part 5 we look at adding an Identity Store to a Tenant in vCAC.

1) Generate the variables for adding an Identity Store

Add a scriptable task so we can generate the parameters we need for an Identity Store

vCOvCACPlugin28b

Add the AD domain as an Attribute of the workflow

vCOvCACPlugin30

Add an additional property to that Configuration Element for the netbiosDomain

vCOvCACPlugin31

and add it as an attribute of the workflow

vCOvCACPlugin32

Create a new Configuration Element for the Identity Store and add Type and URL properties.

vCOvCACPlugin33

vCOvCACPlugin34

 

Then add them as workflow attributes:

vCOvCACPlugin35vCOvCACPlugin36

Add inputs

vCOvCACPlugin37

Add outputs

vCOvCACPlugin38

And the following scripting


identityStoreName = tenantName + "-AD";
identityStoreUserDN = vcoServiceUser.distinguishedName;
identityStoreGroupsSearchDN = tenantGroupsOU.distinguishedName;
identityStoreUsersSearchDN = tenantUsersOU.distinguishedName;

tenantAdministratorsName = tenantAdminsGroup.getAttribute('Name');
infrastructureAdministratorsName = infrastructureAdminsGroup.getAttribute('Name');

tenantAdministratorsUpnName = tenantAdministratorsName + "@" + identityStoreDomain;
infrastructureAdministratorsUpnName = infrastructureAdministratorsName + "@" + identityStoreDomain;

tenantAdministrators = [tenantAdministratorsUpnName];
infrastructureAdministrators = [infrastructureAdministratorsUpnName];

vCOvCACPlugin39

 

 

2) Add the ‘Add an identity store to a tenant’ workflow

Drag the Add an identity store to a tenant’ workflow from the vCloud Automation Center section of the workflow library

vCOvCACPlugin18

Add the In parameters

vCOvCACPlugin41

And the Out parametervCOvCACPlugin42

3) Now run the workflow to test it works

vCOvCACPlugin43

vCOvCACPlugin44

 

vCOvCACPlugin45

vCOvCACPlugin47

In part 6 we will complete the  Administrators configuration

 

Automating vCAC Tenant Creation with vCO: Part 1 AD SSL
Automating vCAC Tenant Creation with vCO: Part 2 AD Users, Groups and OUs
Automating vCAC Tenant Creation with vCO: Part 3 Install the vCAC plugin for vCO
Automating vCAC Tenant Creation with vCO: Part 4 Creating a Tenant
Automating vCAC Tenant Creation with vCO: Part 5 Creating an Identity Store
Automating vCAC Tenant Creation with vCO: Part 6 Adding Administrators
Automating vCAC Tenant Creation with vCO: Part 7 Creating a vCAC Catalog Item

Automating vCAC Tenant Creation with vCO: Part 3 Install the vCAC plugin for vCO

In this series we will see how to automate the creation of a tenant in vCAC using vCO. There are multiple tasks to provision a tenant in vCAC, so even though it is an automation product itself, there’s no reason why you shouldn’t look at automating parts of it too. In part 3 we look at installing the vCAC plugin for vCO

1) Download the vCAC plugin   o11nplugin-vcac-6.0.1.vmoapp vCOADPlugin40

2) Install the plugin I’m installing this on a Windows based vCO box. Ensure that the vCO Configuration service is started since it is usually on manual startup. vCOADPlugin41

Navigate to the Configuration webpage, in my case https://localhost:8283/

vCOvCACPlugin01

and then Plugins

vCOvCACPlugin02

Enter credentials of a member of the vCO admins group. (If you haven’t set this up you might want to add an AD connection on the Authentication page)

vCOvCACPlugin03

and select the downloaded plugin, then Upload and install

vCOvCACPlugin04

Accept the License Agreement

vCOvCACPlugin05

Hopefully you get a nice green success

vCOvCACPlugin06

If so, you’ll get a note further down that you need to restart the vCO Server service

vCOvCACPlugin07


Get-Service VMwareOrchestrator | Restart-Service

After the restart, all is now OK

vCOvCACPlugin08

The built-in vCAC workflows are now available in the vCO client

vCOvCACPlugin09

3) Configure the plugin Navigate to Configuration and run the Add a vCAC host workflow

vCOvCACPlugin10

Fill out the details of the default vCAC tenant

vCOvCACPlugin11 vCOvCACPlugin12

…and now we have a vCAC server to work with

vCOvCACPlugin13

 

Automating vCAC Tenant Creation with vCO: Part 1 AD SSL
Automating vCAC Tenant Creation with vCO: Part 2 AD Users, Groups and OUs
Automating vCAC Tenant Creation with vCO: Part 3 Install the vCAC plugin for vCO
Automating vCAC Tenant Creation with vCO: Part 4 Creating a Tenant
Automating vCAC Tenant Creation with vCO: Part 5 Creating an Identity Store
Automating vCAC Tenant Creation with vCO: Part 6 Adding Administrators
Automating vCAC Tenant Creation with vCO: Part 7 Creating a vCAC Catalog Item

Automating vCAC Tenant Creation with vCO: Part 2 AD Users, Groups and OUs

In this series we will see how to automate the creation of a tenant in vCAC using vCO. There are multiple tasks to provision a tenant in vCAC, so even though it is an automation product itself, there’s no reason why you shouldn’t look at automating parts of it too.

In part 2 we will create the AD Users, Groups and OUs to support the vCAC tenant. In this example we will create:

OUs

TenantName and sub-OUs, Users and Groups

Users

A vcoservice account and tenant admin

Groups

A tenant admin group and infrastructure admin group

1) We’re using vCO 5.5.1 and the AD plugin ships by default. We need to configure it to work with a Domain Controller, so run the Configure Active Directory Server workflow.

vCOADPlugin01

vCOADPlugin02

 

vCOADPlugin03

vCOADPlugin04

Now in the vCO Inventory view we can traverse the AD structure

vCOADPlugin05

2) Use a vCO Configuration Element to store the default Tenants OU.

Since we will place each tenant OU into the default Tenants OU each time, we can store this object in a vCO Configuration Element and assign it as an attribute in the workflow.

vCOADPlugin05b

vCOADPlugin05c

vCOADPlugin05d

vCOADPlugin05e

vCOADPlugin05f

3) Create a workflow for the AD requirements. Later on we will plug this into the Create Tenant workflow which will handle all of the different parts. Add an input tenantName ….

vCOADPlugin06

vCOADPlugin07

 

Here we work on the presentation of the input and ensure that the user is guided into supplying us with the correct information.

vCOADPlugin08

vCOADPlugin08b

and an attribute tenantOU (the configuration element created above)

vCOADPlugin09

vCOADPlugin10

vCOADPlugin11

4) Create an OU

Add the Create an organizational unit workflow to the schema

vCOADPlugin12

Set the In parameters, firstly ouName

vCOADPlugin13

and also ouContainer

vCOADPlugin14

Create an Out parameter, which will be the Tenant OU that this workflow creates

vCOADPlugin15

I find the Visual Binding tab really useful as a quick visual checker that everything is set as I am expecting

vCOADPlugin16

We need to create two sub-OUs from the tenant OU. Since the Create OU workflow only creates one, I will show you an alternative for creating multiples rather than adding the workflow many times. Create a scriptable task and call it Create Sub OUs

vCOADPlugin17

As inputs we need the tenantName and tenantNameOU .

vCOADPlugin18

For outputs we need to create the two OUs as attributes of type AD:OrganizationalUnit since we will need to use these OUs later.

 

vCOADPlugin20

Again, mapped out view helps me to visualise I am on the right track….

The scripting code to create the OUs is relatively straightforward. We can call any action by using the path to it and then supplying the necessary parameters. In this case we use the createOrganizationalUnit and getOrganizationUnitFromOrganizationUnit  actions from the ActiveDirectory plugin.


// Create the Users and Groups OUs using the createOrganizationalUnit action
System.getModule("com.vmware.library.microsoft.activeDirectory").createOrganizationalUnit("Users",tenantNameOU);
System.getModule("com.vmware.library.microsoft.activeDirectory").createOrganizationalUnit("Groups",tenantNameOU);

// Retrieve the OU objects for Output
var usersOU = System.getModule("com.vmware.library.microsoft.activeDirectory").getOrganizationUnitFromOrganizationUnit(tenantNameOU,"Users");
var groupsOU = System.getModule("com.vmware.library.microsoft.activeDirectory").getOrganizationUnitFromOrganizationUnit(tenantNameOU,"Groups");

vCOADPlugin22

 

5) Create Users and Groups

Now we need to create some user accounts and groups, so add a scriptable task

vCOADPlugin23

As inputs we need tenantName, tenantOU, usersOU and groupsOU.

vCOADPlugin24

We need to output one of the users, its password and two of the groups for use later on:

vCOADPlugin25a

 

 

We need them to be out-parameters, not attributes, so that we can use them outside of the workflow later. If you create the Source parameter by clicking in the correct place above and choosing parameter rather than attribute then the workflow Out parameters will be created for you.

 

vCOADPlugin26

We also need to make use of a Configuration Element  for the ActiveDirectory domain. This provides a handy way to supply static values to the workflow without hard-coding them into a script element somewhere.

Navigate to Configuration Elements and create a new one

vCOADPlugin27

vCOADPlugin28

vCOADPlugin29

We can use this Configuration Element in our workflow by adding it as an attribute. Use the chooser button to select it.

vCOADPlugin30

vCOADPlugin31

Add the dnsDomain string to the Users and Groups scriptable task

vCOADPlugin32

vCOADPlugin32a

To create the user accounts we need to supply a password. I generate a random one with a helper action createRandomPassword. Store this somewhere that you can easily reference.

vCOADPlugin34a

We want to output two users and two groups from the workflow and also the vcosvcPassword.

Here’s the code to create the users and groups, and add the users to the groups

 

 

// Create vcoService and Tenant Admin users
var vcosvcPassword = System.getModule("com.jonathan.action.general").generateRandomPassword(12)
System.getModule("com.vmware.library.microsoft.activeDirectory").createUserWithPassword(tenantName + "_vCOSvc",vcosvcPassword,vcosvcPassword,dnsDomain,tenantName + "_vCOSvc",usersOU);
var tenantadminPassword = System.getModule("com.jonathan.action.general").generateRandomPassword(12)
System.getModule("com.vmware.library.microsoft.activeDirectory").createUserWithPassword(tenantName + "_TenantAdmin",tenantadminPassword,tenantadminPassword,dnsDomain,tenantName + "_TenantAdmin",usersOU);

System.log("vcosvc password is: " + vcosvcPassword);
System.log("tenantadmin password is: " + tenantadminPassword);

// Retrieve the vcoService and Tenant Admin users
var vcoServiceUser = System.getModule("com.vmware.library.microsoft.activeDirectory").getUserFromContainer(usersOU,tenantName + "_vCOSvc");
var tenantAdminUser = System.getModule("com.vmware.library.microsoft.activeDirectory").getUserFromContainer(usersOU,tenantName + "_TenantAdmin");

System.log("Tenant admin is: " + tenantAdminUser.distinguishedName);

// Create the Tenant Admin and Infra Admin groups
System.getModule("com.vmware.library.microsoft.activeDirectory").createUserGroup(tenantName + "_TenantAdmins",groupsOU);
System.getModule("com.vmware.library.microsoft.activeDirectory").createUserGroup(tenantName + "_InfraAdmins",groupsOU);

// Retrieve the Tenant Admin and Infra Admin groups and fix the SamAccountName
tenantAdminsGroup = System.getModule("com.vmware.library.microsoft.activeDirectory").getUsergroupFromContainer(groupsOU,tenantName + "_TenantAdmins");
tenantAdminsGroup.setAttribute('SamAccountName',tenantName + "_TenantAdmins");

infrastructureAdminsGroup = System.getModule("com.vmware.library.microsoft.activeDirectory").getUsergroupFromContainer(groupsOU,tenantName + "_InfraAdmins");
infrastructureAdminsGroup.setAttribute('SamAccountName',tenantName + "_InfraAdmins");
//Add tenant admin to admin groups
var tenantAdminUserArray = [tenantAdminUser];
tenantAdminsGroup.addElements(tenantAdminUserArray);
infrastructureAdminsGroup.addElements(tenantAdminUserArray);

vCOADPlugin35

Finally we need to get the usersOU and groupsOU out of the workflow, having already used them in the workflow. Add an additional scriptable task to do this.

vCOADPlugin42 vCOADPlugin43

vCOADPlugin44

vCOADPlugin46

 

 

 

That’s our completed AD workflow.

It’s worth testing the workflow at this point to ensure that everything works so far.

vCOADPlugin37

vCOADPlugin38

And here’s the result

vCOADPlugin39

 

 

 

Automating vCAC Tenant Creation with vCO: Part 1 AD SSL
Automating vCAC Tenant Creation with vCO: Part 2 AD Users, Groups and OUs
Automating vCAC Tenant Creation with vCO: Part 3 Install the vCAC plugin for vCO
Automating vCAC Tenant Creation with vCO: Part 4 Creating a Tenant
Automating vCAC Tenant Creation with vCO: Part 5 Creating an Identity Store
Automating vCAC Tenant Creation with vCO: Part 6 Adding Administrators
Automating vCAC Tenant Creation with vCO: Part 7 Creating a vCAC Catalog Item