Dynamically Assigning Property Dictionary Values

What makes vCAC such a dynamic product is definitely the use of the Property Dictionary.
If you’re still not familiar with it, you can read about it here (or here)
When using the property dictionary, you can unleash the full potential of the product. When you are able to update the property dictionary values dynamically, the possibilities are endless.

One example of using this scenario of dynamically updated property dictionary is allowing the user to set which vSphere portgroup (or VLAN) the machine will have when created. When a new portgroup is created in vsphere, the vCAC machine request page will be updated automatically as well.

For this special (and really important) use case , I’ve written a powershell module for vCAC Property dictionary (currently is @ version v0.9) with the help of some REST/JSON Functions written by Tom O’rourke . You can download the powershell module at the bottom of the page as well. Now, with the help of powerCLI & and the vCACPSModule we can grab all of vSphere’s portgroups, and dynamically add them to a vCAC property. Lets see how!

First, we need to open a powershell console on our vCAC Module Manager web server , and type in the following commands:

– This will create a new Property Dictionary for us to use, we can do this through the UI as well.

[powershell]
Import-Module vCACPSModule
New-vCACProperty -server vcac.domain.com -PropertyName "VirtualMachine.Netowrk.Choice" -PropertyType DropdownList -IsRequired True
[/powershell]

– Our second stage is to create and schedule a script with the following code, in order to get vsphere portgroups and dynamically insert them into the vCAC Property dictionary with the help of the vCAC Powershell Module (Adjust the logic for getting the networks you actually need by cluster / name etc / use different network choices for different blueprints etc)

[powershell]
# GrabvSphereNetworks.ps1
Import-Module vCACPSModule
Add-PSSnapIn vmware.vimautomation.core
connect-viserver $vCenter -username $user -password $Password
# Edit to retrieve portgroups according to any logic you want
$Networks = Get-virtualportgroup | where-object Name -match "dvp" | Select Name -unique
# Changes the network list to something in format of a comma delimited string: "net1,net2,net3"
$Networks = ($networks | select -expand name ) -join ","
# Updates the vCAC property with the new values
update-vcacpropertyattribute -server vcac.domain.com -PropertyName "VirtualMachine.Network.Choice" -AttributeName Networks -AttributeType ValueList -AttributeValue $Networks
disconnect-viserver -confirm:$false
[/powershell]

– Third stage, is to add the “VirtualMachine.Network.Choice” property we’ve created to our blue print, and create a workflow for the machine to set “VirtualMahchine.Network0.Name” property, with the network we want it to have. Here, we’ll use the building machine stub workflow in order to do so.

Setting our blueprint with the relevant properties:

Adding the Blueprint with Custom Property we created

When requesting the machine we will be able to select a Network from our property:

Now lets create the workflow for actually setting the machine’s network property.

Open the vCAC Designer, and create a workflow for changing the VM network. First, load the “ExternalWFStubBuildingMachine” workflow, and edit it like so:

DesignerNetwork

Don’t forget to create a Variable named “NetworkName” (or any other name) with a String Type.

Also, you need to set the red marked properties for each activity. On GetMachineProperty we’ll set

  • MachineID -> virtualmachineid
  • PropertyName – > “VirtualMachine.Network.Choice” (dont forget ” sign)
  • PropertyValue -> NetworkName (Our created string variable)

At the SetMachineProperty, we’ll just set

  • MachineID -> virtualmachineid
  • PropertyName -> “VirtualMachine.Network0.Name”
  • PropertyValue -> NetworkName (Our created string variable)

Now we’ll Load the workflow back to the database.

In order for this to work , technically the networks that are in the custom property should be checked at the vCAC reservation level. you can simply check all of the networks when you create the reservation, and re-select each newly added portgroup to the vSphere environment, while I figure out how to get this automatically done via the API’s as well :)

Also, you need to schedule the GrabvSphereNetwork.ps1 script , for it to update the dictionary property on a permanent basis.

But more importantly, this PS Module can be of use to plenty of other use cases, for example:

  • Building machines in specific vSphere Directories per property choice
  • Choosing Machine’s Service classification from CMDB (simply sync the dictionary properties with services existing in CMDB using powershell)

If you think of any other scenarios – Let me Know!!! Comment section is below :)

vCAC PS Module Download

You can see example usage of the module’s functions at the file’s bottom section! There are some really cool CSV capabilities!


Comments
Harvey Specter
Posted at 3:55 pm October 10, 2013
Robert Heckenbichler
Reply
Author

hi,
great blog.
vg
robert

Harvey Specter
Posted at 3:59 pm October 10, 2013
Robert Heckenbichler
Reply
Author

hi,
do you see any Chance that only the Networks are shown to which the self Service user is allowed to Provision? In your example the user will see alll Networks (like vmotion). In my case there is a self Service user which only have Access to his own cloud Network (for example Net-Cloud-A 192.168.1.0/24). So in your list should only this Network be listed. I don’t want that my self Service users place a vm into the vmotion Network.
best regards
robert

    Harvey Specter
    Posted at 4:11 pm October 10, 2013
    Omer Kushmaro
    Reply
    Author

    Hi Robert,

    Well my example only meant to show the capability itself… if you’d want to make a user see his own networks, maybe you could give each portgroup a naming scheme that is consistent with vCAC provisioning groups, and then use the Property dictionary to set up a drop down list that selects only portgroups using that naming scheme.

    Example:

    dvp-DevLan-vlan10

    dvp-DevLan-vlan20

    dvp-QALan-vlan30

    you would just need to change the

    “$Networks = Get-virtualportgroup | where-object Name -match $ProviosioningGroupProperty | Select Name -unique”

    That way it should filter by the Provisioing Group the user is coming from.

    Best Regards,
    Omer

Harvey Specter
Posted at 10:00 am November 26, 2013
d-fens GmbH
Reply
Author

Hi Omer, I just came across your VCAC PS Module. Did you know that you can actually use the MgmtContext of vCAC directly, so you do not have to create the REST calls manually? Have a look at http://d-fens.ch/2013/10/10/investigating-the-vcac-5-2-mgmtcontext/ or check the assembly directly. Regards, Ronald

    Harvey Specter
    Posted at 10:36 am November 26, 2013
    Omer Kushmaro
    Reply
    Author

    Hi Ronald,
    Thanks for the tip, I actually know this functionality, but the thing is, here i’m doing very simple stuff with the property dictionary , to be able to sync with outer systems on a scheduled basis, and not during a provisioning stage.

    The Rest functions were actually the works of Tom O’rourke , who’s one of the developers & founders of the vCAC product.

      Harvey Specter
      Posted at 12:15 pm November 26, 2013
      d-fens GmbH
      Reply
      Author

      yep I can now see the similarity of the script. We are actually doing the same as you and load properties from external systems periodically and still use the MgmtContext (and that’s the cool thing about – that you can use the assembly either from within workflows or just stand alone). But anyway, I got your point …
      Regarding your API remark for checking only selected networks you can also do this with the MgmtContext by correlating the HostNics and HostNicsToReservation tables for each reservation and host. You can check the picture here: http://d-fens.ch/2013/11/25/change-virtualmachine-reservation-and-storagepath/

Harvey Specter
Posted at 3:32 pm April 24, 2014
aenagy
Reply
Author

Will this work with vCAC 6?

    Harvey Specter
    Posted at 6:40 am July 15, 2014
    Kushmaro
    Reply
    Author

    yes it will, just replace the vCAC server with the IaaS model manager component

      Harvey Specter
      Posted at 10:48 am August 4, 2014
      Henry Hazot
      Reply
      Author

      Hi,
      I’v used your script and at the end i was able to receive the list of all of my DVswitchs in the new request field.
      Next up i used the VCAC designer to customize the workflow and entered all of the requested fields.
      At the end i send the changes to the DB that completed successfully.

      But, after i deployed a new vm and selected a specific DVswitch the clone vm didn’t get the requested DVswitch.
      It got connected to a random DVswitch.

      Thanks in advanced,

Harvey Specter
Posted at 2:11 pm April 7, 2015
Brandon Jackson
Reply
Author

Hi — great article. I see it was written 18 months ago and I’m curious if you have an updated version of the vCACPSModule?

    Harvey Specter
    Posted at 9:13 am April 12, 2015
    Kushmaro
    Reply
    Author

    Hi Brandon,
    As discussed via emails – This won’t work for 6.X (which is a shame really…) only for 6.0.X
    I’ll try and make the time to re-implement this according to recent API changes made in vRA.

    Thanks for the heads up!

Harvey Specter
Posted at 2:07 pm July 22, 2015
Fabd
Reply
Author

Hello Kushmaro,

Did you find time to implement your great module with 6.2.x ? This is just what i was looking for. Managing property with powershell.

hope it will be possible

    Harvey Specter
    Posted at 10:18 am July 31, 2015
    Kushmaro
    Reply
    Author

    (very) unfortunately, no :( I’ve been doing had a LOT of stuff lately and my ‘out of work development’ time had went down to an absolute 0%.
    You could however, contact your local VMware team and ask about ‘CCC’ extension for vRA.
    This extension will enable you to do some powershell driven stuff with latest version of vRA, and I believe it is free of charge.

Leave a Reply

Navigation