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