Importing a vRO Package via the API – tagImportMode

I like the new Swagger UI for the vRO API, it makes it really easy to use:

tagImportMode01

While using it to figure out some stuff around importing a package, I hit an issue with the tagImportMode parameter:

tagImportMode02

Depending on which option selected, the following additions to the URL were listed in the documentation as follows:

https://vroserver.fqdn:8281/vco/api/packages?overwrite=false&importConfigurationAttributeValues=true&tagImportMode=Do%20not%20import%20tags.

https://vroserver.fqdn:8281/vco/api/packages?overwrite=false&importConfigurationAttributeValues=true&tagImportMode=Import%20tags%20and%20overwrite%20existing%20values.

https://vroserver.fqdn:8281/vco/api/packages?overwrite=false&importConfigurationAttributeValues=true&tagImportMode=Import%20tags%20but%20preserve%20existing%20values.

However, none of these choices seemed to work, just resulted in 400 (Bad request). Some trial and error followed with different possible combinations, but eventually I found two of them documented in the Developing a Web Services Client for VMware vCenter Orchestrator guide for vCO 5.5.1 and so was able to guess the third.

&tagImportMode=DoNotImport

&tagImportMode=ImportAndOverwriteExistingValue

&tagImportMode=ImportButPreserveExistingValue

Panini Euro 2016 Sticker Tracker

I was using the Panini iPhone app to track our Euro 2016 sticker collection until it helpfully lost all of the data I had input. So I went back to an Excel workbook I had created for previous tournament collections and thought it would be worth sharing it.

On the data sheet track via a colour which stickers you have got, then you can easily see which ones you still need.

Euro201601

On the Swaps sheet, list out your swaps:

Euro201602

Then on the Analysis sheet you will get some figures and graphs to track your collecting progress:

Euro201603

Euro201604

 

You can download the Excel workbook from here.

PowervRA 1.2.2 with Tested Support for vRA 6.2.4

One of the things we did for the 1.2.2 release of PowervRA was to test all of the functions against a vRA 6.2.4 deployment. Now that we have created Pester tests for all of the functions, it is quite straightforward for us to test against different vRA versions.

While we had initially targeted vRA 7+ because of the better API support, we know that currently the majority of installations out there are 6.x.x. So we are happy to confirm that 58 of the functions work fine with 6.2.4, which was a slightly higher figure than I was expecting.

All of the functions which will not work pre v7 have been updated to include an API version check and will exit the function with a message to reflect that if you try to use  them with 6.x.x, e.g.

Get-vRAContentPackage is not supported with vRA API version 6.2

v6Support01

 

Using Pester to Automate the Testing of PowervRA

Learning Pester has been on my list to get done this year and while working on PowervRA I finally had a real project that could make significant use of it. Being able to automate the testing of each PowerShell function means that we can quickly test the impact of any changes to a function. Also, it means that we can test the whole module full of functions against new (and potentially old) versions of vRA.

There is a very useful introduction to Pester on the Hey Scripting Guy site and that is what I used to get started with it.

So after we released the first version of PowervRA I set about creating a test for each function in the module – and here is where I learned my first mistake, although to be fair I knew I was making this mistake during the initial development of PowervRA. With 70+ functions in the module at that time, I needed to write a test for each of them. So after the initial interest in learning how Pester works, I then had the boring task of writing all of the tests.

What (I knew) we should have done, was write a Pester test for each function during (or before) the development of that function. Consequently, it would not seem like such a laborious task to make them. So going forward that’s what we are doing each time we create a new function.

So what does a test look like? Well here is one for Reservation Policies:

You should see that each set of tests is grouped in a Describe section. Each test starts with the It keyword, then typically we do something and check a property of the object returned afterwards. The Should keyword enables us to specify something to check the result against. As you can see Pester has been made so that the tests should be quite nicely readable.

We then follow a pattern of New-xxx, Get-xxx, Set-xxx, Remove-xxx, which all being well leaves us with a clean environment after the tests.

For these tests, we want to check each function against a real life instance of vRA, consequently we need some values. I’m not sure if this is the best way to do it, but for the time being we’ve abstracted the data out of the test files and into a JSON file of variables. This means if we want to run the same tests against a different instance of vRA, we just need to change some of the values in that file. (There is a way to carry out Unit testing in Pester using Mocking which we may visit at some point)

An example of how we can use them is as follows. We can fire the tests against a vRA 7.0 instance and get the following results:

Pester02

By changing some of the variables in the JSON file, we can then fire the same tests against a vRA 7.0.1 instance:

Pester03

and so we can tell with a good degree of confidence that nothing is broken for PowervRA between the two versions. As you can see we can run 81 tests in 60 – 75 seconds, which is pretty cool 🙂

Craig and I have discussed that we are only really scratching the surface with the tests so far and we could probably take someone onto the project who is solely dedicated to the testing (If you are interested, let me know 🙂  ). For example, for the time being we are only checking one property per New-vRAxxxx thing which gets created, ideally we should really test every property. For now though, what we have got so far is a big step forward and I’m looking forward to learning more about Pester.

If you want to check out what we have done with the tests you can find them here.

Import a Package from a Folder in vRO 7.0.1

vRO 7.0.1 in Design mode contains a new toolbar button in Packages; Import package from folder:

ImportFromFolder01

Previously it was possible to export a vRO package to either a zip file or directly to a folder, but only import back from a zip file.

For example, take the following package com.jm.test, which contains 3 workflows and 1 action:
ImportFromFolder02ImportFromFolder03ImportFromFolder04

Exported to a folder test, we get the following:

ImportFromFolder05 ImportFromFolder06 ImportFromFolder07

 

Now in a clean vRO server, I currently do not have those workflows:

ImportFromFolder07b

If I select the Import Package from folder button, I can browse to the folder contained the previously exported to a folder package:

ImportFromFolder08

Then the process to import the package is the same as in the previous vRO versions when importing from a zip file:

ImportFromFolder09

ImportFromFolder10

and now I can use the workflows and action

ImportFromFolder11

ImportFromFolder12

 

Not only is this very handy, it is potentially significant, because it may make it slightly easier to integrate vRO workflow development with source control systems.

vRO requestCatalogItem from vRA Action – Available Properties

The vRO Action requestCatalogItem in the com.vmware.library.vcaccafe.request folder can be used to programmatically request an item from a vRA Catalog.

RequestCatalogItem01

One of the inputs is a properties object which permits you to dynamically make changes to settings configured within the Catalog Item you are deploying from. So say for instance the Catalog Item maps to a Blueprint configured with 1 vCPU, you could change this at request time to be 2 vCPU – which for instance might lead you to needing to maintain fewer Catalog Items.

It’s possible that it exists already, but I haven’t been able to find where the entire list of available properties that you can use are documented. Many of those starting VirtualMachine. or VMware. can be found in the vRA Custom Properties guide, so I’m not going to list them all here. However, not every available property in those ranges actually appear to be in that guide.

So I have decided to maintain a list here garnered from various sources, including a few common ones from the Custom Properties guide. If you know of any others not in the Custom Properties guide, then please leave a comment and I’ll add them:
provider-blueprintId: vRA Blueprint
provider-ProvisioningGroupId: Business Group

provider-VirtualMachine.CPU.Count:
provider-VirtualMachine.Memory.Size:
provider-VirtualMachine.NetworkX.NetworkProfileName: Network profile for NIC 0
provider-VirtualMachine.NetworkX.Name: Network Name (portgroup) for NIC 0

provider-VirtualMachine.DiskX.IsClone:
provider-VirtualMachine.DiskX.Size:

provider-VirtualMachine.DiskX.StorageReservationPolicy: vRA Storage Reservation Policy
provider-VirtualMachine.DiskX.StoragePolicy.FriendlyName: vCenter Storage Policy
provider-VirtualMachine.DiskX.StoragePolicy.vCenterStoragePolicy: vCenter Storage Policy

provider-VirtualMachine.LeaseDays

provider-VMware.VirtualCenter.Folder: Virtual Center folder
provider-Cafe.Shim.VirtualMachine.TotalStorageSize:
provider-Cafe.Shim.VirtualMachine.Description: Description
provider-Cafe.Shim.VirtualMachine.AssignToUser: vRA Machine owner
provider-Cafe.Shim.VirtualMachine.NumberofInstances: Number of VMs to deploy
provider-CustomPrefix
provider-__reservationPolicyID: vRA Reservation Policy

 

Create a vRA Tenant and set Directory and Administrator Configuration with PowervRA

One of the reasons behind creating PowervRA was as a consultant I often have the need to quickly spin up vRA Tenants and / or components within those Tenants to facilitate development or testing work of other things I am automating. PowervRA contains three functions, which when joined together would make a basic vRA Tenant available for use: New-vRATenant, New-vRATenantDirectory and Add-vRAPrincipalToTenantRole.

The following code example demonstrates how to use these in conjunction with each other to make a vRA Tenant (make sure to first of all have generated an API token with Connect-vRAServer with an account that has permission to create a vRA Tenant):

Note that since New-vRATenantDirectory has a lot of parameters, I have taken advantage of the ability to instead provide the necessary JSON text directly to it.

The result is a fresh vRA Tenant with a Directory configured and admin accounts assigned to both the Tenant Admins and Infrastructure Admins roles:

CreateTenantPowervRA02

 

CreateTenantPowervRA01

Find the vRO Workflow ID for an Advanced Service Blueprint with PowervRA

A colleague asked me the other day about how it might be possible to find out which vRO workflow was mapped to an Advanced Service Blueprint (or XaaS Blueprint) in vRA. If you look in the vRA GUI after a Service Blueprint has been created you can’t see which vRO workflow is mapped.

During the creation of the Service Blueprint there is a Workflow tab to select the vRO Workflow:

ServiceBlueprintPowervRA01

 

However, once it has been created, there is no longer a Workflow tab, so you can’t see which vRO workflow is used:
ServiceBlueprintPowervRA02

By using PowervRA though we find this information. The object returned by Get-vRAServiceBlueprint contains a WorkflowId property:

ServiceBlueprintPowervRA03

We can now take that WorkflowId and find the corresponding workflow in vRO. Unless you have memorised all of the workflow IDs then you can issue a REST request to vRO to find out more. The following example uses PowerShell to query the vRO REST API for the WorkflowID above (note that we have to deal with self-signed certificates):

If we look at the data stored in the Workflows variable, we can see the name of the workflow in vRO (OK in this example it’s the same name as the Service Blueprint, but it might well not be in another example):

ServiceBlueprintPowervRA04

Also, if you look at $Workflows.relations.link you will see the first result shows the path in vRO to track down the workflow:ServiceBlueprintPowervRA05

i.e., it can be found in the top-level folder named Test:

 

ServiceBlueprintPowervRA06

Automate vRealize Automation with PowerShell: Introducing PowervRA

While putting together the PowerCLI book 2nd Edition we initially included in the proposed Table of Contents a chapter on vRealize Automation. However, it was fairly apparent that at that time (early 2015) there wasn’t a lot which could be done to fill out the chapter with good content. Firstly, most of the relevant content would be included in the vRO chapter, i.e. use vRA to call a vRO workflow to run PowerShell scripts. Secondly, automating elements within vRA 6.x could be done in part via the REST API, but a) there was a roughly 50 / 50 split between what was in the REST API vs Windows IaaS and b) I didn’t really have the time to make both a PowerShell toolkit for vRA and write a book about PowerCLI.

So we shelved that chapter and I put the thought to the back of my mind that I would revisit the idea when vRA 7 came out and the likelihood of greater coverage in the vRA REST API. At the start  of 2016 this topic came up in a conversation with Xtravirt colleague Craig Gumbley who it turned out had the same idea for making a PowerShell vRA toolkit. So we decided to combine our efforts to produce a PowerShell toolkit for vRA for both our own use as consultants and also to share with the community; consequently the project PowervRA was born.

Initial Release

For the initial release we have 60 functions available covering a sizeable chunk of the vRA 7 REST API. Compatibility is currently as follows:

vRA: version 7.0 – some of the functions may work with version 6.2.x, but we haven’t tested them (yet). Also, they have not been tested with 7.0.1.

PowerShell: version 4 is required.  We haven’t tested yet with version 5, although we wouldn’t expect significant issues.

You can get it from Github  or the PowerShell Gallery

We have provided an install script on Github if you are using PowerShell v4. If you have v5 you can get it from the PowerShell Gallery with:

Getting Started

Get yourself a copy of the module via one of the above methods or simply downloading the zip, unblocking the file and unzipping,  then copying it to somewhere in your $env:PSModulePath.

PowervRA01

PowervRA02

Import the module first:

You can observe the functions contained in the module with the following command:

Before running any of the functions to do anything within vRA, you will first of all need to make a connection to the vRA appliance. If you are using self signed certificates, ensure that you use the IgnoreCertRequirements parameter. :

You’ll receive a response, which most importantly contains an authentication token. This response is stored automatically in a Global variable: $vRAConnection. Values in this variable will be reused when using functions in the module, which basically means you don’t need to get a new authentication token each time, nor have to specify it with a function – it’s done for you.

Each of the functions has help built-in, alternatively you can visit this site http://powervra.readthedocs.org

Example Use Case: Create a vRA Tenant

Having made a connection to the appliance, it’s now time to start using some of the functions. To create a Tenant in vRA we need to have made a connection to vRA with an account that has permissions to do so in the default tenant (typically [email protected]) and then it is as simple as the following:

PowervRA03

PowervRA04

If you look through the rest of the functions, you may notice that a lot of them contain a JSON parameter. So if you know the JSON required for the REST API request or are working with a system that produces it as an output, you can do something like the following:

The Future

VMware may put out something official at some point (I have no inside info on that, it could be weeks, months, years away or not even planned right now). Until that happens Craig and I have various things planned including greater coverage of the API, dealing with any feedback from this release and looking at automating some of our own testing so that we can more easily figure out which vRA versions are supported.

In the meantime, fill your boots and if you want to help us, feel free to get involved via the Develop branch on GitHub.