Home > vCloud Automation Center > Setting the Machine Name of a vCAC-provisioned VM to comply with a Corporate Standard Part 3 of 4

Setting the Machine Name of a vCAC-provisioned VM to comply with a Corporate Standard Part 3 of 4

03/17/2014

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

  1. Launch the vCAC Designer, Load the WFStubBuildingMachine workflow from the list.Load Workflow
  2. 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 CodeBreadcrumbs
  3. 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

    Custom Code Variables Did you notice that “mgmtContext” variable that was already in there? We’re going to use that later.

  4. 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 vmNameGetMachineName Properties
  5. 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 GetVMwareOS because we’ll use several of the GetMachineProperty activities and need to be able to tell them apart.GetVMwareOS Properties
  6. 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 GetMachineRole so we can tell at a glance what it’s doing.GetMachineRole Properties
  7. 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". InvokePowerShell PropertiesLastly, 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

    Powershell VariablesClick Ok to save the Powershell Variables

  8. 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 to mgmtContext.VirtualMachines.Where(Function (vm) vm.VirtualMachineID = virtualmachineId).FirstOrDefault() Assign machine ObjectThanks to Tom O’Rourke for that LINQ query!
  9. 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” to PowerShellOutVarAssign Name
  10. (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.UpdateObject
  11. 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 mgmtContextSaveChanges
  12. 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 -> SaveChangesCustomCode flowchart
  13. Click “Send” to save your updated version of the workflow to the database

Continue to Part 4 – Updating the blueprint

Advertisements
%d bloggers like this: