Esempio n. 1
0
    def _dispatch(self, instance_data, item):
        """
        Handle an item in the commands array, examples:

        "echo foo"                           # SSH (shorthand)
        { type: "ssh", command: "echo foo"}  # also SSH
        { type: "copy", from: x, to: y }     # scp

        """

        what = item.get('type', None)

        if what == 'ssh':
            # wait for SSH and then launch a command
            self._wait_for_ready(instance_data)
            return invoke(self._build_ssh_cmd(
                instance_data, item.get('command', None)
            ))

        elif what == 'copy':
            # wait for SSH and then launch an scp
            copy_from = item['copy_from']
            copy_to = item['copy_to']
            self._wait_for_ready(instance_data)
            invoke(self._build_ssh_cmd(instance_data, "mkdir -p %s" % copy_to))
            return invoke(self._build_copy_cmd(
                instance_data,
                copy_from = copy_from,
                copy_to = copy_to
            ))

        # add any other operational types here (such as local command execution)

        else:
            raise Exception("unknown type in commands list: %s, %s" % (item, what))
Esempio n. 2
0
    def converge(self, instance_data):
        """ rsync if needed, then run the shell commands """

        self.wait_for_ready(instance_data)
        if self.copy_from:
            invoke(self._build_rsync_cmd(instance_data))
        for pc in self.commands:
            invoke(self._build_ssh_cmd(instance_data, " %s" % pc))
Esempio n. 3
0
    def converge(self, instance_data):
        """ rsync if needed, then run the shell commands """

        self.wait_for_ready(instance_data)
        if self.copy_from:
            invoke(self._build_rsync_cmd(instance_data))
        for pc in self.commands:
            invoke(self._build_ssh_cmd(instance_data, " %s" % pc))
Esempio n. 4
0
    def ssh(self, instance_data):
        """ open a shell into a box """

        # if writing a new provisioner, it may be helpful to subclass this
        # class rather than reimplementing this method.  Then just override
        # converge

        self._wait_for_ready(instance_data)
        return invoke(self._build_ssh_cmd(instance_data, ""))
Esempio n. 5
0
    def ssh(self, instance_data):
        """ open a shell into a box """

        # if writing a new provisioner, it may be helpful to subclass this
        # class rather than reimplementing this method.  Then just override
        # converge

        self._wait_for_ready(instance_data)
        return invoke(self._build_ssh_cmd(instance_data,""))
Esempio n. 6
0
    def _dispatch(self, instance_data, item):
        """
        Handle an item in the commands array, examples:

        "echo foo"                           # SSH (shorthand)
        { type: "ssh", command: "echo foo"}  # also SSH
        { type: "copy", from: x, to: y }     # scp

        """

        what = item.get('type', None)

        if what == 'ssh':
            # wait for SSH and then launch a command
            self._wait_for_ready(instance_data)
            return invoke(self._build_ssh_cmd(
                instance_data, item.get('command', None)
            ))

        elif what == 'copy' or what == 'rsync':
            # wait for SSH and then launch an scp
            copy_from = item['copy_from']
            copy_to = item['copy_to']
            self._wait_for_ready(instance_data)
	
            if what == 'rsync':
            	return invoke(self._build_rsync_cmd(
                	instance_data,
                	copy_from = copy_from,
                	copy_to = copy_to
            	))
            elif what == 'copy':
		invoke(self._build_ssh_cmd(instance_data, "mkdir -p %s" % copy_to))
            	return invoke(self._build_copy_cmd(
                	instance_data,
                	copy_from = copy_from,
                	copy_to = copy_to
            	))
        elif what == 'command':
            command = item['command']
            # wait for SSH and then launch an scp
            self._wait_for_ready(instance_data)
            return invoke(self._build_local_cmd(
                instance_data,
                command = command
            ))

        # add any other operational types here (such as local command execution)

        else:
            raise Exception("unknown type in commands list: %s, %s" % (item, what))
Esempio n. 7
0
    def _wait_for_ready(self, instance_data):
        """ wait for SSH availability """

        if self.waited:
            return True

        (host, port) = (instance_data.ssh.host, instance_data.ssh.port)
        self.log("checking for SSH availability on %s:%s" % (host, port))
        while True:

            cmd = self._build_ssh_cmd(instance_data,
                                      "echo %s" % SSH_CANARY,
                                      connect_timeout=SSH_CONNECT_TIMEOUT)
            output = invoke(cmd, check_output=True).strip()

            if output.endswith(SSH_CANARY):
                self.waited = True
                return True

            self.log("retrying SSH availability in %s seconds..." % SSH_RETRY)
            time.sleep(SSH_RETRY)
Esempio n. 8
0
    def _wait_for_ready(self, instance_data):
        """ wait for SSH availability """

        if self.waited:
            return True

        (host, port) = (instance_data.ssh.host, instance_data.ssh.port)
        self.log("checking for SSH availability on %s:%s" % (host, port))
        while True:

            cmd = self._build_ssh_cmd(
                instance_data,
                "echo %s" % SSH_CANARY,
                connect_timeout=SSH_CONNECT_TIMEOUT)
            output = invoke(cmd, check_output=True).strip()

            if output.endswith(SSH_CANARY):
                self.waited = True
                return True

            self.log("retrying SSH availability in %s seconds..." % SSH_RETRY)
            time.sleep(SSH_RETRY)
Esempio n. 9
0
    def ssh(self, instance_data):
        """ open a shell into a box """

        self.wait_for_ready(instance_data, extra_sleep=0)
        return invoke(self._build_ssh_cmd(instance_data, ""))
Esempio n. 10
0
    def ssh(self, instance_data):
        """ open a shell into a box """

        self.wait_for_ready(instance_data, extra_sleep=0)
        return invoke(self._build_ssh_cmd(instance_data, ""))