6.4 Manual Management of a VM Lifecycle

The example provided in this section is a general purpose job that only provisions a resource.

You might use a job like this, for example, each day at 5:00 p.m. when your accounting department requires extra SAP servers to be available. As a developer, you would create a job that provisions the required VMs, then use the PlateSpin Orchestrate Scheduler to schedule the job to run every day at the time specified.

In this example, the provision job retrieves the members of a resource group (which are VMs) and invokes the provision action on the VM objects. For an example of a provision job JDL, see Section 6.4.3, Provision Job JDL.

To setup to create the provision.job, use the following procedure:

  1. Create your VMs and follow the discovery process in the Development Client so that the VMs are contained in the PlateSpin Orchestrate inventory.

  2. In the Development Client, create a Resource Group called sap and add the required VMs as members of the group.

  3. Given the .jdl and .policy below you would create a .job file (jar them):

    >jar cvf provision.job provision.jdl provision.policy
    
  4. Deploy the provision.job file to the Orchestrate Server using either the Development Client or the zosadmin command line.

To run the job, use either of the following procedures:

6.4.1 Manually Using the zos Command Line

  1. At the command line, enter:

    >zos login <zos server>
    >zos run provision VmGroup="sap"
    

For more complete details about entering CLI commands, see The zos Command Line Tool in the PlateSpin Orchestrate 2.5 Command Line Reference.

6.4.2 Automatically Using the Development Client Job Scheduler

  1. In the Development Client, create a New schedule.

  2. Fill in the job name (provision), user, and priority.

  3. For the jobarg VmGroup, enter sap.

  4. Create a Trigger for the time you want this job to run.

  5. Save the Schedule and enable it by clicking Resume.

You can manually force scheduling by clicking Test Schedule Now.

For more complete details about using the Job Scheduler, see The PlateSpin Orchestrate Job Scheduler in the PlateSpin Orchestrate 2.5 Development Client Reference. You can also refer to Section 6.6, Automatically Provisioning a VM in this guide.

6.4.3 Provision Job JDL

"""Job that retrieves the members of a supplied resource group and invokes the provision action on all members. For more details about this class, see Job. See also ProvisionSpec.

The members must be VMs.

"""
class provision(Job):

    def job_started_event(self):

        # Retrieves the value of a job argument supplied in
        # the 'zos run' or scheduled run.
        VmGroup = self.getFact("jobargs.VmGroup")

        #
        # Retrieves the resource group grid object of the supplied name.
        # The job Fails if the group name does not exist.
        #
        group = getMatrix().getGroup(TYPE_RESOURCE,VmGroup)
        if group == None:
            self.fail("No such group '%s'." % (VmGroup))

        #
        # Gets a list of group members and invokes a provision action on each one.
        #
        members = group.getMembers()
        for vm in members:
           vm.provision()
           print "Provision action requested for VM '%s'" % (vm.getFact("resource.id"))


Job Policy:
<!--
    The policy definition for the provision example job.
    
    This specifies the job argument VmGroup' which is required
-->
<policy>

    <jobargs>

        <fact name="VmGroup"
              type="String"
              description="Name of a VM resource group whose members will be provisioned"
              />

    </jobargs>

</policy>