Automating vRA IaaS Blueprint creation with vRO

In some situations it might be very convenient to be able to automatically create vRA (vCAC) Iaas blueprints. However, since the IaaS part of vRA uses an OData API doing so is not a trivial task. OData is basically just a representation of the IaaS database. So there is no logic in front of it and thus no way to tell the API: “Create a blueprint for this VM please”. Previsously I talked a bit about the vCAC API. In this post I’ll get more practical and explain the steps involved when automating vRA IaaS blurptint creation with vRO.

Entities

All objects in the IaaS OData API are called entities. It doesn’t matter if it is a blueprint, a host or a build profile, everything is an entity. So in order to create a new blueprint we have to create a new entity. Which is done with the following line of code:

the createModelEntiy method  needs a couple of input parameters. The first one is easy, it’s the id of the vCACServer. This is the IaaS server object in vRO not the vCACCAFE host. You can just configure this server as an input of the workflow.

The second parameter is always “ManagementModelEntities.svc” and the third one is basically the table name of where the entity should end up. In the case of a blueprint entity it’s always “VirtualMachineTemplates” because that’s the table where the blueprints live.

Now for the tricky part: the parameter and links values.

Parameters

The parameters for the entity are basically the properties of the object. The trick is figuring out which properties to use. There are a couple of methods. You could create a simple workflow that just dumps all the properties of an existing blueprint entity in a log. I prefer using LINQpad because it also shows you the relations between different tables.

So which properties do we need for the blueprint entity and how do we put them into the parameters variable? The script below shows how to do this.

Obviously you might want to change the TenantID or get it from a variable.

Links

An entity object is basically an entry in a database table. This table links to other tables. So when creating a new entity you need to define to which elemetns in other tables this entity links to.

For blueprint entities there are 5 links to be set:

  • InterfaceType (vSphere in this case)
  • HostReservationPolicy (The reservation policy to deploy to)
  • ProvisioningGroup (A.ka Businiss Group)
  • WorkflowInfo (This is the kind of deployment you want. So for a BP that clones a template you need the Clone Workflow WorkflowInfo entity… still with me?)
  • GlobalProfiles (A.k.a Build Profiles)

This is how you put those links into a links object:

As you can see each attribute in the object is an array. The content of the array are vCAC Entities.  Most arrays have one value only the globalProfiles has multiple values if you have more then one build profile selected. In the code above I the buildProfiles variable is defined somewhere else and it is already an array so I left out the [ ].

Finding links entities

I guess you’re now wondering how to get the entities object for the links. You need to use the vCACEntitieManager to find these entities. Here is an example of how to find the WorkflowInfo entity for the clone workflow:

You can find the reservation policy by name in a very similar way:

If you have an array with build profile names as in input you can find all the corresponding entities with this piece of code:

If you want more of this in a workflow that’s ready to run, see the link at the end of this post.

Properties

So now we are able to create an entitie with the right parameters and links. After that’s successfully done there is one more thing we need to do: configuring the custom properties on the blueprint.

There are a couple required properties which start with a double underscore. Here is the list I used:

__buildprofile_order (order in which the buildprofiles are applied)
__clonefromid (id of the virtualmachineTemplate entity we created)
__clonefrom (name of the vmtemplate entity we created)
__clonespec (name of the customization spec in vCenter)
__displayLocationToUser (false)
__menusecurity_snapshotmanagement (false)
VirtualMachine.DiskN.IsClone (true for each disk)
VirtualMachine.DiskN.Size (the size of each disk)

You can set these properties with the “Update Property to Blueprint” workflow that comes with the vCAC plugin.

I used this script to generate the buildprofile order:

 Just give me the workflow

Too much information? I uploaded the example workflows to flowgrab. Find the download here.

A word of warning: The workflows might assume you’re using the vsphere.local tenant in vCAC. Should be easily fixable. If I’ve got some timeleft in the near future I might fix that myself. If you’re using another tenant you should be able to easily makes this work for you anyways.

15 thoughts on “Automating vRA IaaS Blueprint creation with vRO”

  1. This is great, thanks so much for publishing it!

    Did you manage to get the Blueprint to be published?

    I set the line:

    “IsPublished”: true,

    which makes it appear to be published in the GUI in Blueprints, since there is a Yes in the published column. However, when I go to Catalog Items it is not listed as a published item, which suggests another step is also required?

    1. You’re welcome.

      Setting IsPublished to true doesn’t do anything. You’re just changing the setting in the database. The actual process is only kicked off when you click the “Publish” button.
      However, I did figure out how to publish it. Maybe I’ll do another blog post on that.
      But it comes down to creating a new provider catalog item. The providerBindingId needs to be set to the virtualMachineTemplateID. That’s it 🙂

      1. Ah OK. I also noticed that if you set isPublished to be true as above, then open the Blueprint in the GUI and click OK it will be published then too.

        I’d be very interested to see how you did it 😉

  2. Yeah this is pretty awesome for me right now. Currently working on creating 9 blueprints for a migration project. I’m fronting your workflow with a csv file taken from the system I’m importing the blueprints from so I can just automagically create the blueprints in my various environments. Saves me A LOT of time.

    Thanks for this Chris… 🙂

  3. BTW, in the get props scriptable task you have the below to disallow snapshots:

    blueprintProperties.put(“__menusecurity_snapshotmanagement”, “False”);

    It only seems to work if false has a lower case f, like the below:

    blueprintProperties.put(“__menusecurity_snapshotmanagement”, “false”);

    This is what you have in the text in the post, but not in the downloadable code.

    1. I’m sure __clonefromid is not used or at least doesn’t have an effect on which template is deployed. But this property is populated when you create a blueprint through the gui so I think it’s a good idea to populate it from the workflow as well.

  4. Hi Christiaan,

    Fantastic article – very useful.

    Any chance you might be able to provide the script to publish the IaaS blueprint – please of course?

    I very much need this last bit to complete this exercise for a client – thanks!

  5. Hi Christiaan
    Hope all is well. I have tried to get this to work in my environment where I am trying to create blueprints using this workflow.
    For our environment, the default tenant is not used.

    When trying to use this workflow, I can select the VRA host, however when trying to select a business group, the list is empty. To get around this, I made some changes to the workflow so that the tenant ID was changed to our tenant and made a few other changes. When running the workflow, the output shows as successful, however I cannot see the new blueprint. When I run the workflow again, it fails with an output that the blueprint already exists.

    Now when I go to Blueprints on the VRA site, I get application error, similar to this

    https://communities.vmware.com/thread/490748?start=0&tstart=0

    the only way I managed to get this fix was to restore the database from backup.

    My environment is 6.2.1

    Any help would be much appreciated.

    1. The workflow looks up the provisioningGroup in the IaaS part of vRA. a provisioning group is the former name of business groups and is the entity that represents the business group on the IaaS side.
      The lookup is done by first getting the BG ID from the CAFE part of vRA and then searching for a PG with that same ID. If you can’t browse business groups in vRO than that lookup will fail end you end up linking your blueprint to null. So you won’t ever find your BP in the gui 🙂

      To check if this is the case put a System.log(provisioningGroup) in the “Get Entities” script object.

  6. Hello again,

    I ran this workflow and the output showed that the blueprint was created successfully, however when clicking on blueprint in the GUI, i see the following error message

    Application Error
    Error has occurred. For more information, see event logs on the IaaS server or contact your system administrator.

    The only way to get rid of this error is to either restore the database or delete the blueprint row from the sql database in the table dbo.VirtualMachineTemplate

    I was wondering, when creating a new Blueprint, does it populate any other tables apart from dbo.VirtualMachineTemplate and dbo.TemplateToGlobalProfiles?

Leave a Reply

Your email address will not be published. Required fields are marked *