| 63 | |
| 64 | |
| 65 | def _execute_ssh_command(hostip, port, username, password, ssh_command, timeout=5): |
| 66 | #SSH to the machine |
| 67 | ssh = SshClient(hostip, port, username, password) |
| 68 | # Ensure the SSH login is successful |
| 69 | while True: |
| 70 | res = ssh.execute(ssh_command) |
| 71 | if len(res) == 0: |
| 72 | return res |
| 73 | elif "Connection refused".lower() in res[0].lower(): |
| 74 | pass |
| 75 | elif res[0] != "Host key verification failed.": |
| 76 | break |
| 77 | elif timeout == 0: |
| 78 | break |
| 79 | |
| 80 | time.sleep(5) |
| 81 | timeout = timeout - 1 |
| 82 | return res |
| 83 | |
| 84 | def restart_mgmt_server(server): |
| 85 | """Restarts the management server""" |