Пример #1
0
def test_ssh(ssh_config):
    result = True
    client = SSHClient(ssh_config)
    try:
        client.ping()
    except Exception as e:
        result = False
        return result, e
    return result, None
Пример #2
0
def is_host_connected(ip, port, credential):
    config = SshConfig(host=ip,
                       username=credential.username,
                       password=credential.password,
                       private_key=credential.private_key,
                       port=port)
    client = SSHClient(config)
    return client.ping()
Пример #3
0
 def gather_auth_token(self):
     cmd = "kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep tiller | awk '{print $1}') | grep token: | awk '{print $2}'"
     master = self.cluster.group_set.get(name='master').hosts.first()
     ssh_config = parse_host_to_ssh_config(master)
     ssh_client = SSHClient(ssh_config)
     connected = ssh_client.ping()
     if not connected:
         raise Exception("ssh connect error!")
     else:
         out, code = ssh_client.run_cmd(cmd)
     if code == 0:
         self.cache_auth_token(out)
         return out
     else:
         raise Exception('exec cmd error:' + out)