Total Complexity | 7 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | #!/usr/bin/env python3 |
||
|
|||
2 | # -*- coding: utf-8 -*- |
||
3 | |||
4 | import sys |
||
5 | from db_sync_tool.utility import mode, output |
||
6 | from db_sync_tool.remote import client as remote_client |
||
7 | |||
8 | |||
9 | def run_ssh_command_by_client(client, command): |
||
10 | """ |
||
11 | Running origin ssh command |
||
12 | :param client: String |
||
13 | :param command: String |
||
14 | :return: |
||
15 | """ |
||
16 | if client == mode.Client.ORIGIN: |
||
17 | return run_ssh_command(command, remote_client.ssh_client_origin) |
||
18 | elif client == mode.Client.TARGET: |
||
19 | return run_ssh_command(command, remote_client.ssh_client_target) |
||
20 | |||
21 | |||
22 | def run_ssh_command(command, ssh_client=remote_client.ssh_client_origin): |
||
23 | """ |
||
24 | Running ssh command |
||
25 | :param command: String |
||
26 | :param ssh_client: |
||
27 | :return: |
||
28 | """ |
||
29 | stdin, stdout, stderr = ssh_client.exec_command(command) |
||
30 | exit_status = stdout.channel.recv_exit_status() |
||
31 | |||
32 | err = stderr.read().decode() |
||
33 | |||
34 | if err and 0 != exit_status: |
||
35 | sys.exit(output.message(output.Subject.ERROR, err, False)) |
||
36 | elif err: |
||
37 | output.message(output.Subject.WARNING, err, True) |
||
38 | |||
39 | return stdout |
||