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 required network zone, into Embotics vCommander to make sure the deployed VMs are connected where you want them to be. Some scripts, like the one detailed in this example, are embedded within the workflow itself.


This article demonstrates specifying the required network zone based on the values selected in the form when the service was requested. We’ll be using two networks, Internal and External as our examples, but you can use however many network zones, named suitably for your organization’s purposes.


Important: The solution described here assigns a single network zone to all components in a service, and as such is not suitable for use with services that include multiple components which must be placed on separate network zones.


Creating a Network Custom Attribute


The procedure below demonstrates how to create a list-based custom attribute so users can choose their network from a predefined list when submitting a request. Using a list is preferable whenever you have known values because it prevents spelling errors from interrupting the automation that follows.

  1. Under the Configuration menu, choose Custom Attributes.
  2. Click Add.
  3. Name the attribute Network and add a meaningful Description if you prefer.
  4. Choose Applies To: Virtual Machines and Virtual Apps.
  5. Choose List as the Type.
  6. Check Edit in Service Portal.
  7. Click Next.
  8. Enter Internal in the text field, and click Add. Repeat with External. Highlight one and use the Move Up and Move Down buttons to sort the list by the order you want them to appear.

  9. Click Finish.

Configuring the Approval Workflow


Follow the procedure below to configure an approval workflow step that uses an embedded script to choose the network to which the VM or vApp will be deployed. 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 Workflows tab.
  3. Create a new approval workflow for new requests, or edit and existing workflow for new requests.
  4. On the Steps page, click Add and choose Execute Script.
  5. Provide a meaningful name, such as Determine Network.


  6. Choose appropriate settings for Step Execution. You can always run the script to set the network, or check a condition, for example the name of the source template, and execute the step only when the condition has been satisfied.
  7. Leave the 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 (download a copy here):

        

    powershell -command "& { 
    # Get the network from the component form
    $network1 = '#{request.services[1].components[1].settings.customAttribute['Network']}';
     
    # write out the correct network label based on the form choice
    if ($network1 -eq 'internal') {write-host '$NETWORK1=Internal Network'
    }  elseif ($network1 -eq 'external') { write-host '$NETWORK1=External Network'
    }   else { write-host Unknown value $network1; exit 1 } }" 

        

  11. Complete the rest of the wizard as appropriate for your needs.


See Also