Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

How run_script.py copy and exec script #15

Open
weburnit opened this issue Nov 11, 2018 · 3 comments
Open

How run_script.py copy and exec script #15

weburnit opened this issue Nov 11, 2018 · 3 comments

Comments

@weburnit
Copy link

Fix me if I'm wrong
I don't know how you guys can copy and run the script within this function in attacks.run_script.RunScript#_run_script

    def _run_script(self, host, user, local_script, remote_script, pem):
        """
        Copy a script to a remote host and exec it.
        """
        self.log.info("running %s in node %s", local_script, host)

        pem_decoded = base64.b64decode(pem).decode()

        temp = tempfile.NamedTemporaryFile('w', delete=False)
        temp.write(pem_decoded)
        temp.flush()
        temp.close()

        self.log.info("connect ssh client to %s with user %s", host, user)
        self.log.info("Executing remote script")
@gdiazlo
Copy link
Contributor

gdiazlo commented Nov 12, 2018

You're right. The old SSH code was removed due to license incompatibilities. If you look at the prior commit, you can see the correct code which was based on paramiko library. This needs to be fixed.

@weburnit
Copy link
Author

According to this example
This is my approach.

    def _run_script(self, host, local_script, public_key):
        """
        Copy a script to a remote host and exec it.
        """
        self.log.info("running %s in node %s", local_script, host)

        with open(local_script) as fp:
            local_script = fp.read()
        step1 = SSHKeyDeployment(public_key)
        step2 = ScriptDeployment(local_script)

        deployment = MultiStepDeployment([step1, step2])
        conn = self.driver
        images = conn.list_images()
        sizes = conn.list_sizes()

        # deploy_node takes the same base keyword arguments as create_node.
        conn.deploy_node(name='deploy_local_script', image=images[0], size=sizes[0],
                         deploy=deployment)

If you think it makes sense, I would like to make PR @gdiazlo

@gdiazlo
Copy link
Contributor

gdiazlo commented Nov 12, 2018

Cool. Please make a PR so we can test it too!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants