Adding scripts to Embotics® vCommander® workflows allows you to fine-tune the already powerful automation options and make sure that deployments are happening the right way. You can pass information, like VM name, into Embotics vCommander to make sure a consistent naming convention is used in your environment. Using scripting the name can be constructed based on information from external systems or the values entered by the user at the time of the request.


This article demonstrates specifying the VM name based on the values entered in the form when the service was requested. These are the operating system, owner and unique number, so the resulting VM name will be in the format: Jesse-2k8-001. You can use other information to construct your names as well, including custom attributes you add to Embotics vCommander.


Important: The solution described in this article will work for services that include a single VM component. Using this solution with multiple VM components will cause all the VMs to deploy with the same name.


Creating the Script


Use any text editor to create this Powershell script, which you must save with the name VMname.ps1. Alternatively, download a copy here.

 

#Build a format string for the name of the VM
#This can call out to an external program or manipulate the strings in the code as
#below
#Get the owner name
$name = $args[0]
#Split owner name into first and last and keep the first name
$first = $name.split()[0]
#Get the operating system
$os = $args[1]
#Abbreviate the OS name
if ($os -like ‘*2012*’){$os = ‘2k12′}
elseif ($os -like ‘*2008*’) {$os = ‘2k8′}
elseif ($os -like ‘*2003*’) {$os = ‘2k3′}
elseif ($os -like ‘*RHEL*’) {$os = ‘RH’}
elseif ($os -like ‘*Ubuntu*’) {$os = ‘UB’}
else { write-host Unknown OS $os; exit 1}
#Return the format string so V-Commander can add the unique number
$format = ‘$VMNAME=’ + $first + ‘-‘ + $os + ‘#{uniqueNumber[3]}$’
write-host $format


In the example workflow displayed below, it’s assumed that the VMname.ps1  is saved on the Embotics vCommander server in the location C:\scripts\.


Configuring the Approval Workflow


Follow the procedure below to configure an approval workflow step  that uses the script you’ve created in the previous section. Depending  on your needs, you may have other steps required, but only the execute  script step that would occur after all approvals have been granted is  discussed here.

  1. Under the Configuration menu, choose Service Request Configuration.
  2. Switch to the Approval Workflow tab.
  3. Create a new approval workflow for new requests, or edit an existing workflow for new requests.
  4. On the Steps page, click Add and choose Execute Script.
  5. Provide a meaningful name, such as Determine VM Name.



  6. Choose appropriate settings for Step Execution. You  can always run the script to name the VM, or check a condition, for  example how much it costs, and execute the step only when the condition  has been satisfied.
  7. Leave the default Timeout value as it is.
  8. Select Capture script output as comment for Script Output.
  9. Select Mark workflow step as failed: do not proceed as the action to take When Script Fails.
  10. Enter the following as the Command Line: powershell  -ExecutionPolicy bypass -file c:\scripts\vmname.ps1  "#{request.requester.name}"  "#{request.services[1].components[1].description}"

  11. Click Next.