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
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()
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)