A.2 Using an Orchestration Job to Install the Orchestration Agent on a VM Host

The following jobe code sample shows how you can use a job to install the Orchestration Agent on a VM host.

"""
Search for a VM Grid objects using Constraints and run a VM operation on them.
"""
class test(Job):
   
   def job_started_event(self):
      
      # collect all VM Instances whose resource ID
      # starts with the string "apache"
      
      a = AndConstraint()
      
      e1 = EqConstraint()
      e1.setFact("resource.type")
      e1.setValue("VM")
      a.add(e1)
      
      e2 = EqConstraint()
      e2.setValue("apache*")
      e2.setMatchMode(EqConstraint.MATCH_MODE_REGEXP)
      e2.setFact("resource.id")
      a.add(e2)
      
      vms = getMatrix().getGridObjects(TYPE_RESOURCE,a,None)
      for vm in vms:
         vm.installAgent()