Beispiel #1
0
def VMwarePowerOffAction(endpoints=[VMwarePoweredOnVM]):
    Task.VMRestart(name="RestartTask", target=endpoints[0])
    Task.VMPowerOff(name="PowerOffTask", target=endpoints[0])
    Task.Exec.ssh(
        name="ShellTask",
        script='''echo "Shell Task is Successful"''',
        target=endpoints[0],
    )
Beispiel #2
0
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")))
Beispiel #3
0
def DslWhileLoopRunbook():
    "Runbook example with while loop"

    with Task.Loop(
            iterations=2,
            name="WhileTask",
            exit_condition=Status.SUCCESS,
            loop_variable="loop_var",
    ):
        Task.Exec.escript(name="Task1",
                          script="print 'Inside loop1 @@{loop_var}@@'")

    with Task.Loop(iterations=2, name="WhileTask2"):
        Task.Exec.escript(name="Task2",
                          script="print 'Inside loop2 @@{iteration}@@'")
Beispiel #4
0
def WhileTaskLoopVariable(endpoints=[http_endpoint]):
    "Runbook Service example"
    with Task.Loop(10, name="Task1", loop_variable="iteration"):
        Task.SetVariable.escript(
            name="SetVariableTask",
            script='''print "iteration=random"''',
            variables=["iteration"],
        )
        with Task.Loop(10, name="Task2", loop_variable="iteration"):
            Task.HTTP.post(
                relative_url="/list",
                body=json.dumps({}),
                headers={"Content-Type": "application/json"},
                content_type="application/json",
                response_paths={"iteration": "$"},
                status_mapping={200: True},
                target=endpoints[0],
            )
Beispiel #5
0
def DslWhileDecisionRunbookForMPI():
    "Runbook Service example"
    var = Variable.Simple("3")  # noqa
    with Task.Loop("@@{var}@@", name="WhileTask", loop_variable="iteration"):
        Task.Exec.escript(name="Exec", script='''print "test"''')

    with Task.Decision.escript(script="exit(0)") as d:

        if d.ok:
            Task.Exec.escript(name="SUCCESS", script="print 'SUCCESS'")

        else:
            Task.Exec.escript(name="FAILURE", script="print 'FAILURE'")
Beispiel #6
0
def DslInputRunbook():
    "Runbook Service example"
    Task.Input(
        name="Input_Task",
        inputs=[
            Variable.TaskInput("user_name"),
            Variable.TaskInput("password", input_type="password"),
            Variable.TaskInput("date", input_type="date"),
            Variable.TaskInput("time", input_type="time"),
            Variable.TaskInput("user",
                               input_type="select",
                               options=["user1", "user2", "user3"]),
        ],
    )
    Task.Exec.escript(name="Exec_Task", script=code)
Beispiel #7
0
def WhileTask(endpoints=[linux_endpoint, windows_endpoint, http_endpoint]):
    "Runbook Service example"
    with Task.Loop(10, exit_condition=Status.SUCCESS):
        with Task.Decision.ssh(name="Task1", script="exit 0", target=endpoints[0]) as d:

            if d.ok:
                Task.Exec.ssh(
                    name="SUCCESS1", script="echo 'SUCCESS'", target=endpoints[0]
                )

            else:
                Task.Exec.ssh(
                    name="FAILURE1", script="echo 'FAILURE'", target=endpoints[0]
                )

        with Task.Decision.ssh(name="Task2", script="exit 1", target=endpoints[0]) as d:

            if d.ok:
                Task.Exec.ssh(
                    name="SUCCESS2", script="echo 'SUCCESS'", target=endpoints[0]
                )

            else:
                Task.Exec.ssh(
                    name="FAILURE2", script="echo 'FAILURE'", target=endpoints[0]
                )

        Task.Delay(15, name="Task3")
        Task.Delay(15, name="Task4")
        Task.HTTP.post(
            name="Task5",
            relative_url="/list",
            body=json.dumps({}),
            headers={"Content-Type": "application/json"},
            content_type="application/json",
            status_mapping={200: True},
            target=endpoints[2],
        )
        Task.HTTP.post(
            name="Task6",
            relative_url="/list",
            body=json.dumps({}),
            headers={"Content-Type": "application/json"},
            content_type="application/json",
            status_mapping={200: True},
            target=endpoints[2],
        )
        with Task.Loop(
            10, name="Task7", loop_variable="iteration1", exit_condition=Status.SUCCESS
        ):
            Task.Exec.escript(script="print 'test'")
        with Task.Loop(
            10, name="Task8", loop_variable="iteration2", exit_condition=Status.SUCCESS
        ):
            Task.Exec.escript(script="print 'test'")
        Task.Exec.escript(script="print 'test'", name="Task9")
        Task.Exec.escript(script="print 'test'", name="Task10")
        Task.Exec.ssh(script="echo 'test'", name="Task11", target=endpoints[0])
        Task.Exec.ssh(script="echo 'test'", name="Task12", target=endpoints[0])
        Task.Exec.powershell(script="echo 'test'", name="Task13", target=endpoints[1])
        Task.Exec.powershell(script="echo 'test'", name="Task14", target=endpoints[1])
Beispiel #8
0
def WhileTaskMacro():
    "Runbook Service example"
    var = Variable.Simple("3")  # noqa
    with Task.Loop("@@{var}@@", name="WhileTask", loop_variable="iteration"):
        Task.Exec.escript(name="Exec", script='''print "test"''')
Beispiel #9
0
def DslConfirmRunbook():
    "Runbook Service example"
    Task.Confirm(name="Confirm_Task")
    Task.Exec.escript(name="Exec_Task", script=code)
Beispiel #10
0
def Hello(endpoints=[PCEndpoint, IPEndpoint]):
    """ Sample runbook for Hello """

    # Defining variables for entity counts
    endpoints_count  = Variable.Simple.int("0", runtime=True)  # noqa
    blueprints_count = Variable.Simple.int("0", runtime=True)  # noqa
    runbooks_count   = Variable.Simple.int("0", runtime=True)  # noqa
    apps_count       = Variable.Simple.int("0", runtime=True)  # noqa

    # HTTP Tasks to get CALM Entity Counts
    # default target is set as endpoints[0] = PCEndpoint, therefore target not required for http tasks
    Task.HTTP.post(
        name="EndpointCount",
        relative_url="/endpoints/list",
        body=json.dumps({}),
        headers={"Authorization": "Bearer @@{calm_jwt}@@"},
        content_type="application/json",
        response_paths={"endpoints_count": "$.metadata.total_matches"},
        status_mapping={200: True},
    )
    Task.HTTP.post(
        name="BlueprintCount",
        relative_url="/blueprints/list",
        body=json.dumps({}),
        headers={"Authorization": "Bearer @@{calm_jwt}@@"},
        content_type="application/json",
        response_paths={"blueprints_count": "$.metadata.total_matches"},
        status_mapping={200: True},
    )
    Task.HTTP.post(
        name="RunbookCount",
        relative_url="/runbooks/list",
        body=json.dumps({}),
        headers={"Authorization": "Bearer @@{calm_jwt}@@"},
        content_type="application/json",
        response_paths={"runbooks_count": "$.metadata.total_matches"},
        status_mapping={200: True},
    )
    Task.HTTP.post(
        name="AppCount",
        relative_url="/apps/list",
        body=json.dumps({}),
        headers={"Authorization": "Bearer @@{calm_jwt}@@"},
        content_type="application/json",
        response_paths={"apps_count": "$.metadata.total_matches"},
        status_mapping={200: True},
    )

    # running tasks in parallel
    with parallel() as p:

        with branch(p):

            # Exec Task to print all entity stats
            Task.Exec.escript(name="EntityStats", filename="scripts/entity_stats.py2", target=endpoints[1])

        with branch(p):

            # loop task example
            with Task.Loop(iterations=2, name="LoopTask", loop_variable="loop_var"):

                # decision task example
                with Task.Decision.escript(name="DecisionTask", script="print 'ExitCode-@@{loop_var}@@';exit(@@{loop_var}@@)") as d:
                    if d.ok:
                        Task.Exec.escript(name="TruePath", script="print 'True path is executed'")
                    else:
                        Task.Exec.escript(name="FalsePath", script="print 'False path is executed'")
Beispiel #11
0
def VMwarePowerOnAction(endpoints=[VMwarePoweredOffVM]):
    Task.VMPowerOn(name="PowerOnTask", target=endpoints[0])