- Machine Prefix/Property Definition – Part 1
- Powershell – Part 2
- Workflow Configuration – Part 3
- Blueprint Update – Part 4
Review
In part 1, we configured the Machine Prefix, Property Dictionary and layout to accommodate our change. In part 2, we created and saved a powershell script to create the desired machine name from the inputs we provided. In part 3, we’ll modify the Building Machine workflow stub to create and assign a new machine name. We’ll be using the vCAC Designer, so make sure you have it installed and accessible.
Steps
- Launch the vCAC Designer, Load the
WFStubBuildingMachine
workflow from the list. - In the “Building Machine Workflow” try/catch loop, double-click the “Building Machine” flowchart to expand it. Now, locate a double-click on the “Custom Code” flowchart to expand it. The Breadcrumb should read
WFStubBuildingMachine > Building Machine Workflow > Building Machine > Custom Code
- At the bottom of the designer pane, click “Variables” to display and add variables to this flowchart. Add the following variables to the Custom Code scope:
Name Variable Type vmName String vmwareOS String machineRole String PowerShellOutVar String machine DynamicOps.ManagementModel.VirtualMachine Did you notice that “mgmtContext” variable that was already in there? We’re going to use that later.
- From the DynamicOps.Cdk.Activities pane, drag the “GetMachineName” object to the Custom Code flowchart box. Select/highlight it and in the properties pane, set the “Machine Id” value to
VirtualMachineId
, Set the Machine Name value tovmName
- Again from the DynamicOps.Cdk.Activities pane, drag the “GetMachineProperty” object to the Custom Code flowchart box. Select/highlight it and in the properties pane, set the “Machine Id” value to
VirtualMachineId
, set the PropertyName to"VMware.VirtualCenter.OperatingSystem"
, set the PropertyValue tovmwareOS
, leave IsRequired empty. I also set the DisplayName toGetVMwareOS
because we’ll use several of the GetMachineProperty activities and need to be able to tell them apart. - Once again from the DynamicOps.Cdk.Activities pane, drag another “GetMachineProperty” object to the Custom Code flowchart box. Select/highlight it and in the properties pane, set the “Machine Id” value to
VirtualMachineId
, set the PropertyName to"custom.machineRole"
, set the PropertyValue tomachineRole
, leave IsRequired empty. Set the DisplayName toGetMachineRole
so we can tell at a glance what it’s doing. - Drag the “InvokePowershell” activity to the Custom Code flowchart box, under the GetProperty activities.. Just like previously, select/highlight it and populate the properties on the right. This activity has several more properties than the others, but we’re only going to be using a few. First, check the “IsScript” box to indicate that the CommandText value points to a PowerShell script. Then, set the Commandtext value to the path (in quotes) to the PS script you saved on the IaaS Server;
"C:\scripts\CreateNewMachineName.ps1"
.Lastly, click the ellipsis button beside PowerShellVariables to set them. Add the following PowerShell Variables (these should look familiar, from Part 2):
Name Direction Type Value vmwareOS In String vmwareOS machineRole In String machineRole originalName In String vmName PowerShellOutVar OUT String PowerShellOutVar - From the “Primitives” section of the toolbox, drag “Assign” to the custom code flowchart box, under or beside the InvokePowershell action. Admittedly, this thing is somewhat confusing. It’s used to instantiate an object from the database for manipulation. You cannot just update the MachineName property in the request, you have to pull the machine object out, set the property on the object, then push the updated object back into the database. So, select/highlight your “Assign” statement object and set the “To” property to
machine
and the “Value” property tomgmtContext.VirtualMachines.Where(Function (vm) vm.VirtualMachineID = virtualmachineId).FirstOrDefault()
Thanks to Tom O’Rourke for that LINQ query!
- Drag another “Assign” statement next to the first. This one will be used to assign the value from our PowerShell script to the virtualmachinename property of the machine object. So, set the “To” property to
machine.virtualmachinename
and the “Value” toPowerShellOutVar
- (Almost done) From the “DynamicOps.Repository” section of the toolbox, drag an “UpdateObject” activity object to the Custom Code area. Just as before, select/highlight it. Set “DataServiceContext” to
mgmtContext
. Set “Instance” tomachine
. That’s it. - Also from the “DynamicOps.Repository” section of the toolbox, drag a “SaveChanges” activity object to the Custom Code area. Just as before, select/highlight it. Set “DataServiceContext” to
mgmtContext
- Link it up! Use the tabs that appear on the side of the objects to connect them in the following order:
Start -> GetMachineName -> GetVMwareOS -> GetMachineRole -> InvokePowerShell -> Assign (machine) -> Assign (machine.virtualmachinename) -> UpdateObject -> SaveChanges
- Click “Send” to save your updated version of the workflow to the database
3 thoughts on “Setting the Machine Name of a vCAC-provisioned VM to comply with a Corporate Standard Part 3 of 4”
Comments are closed.