def DslVMOperationsRunbook(): "Runbook Service example" Task.VMPowerOff(name="VM Power Off Task", target=ref(Endpoint.use_existing("VMEndpoint"))) Task.VMPowerOn(name="VM Power On Task", target=ref(Endpoint.use_existing("VMEndpoint"))) Task.VMRestart(name="VM Restart Task", target=ref(Endpoint.use_existing("VMEndpoint")))
def DslDecisionRunbook(): """ Runbook example with decision task Decision tasks can be defined in 2 ways 1. with Task.Decision() as d: if d.ok: true_path else: false_path 2. with Task.Decision() as d: if d.exit_code == 0: true_path if d.exit_code == 1: false_path """ with Task.Decision.ssh( name="DecisionTask", script="cat hell", target=ref(Endpoint.use_existing("DslEndpoint")), ) as d: if d.ok: Task.Exec.escript( name="Task1", script="print 'Decision Task is Successful'" ) else: Task.Exec.escript(name="Task2", script="print 'Decision Task Failed'")
def DslExistingEndpoint(): """ Runbook example for using existing endpoint Existing endpoint as target can be given as 'Endpoint.use_existing(<ep-name>)' Existing endpoints are not allowed in endpoints argument in runbook creation """ Task.Exec.ssh( name="Task1", script='echo "hello"', target=ref(Endpoint.use_existing("DslEndpoint")), )
def DslSetVariableRunbook(): "Runbook example with Set Variable Tasks" Task.SetVariable.escript(name="Task1", filename=os.path.join( "scripts", "set_variable_task1_script.py"), variables=["var1"]) Task.SetVariable.ssh(name="Task2", filename=os.path.join("scripts", "set_variable_task2_script.sh"), variables=["var2"], target=ref(Endpoint.use_existing("linux_bedag"))) Task.Exec.escript(name="Task3", script="print '@@{var1}@@ @@{var2}@@'")