- Machine Prefix/Property Definition – Part 1
- Powershell – Part 2
- Workflow Configuration – Part 3
- Blueprint Update – Part 4
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.
- Launch the vCAC Designer, Load the
WFStubBuildingMachineworkflow 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
- 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 to
- 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 to
vmwareOS, leave IsRequired empty. I also set the DisplayName to
GetVMwareOSbecause 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 to
machineRole, leave IsRequired empty. Set the DisplayName to
GetMachineRoleso 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
machineand the “Value” property to
mgmtContext.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.virtualmachinenameand the “Value” to
- (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” to
machine. 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
- 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