Beispiel #1
0
 def execute(self, cmd, **kwargs):
     if 'log_true' in kwargs:
         if kwargs['log_true']:
             LOG.info('Node: %s Executing: %s' % (self.node.name, cmd))
         kwargs.pop('log_true')
     NodeManager.gen_ssh_config(self.node)
     if not isinstance(cmd, str):
         cmd = ' '.join(cmd)
     cmd_addition = ['ssh', '-i', SshUtil.get_id_rsa(), '-F',
                     SshUtil.get_config_file_path(),
                     self.node.name]
     if self.node.password:
         cmd_addition = ['sshpass', '-p', self.node.password] + cmd_addition
     if 'as_root' in kwargs:
         kwargs.pop('as_root')
         cmd = 'sudo ' + cmd
     cmd_addition.append(cmd)
     return execute(cmd_addition, **kwargs)
Beispiel #2
0
 def _copy(self, direction, local_path, remote_path, **kwargs):
     # TODO create dir is not existing
     NodeManager.gen_ssh_config(self.node)
     cmd = ['scp', '-i', SshUtil.get_id_rsa(), '-F',
            SshUtil.get_config_file_path()]
     if direction == 'to':
         if os.path.isdir(local_path):
             cmd.append('-r')
         cmd = cmd + [local_path,
                      ('%s:%s') % (self.node.name, remote_path)]
     if direction == 'from':
         if self.node.is_dir(remote_path):
             cmd.append('-r')
         cmd = cmd + [('%s:%s') % (self.node.name, remote_path),
                      local_path]
     if self.node.password:
         cmd = ['sshpass', '-p', self.node.password] + cmd
     return execute(cmd, **kwargs)
Beispiel #3
0
 def to_ssh_config(self):
     config = ["Host %s" % self.name,
               "    Hostname %s" %
               (self.address if self.address else self.name)]
     if self.jump:
         config.append("    ProxyCommand ssh -F %(config_path)s "
                       "-W %%h:%%p %(name)s"
                       % {'config_path': SshUtil.get_config_file_path(),
                          'name': self.jump.name})
     if self.user:
         config.append("    user %s" % self.user)
     if self.port:
         config.append("    port %s" % self.port)
     return '\n'.join(config)
Beispiel #4
0
 def gen_ssh_config(cls, node):
     if node not in cls.env_nodes:
         cls.env_nodes.append(node)
     SshUtil.gen_ssh_config(cls.env_nodes)