예제 #1
0
 def cmd_raw(self, key, ip, cmd, user):
     if key:
         ip = user + '@' + ip
         ssh = 'LC_ALL=C && ssh -o ConnectTimeout=20 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ' + key + ' -t -t ' + ip + ' \'%s\'' % cmd
         logging.warning(ssh)
         out, _, _ = robust_com(ssh)
         return out
     else:
         return ''
예제 #2
0
파일: local.py 프로젝트: TENorbert/ferry
 def cmd_raw(self, key, ip, cmd, user):
     if key:
         ip = user + '@' + ip
         ssh = 'LC_ALL=C && ssh -o ConnectTimeout=20 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ' + key + ' -t -t ' + ip + ' \'%s\'' % cmd
         logging.warning(ssh)
         out, _, _ = robust_com(ssh)
         return out
     else:
         return ''
예제 #3
0
    def _execute_cmd(self, cmd, server=None, user=None, read_output=True):
        """
        Execute the command on the server via ssh. 
        """

        if not server:
            # The server is not supplied, so just execute
            # the command locally. 
            proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
            if read_output:
                out = proc.stdout.read()
                err = proc.stderr.read()
        else:
            # Do not store results in hosts file or warn about 
            # changing ssh keys. Also use the key given to us by the fabric. 
            flags = " -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "
            flags += " -i " + self.key

            # If the user is given explicitly use that. Otherwise use the
            # default user (which is probably root). 
            if user:
                ip = user + '@' + server
            else:
                ip = self.docker_user + '@' + server
            flags += " -t -t " + ip

            # Wrap the command around an ssh command. 
            ssh = 'ssh ' + flags + ' \'%s\'' % cmd
            logging.warning(ssh)

            # All the possible errors that might happen when
            # we try to connect via ssh. 
            if read_output:
                out, err, success = robust_com(ssh)
            else:
                # The user does not want us to read the output.
                # That means we can't really check for errors :(
                proc = Popen(ssh, stdout=PIPE, stderr=PIPE, shell=True)

        if read_output:
            # Read both the standard out and error. 
            return out, err
        else:
            # The user does not want to read the output.
            return proc
예제 #4
0
 def copy_raw(self, key, ip, from_dir, to_dir, user):
     if key:
         opts = '-o ConnectTimeout=20 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
         scp = 'scp ' + opts + ' -i ' + key + ' -r ' + from_dir + ' ' + user + '@' + ip + ':' + to_dir
         logging.warning(scp)
         robust_com(scp)
예제 #5
0
파일: cloud.py 프로젝트: TENorbert/ferry
 def copy_raw(self, key, ip, from_dir, to_dir, user):
     opts = '-o ConnectTimeout=20 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
     scp = 'scp ' + opts + ' -i ' + key + ' -r ' + from_dir + ' ' + user + '@' + ip + ':' + to_dir
     logging.warning(scp)
     robust_com(scp)