Exemple #1
0
 def sample_action():
     with parallel():
         CalmTask.Exec.ssh(
             name="Task1", script="echo 'Sample parallel Task 1'\ndate"
         )
         CalmTask.Exec.ssh(
             name="Task2", script="echo 'Sample parallel Task 2'\ndate"
         )
Exemple #2
0
    def custom_action_2():

        # Step 1
        Task.Exec.ssh(name="Task21", script="date")

        # Step 2
        with parallel():  # All tasks within this context will be run in parallel
            Task.Exec.ssh(name="Task22a", script="date")
            Task.Exec.ssh(name="Task22b", script="date")

        # Step 3
        Task.Exec.ssh(name="Task23", script="date")
Exemple #3
0
    def Upgrade():
        KUBE_VERSION_NEW = CalmVariable.Simple.string(  # noqa
            "v1.13.6",
            label="Kubernetes cluster version",
            regex=r"^v1\.[0-9]?[0-9]\.[0-9]?[0-9]$",
            validate_regex=True,
            is_mandatory=True,
            runtime=True,
        )

        with parallel():
            CalmTask.SetVariable.escript(
                name="Set Version Master",
                script="print 'VERSION=@@{KUBE_VERSION_NEW}@@'",
                variables=["VERSION"],
                target=ref(Master),
            )
            CalmTask.SetVariable.escript(
                name="Set Version Slave",
                script="print 'VERSION=@@{KUBE_VERSION_NEW}@@'",
                variables=["VERSION"],
                target=ref(Worker),
            )
        with parallel():
            CalmTask.Exec.ssh(
                name="Upgrade Master",
                filename="scripts/Master11.sh",
                target=ref(Master),
            )
            CalmTask.Exec.ssh(
                name="Upgrade Minion",
                filename="scripts/Worker04.sh",
                target=ref(Worker),
            )
        CalmTask.Exec.ssh(name="RestartServices",
                          filename="scripts/Master12.sh",
                          target=ref(Master))
Exemple #4
0
 def test_profile_action():
     var1 = CalmVariable.Simple(  # noqa
         "var1_val",
         label="var1_label",
         regex="^[a-zA-Z0-9_]+$",
         validate_regex=True,
         runtime=True,
     )
     var2 = CalmVariable.Simple.Secret(  # noqa
         "var2_val",
         label="var2_label",
         regex="^[a-zA-Z0-9_]+$",
         validate_regex=True,
         is_hidden=True,
         is_mandatory=True,
     )
     CalmTask.Exec.ssh(name="Task5",
                       filename="scripts/sample_script.sh",
                       target=ref(MySQLService))
     PHPService.test_action(name="Task6")
     CalmTask.HTTP.get(
         "https://jsonplaceholder.typicode.com/posts/1",
         credential=DefaultCred,
         headers={"Content-Type": "application/json"},
         secret_headers={"secret_header": "secret"},
         content_type="application/json",
         verify=True,
         status_mapping={200: True},
         response_paths={"foo_title": "$.title"},
         name="Test HTTP Task Get",
         target=ref(MySQLService),
     )
     CalmTask.HTTP.post(
         "https://jsonplaceholder.typicode.com/posts",
         body=json.dumps({
             "id": 1,
             "title": "foo",
             "body": "bar",
             "userId": 1
         }),
         headers={"Content-Type": "application/json"},
         cred=ref(DefaultCred),
         content_type="application/json",
         verify=True,
         status_mapping={200: True},
         response_paths={"foo_title": "$.title"},
         name="Test HTTP Task Post",
         target=ref(MySQLService),
     )
     CalmTask.HTTP.put(
         "https://jsonplaceholder.typicode.com/posts/1",
         body=json.dumps({
             "id": 1,
             "title": "foo",
             "body": "bar",
             "userId": 1
         }),
         headers={"Content-Type": "application/json"},
         content_type="application/json",
         verify=True,
         status_mapping={200: True},
         response_paths={"foo_title": "$.title"},
         name="Test HTTP Task Put",
         target=ref(MySQLService),
     )
     CalmTask.HTTP.delete(
         "https://jsonplaceholder.typicode.com/posts/1",
         headers={"Content-Type": "application/json"},
         content_type="application/json",
         verify=True,
         status_mapping={200: True},
         name="Test HTTP Task Delete",
         target=ref(MySQLService),
     )
     CalmTask.HTTP(
         "PUT",
         "https://jsonplaceholder.typicode.com/posts/1",
         body=json.dumps({
             "id": 1,
             "title": "foo",
             "body": "bar",
             "userId": 1
         }),
         headers={"Content-Type": "application/json"},
         content_type="application/json",
         verify=True,
         status_mapping={200: True},
         response_paths={"foo_title": "$.title"},
         name="Test HTTP Task",
         target=ref(MySQLService),
     )
     with parallel():
         CalmTask.Exec.escript("print 'Hello World!'",
                               name="Test Escript",
                               target=ref(MySQLService))
         CalmTask.SetVariable.escript(
             script="print 'var1=test'",
             name="Test Setvar Escript",
             variables=["var1"],
             target=ref(MySQLService),
         )
         CalmTask.SetVariable.ssh(
             filename="scripts/sample_script.sh",
             name="Test Setvar SSH",
             variables=["var2"],
             target=ref(MySQLService),
         )
     CalmTask.Scaling.scale_out(1,
                                target=ref(LampDeployment),
                                name="Scale out Lamp")
     CalmTask.Delay(delay_seconds=60,
                    target=ref(MySQLService),
                    name="Delay")
     CalmTask.Scaling.scale_in(1,
                               target=LampDeployment,
                               name="Scale in Lamp")
 def custom_action_2():
     with parallel(
     ):  # All tasks within this context will be run in parallel
         Task.Exec.ssh(name="Task41", script="date")
         Task.Exec.ssh(name="Task51", script="date")
    def UpdateApp():
        """This action updates the app with the most recent code from git"""

        label = CalmVariable.Simple("latest", is_mandatory=True, runtime=True)

        with parallel():
            CalmTask.Exec.ssh(
                name="1RemoveWS1",
                filename="scripts/haproxy/updateapp/RemoveWS1.sh",
                target=ref(HaProxy),
            )
            CalmTask.Exec.escript(
                name="1UpdateContainers",
                filename="scripts/webserver/updateapp/UpdateContainers.py",
                target=ref(WebServerK8s),
            )

        CalmTask.Exec.ssh(
            name="2StopWebServer",
            filename="scripts/webserver/stop/StopWebServer.sh",
            target=ref(WebServer1),
        )
        CalmTask.Exec.ssh(
            name="3UpdateFromGit",
            filename="scripts/webserver/updateapp/UpdateFromGit.sh",
            target=ref(WebServer1),
        )
        CalmTask.Exec.ssh(
            name="4ConfigureSite",
            filename="scripts/webserver/create/ConfigureSite.sh",
            target=ref(WebServer1),
        )
        CalmTask.Exec.ssh(
            name="5StartWebServer",
            filename="scripts/webserver/start/StartWebServer.sh",
            target=ref(WebServer1),
        )
        CalmTask.Exec.ssh(
            name="6AddWS1",
            filename="scripts/haproxy/updateapp/AddWS1.sh",
            target=ref(HaProxy),
        )
        CalmTask.Exec.ssh(
            name="7Delay",
            filename="scripts/haproxy/updateapp/Delay.sh",
            target=ref(HaProxy),
        )
        CalmTask.Exec.ssh(
            name="8RemoveWS2",
            filename="scripts/haproxy/updateapp/RemoveWS2.sh",
            target=ref(HaProxy),
        )
        CalmTask.Exec.ssh(
            name="9StopWebServer",
            filename="scripts/webserver/stop/StopWebServer.sh",
            target=ref(WebServer2),
        )
        CalmTask.Exec.ssh(
            name="10UpdateFromGit",
            filename="scripts/webserver/updateapp/UpdateFromGit.sh",
            target=ref(WebServer2),
        )
        CalmTask.Exec.ssh(
            name="11ConfigureSite",
            filename="scripts/webserver/create/ConfigureSite.sh",
            target=ref(WebServer2),
        )
        CalmTask.Exec.ssh(
            name="12StartWebServer",
            filename="scripts/webserver/start/StartWebServer.sh",
            target=ref(WebServer2),
        )
        CalmTask.Exec.ssh(
            name="13AddWS2",
            filename="scripts/haproxy/updateapp/AddWS2.sh",
            target=ref(HaProxy),
        )