9.2 Customizing Jobs for the Provisioning Adapter Hooks

This section includes the following information:

9.2.1 Adding Hooks Jobs to Customize a VM Event

If you want to augment what happens when a VM event occurs, you can do so by adding your custom hooks jobs to run in conjunction with the provisioning adapter. Pre- and Post-VM event jobs are executed synchronously, defined by default sequence, or by custom sequence. The actual VM event is allowed to run synchronously or asynchronously.

NOTE:In earlier versions of PlateSpin Orchestrate, paHooks jobs worked only with local repositories. These jobs now work with network attached storage (NAS) in PlateSpin Orchestrate 2.5.

PlateSpin Orchestrate includes two example jobs (paHooks_mount and paHooks_simple) intended as models that you can customize for use by the xen provisioning adapter. These example jobs illustrate some of the implemented xen provisioning adapter pre- and post-hooks. You can use these example jobs can help you to write similar jobs for performing tasks prior to and following a VM event executed by the provisioning adapter.

This section includes the following information:

How to Use the paHooks_simple Example to Help Trigger Pre- and Post-Hook Events

You can use paHooks_simple as an example to help you trigger pre- and post-hook events. The following are some requirements you must satisfy when customizing your own paHooks job.

  • Your job needs to have an associated .policy file. It is standard practice for the policy to have the same name as the job. This policy file must contain these jobargs:

      <jobargs>
        <fact name="mode"
              type="String"
              description="The event received by the provision adapter job." 
              value="" />
        <fact name="msg"
              type="String"
              description="The job memo describing this child job." 
              value="" />
        <fact name="useJoblets"
              type="Boolean"
              description="Schedule joblets or simulation only." 
              value="true" />
        <fact name="params"
              type="Dictionary"
              description="The parameters that were passed to the provision adapter job for the current event (mode)." />
      </jobargs>
    

    HINT:To avoid errors, we recommend that you make a copy of the paHooks_simple.policy file and and rename it to match the name of your job (or create a new policy and then copy the contents of the paHooks_simple.policy file to this file).

  • Make sure that the .jdl file for your job has the job_started_event defined. The job_started_event is responsible to parse the jobargs.mode argument sent at startup and in turn call the correct pre- or post-event. The paHooks_simple.jdl file does this in a generalized way:

        def job_started_event(self):
            msg = self.getFact("jobargs.msg")
            if msg:
                print msg
                self.setFact("jobinstance.memo", msg)
    
            mode = self.getFact('jobargs.mode')
            if not mode:
                self.fail('jobargs.mode not specified!')
    
            params = self.getFact('jobargs.params')
            params['mode'] = mode
            if self.factExists("job.debug") and self.getFact("job.debug"):
                print 'params=%s' % (params)
    
            func_name = '%s_event' % (mode)
            try:
                func= getattr(self, func_name)
                func.__call__(params)
            except AttributeError:
                print "Job mode '%s' not implemented" % (mode)
            except TypeError:
                print "Job mode '%s' has invalid signature" % (mode)
    
  • Customize the .jdl file for your job needs by including the pre_ and post_ events you want to call, for example:

        def pre_makeStandalone_event(self, params):
            print "******** pre_makeStandalone_event"
            self.__schedule_vmhost(params)
    

    This schedules the joblet for your paHooks job on the vmHost resource that has access to the files for the VM being affected. Your joblet code must then parse the jobletargs mode in order to determine what action to take:

        def joblet_started_event(self):
               mode = self.getFact("jobletargs.mode")
               if mode.startswith("pre_makeStandalone"):
                   """ do something useful here... """
    
  • Make sure that the The job.paHooksVmJob fact is set in the provisioning adapter job. The job.paHooksVmJob standard fact is available for implementation only in provision adapter jobs (xen, vsphere, and hyperv). For information about the location of this fact in the Development Client, see Provision Adapter Hook Jobs in Job Control Settings in the PlateSpin Orchestrate 2.5 Development Client Reference.

    The job.paHooksVmJob fact is a String array that needs to contain the names of the hooks job or jobs that you create and customize for use with the provisioning adapter. By default, the fact specifies that the listed jobs run sequentially as pre-event jobs. Then, after the provision adapter runs, these same hooks jobs execute in reverse sequence.

  • Make sure that the policy for the paHooks custom job is associated to the job.

Other Things to Know About Provisioning Adapter Hooks Jobs

  • Hyper-V hooks jobs you create can use a job structure similar to the example Xen jobs. For the vsphere provisioning adapter, however, we recommend that you confer with Novell Consulting for assistance in creating your own hooks jobs.

  • You can create hooks jobs that implement only one kind of event or many events. The jobs can be configured to be triggered by a single type of event, or that include all of the VM events. Customization options allow flexibility in the role of the job.

  • To increase the amount of detail available for hooks job implementation and monitoring, go to the hooks job and set the job.debug fact or the job.tracing fact to True.

9.2.2 Customizing Pre- and Post-Job Execution Order

If you do not want to use the default execution order for the Pre- and Post-event jobs, you can customize the order of their execution by adding custom facts:

  • job.paHooksPreVmJob: Use this fact to hard code the implementation order of the hooks jobs prior to a VM event. Make sure the fact is defined as a String array.

  • job.paHooksPostVmJob: Use this fact to hard code the implementation order of the hooks jobs following a VM event. Make sure the fact is defined as a String array.

IMPORTANT:Make sure you create these custom facts using the exact naming syntax shown above.

For example, if the default order for Pre-event VM jobs was Job 1, Job 2, Job 3 (specified using the job.paHooksVmJob fact), you could add the job.paHooksPostVmJob custom fact to specify the Post-event VM job execution order as Job 2, Job 1, Job 3.

9.2.3 Customizing Hooks Job Execution Based on Event Type

If you want to make sure that a provisioning adapter is invoked only when certain events occur, you have two options:

  • Manually add hooks jobs to the job.paHooksVmJob fact that contain only the event types you want (this is always an option).

  • Create a custom fact for the hooks jobs that works only for a specific event.

    The naming syntax for a custom fact like this follows the pattern of job.paHooks<Pre or Post><event_name>VmJob. For example, if you wanted to invoke a job to execute exclusively prior to a START event, you would add the custom fact job.paHooksPreStartVmJob, with the hooks job name or names specified in its String array.

    Each hooks job that you define is called only if it implements the event named, so you can set up a job for the provisioning adapter that implements only the desired event. For example, if you set up a Pre-Start VM hooks job for the Xen provisioning adapter, any other event except Start that occurs in that hooks job is never invoked.

paHooks requires a policy and for the job start event to call the specific methods according to jobargs.mode. For more information, see How to Use the paHooks_simple Example to Help Trigger Pre- and Post-Hook Events.