Defines the base class for creating custom computed facts. Computed facts provide the ability to create custom calculations that extend the built-in factsets for a grid object. The computed fact can be in constraints. User defined computed facts are required to subclass this class. In order to use ComputedFact, you must deploy a subclass of ComputedFact and then create a linked fact referencing the deployed ComputedFact. The linked fact is then used in constraints. See the Example below.
Retrieves the context object for this computed fact instance.
The context object allows read-only access to the grid objects in the evaluation context. For example, when a computed fact is evaluated in the context of a Start constraint, the context object provides access to the job instance's factset.
Returns: ComputedFactContext for this computed fact evaluation or None if there is no context.
VmSpec here is used for creating a clone on a named host from a template resource:
class ActiveFooJobs(ComputedFact): def compute(self): count = 0 ctx = self.getContext() if ctx == None: print "No context" else: jobInstance = ctx.getJobInstance() if jobInstance == None: print "No job instance in context" else: activejobs = getMatrix().getActiveJobs() for j in activejobs: state = j.getFact("jobinstance.state.string") if j.getFact("job.id") == "foo" and \ j.getFact("user.id") == ctx.getFact("user.id") and \ (state == "Running" or state == "Starting"): count+=1 return count
Javadoc: ComputedFact