Skip to content

Commit 13b435c

Browse files
author
Isaac Hill
committed
File struct refactoring
1 parent 453bd1b commit 13b435c

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

hotfix_checker.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import sys
44
from util.channel_access import ChannelAccessUtils
5-
import paramiko
5+
from util.ssh_access import runSSHCommand
66
import requests
77

88
EPICS_DIR = "C:\\Instrument\\Apps\\EPICS\\"
@@ -54,36 +54,6 @@ def get_insts_on_latest_ibex_via_inst_congif():
5454
return insts_on_latest_ibex
5555

5656

57-
def runSSHCommand(host, username, password, command):
58-
""" Run a command on a remote host using SSH.
59-
60-
Args:
61-
host (str): The hostname to connect to.
62-
username (str): The username to use to connect.
63-
password (str): The password to use to connect.
64-
command (str): The command to run on the remote host.
65-
66-
Returns:
67-
dict: A dictionary with the success status and the output of the command.
68-
"""
69-
try:
70-
client = paramiko.SSHClient()
71-
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
72-
client.connect(host, port=SSH_PORT,
73-
username=username, password=password)
74-
stdin, stdout, stderr = client.exec_command(command)
75-
output = stdout.read().decode('utf-8')
76-
error = stderr.read().decode('utf-8')
77-
client.close()
78-
if error:
79-
return {'success': False, 'output': error}
80-
else:
81-
return {'success': True, 'output': output}
82-
except Exception as e:
83-
print(str(e))
84-
return {'success': False, 'output': str(e)}
85-
86-
8757
def check_for_uncommitted_changes(hostname):
8858
""" Check if there are any uncommitted changes on the instrument via SSH.
8959

util/ssh_access.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import paramiko
2+
3+
4+
class SSHAccessUtils(object):
5+
6+
@staticmethod
7+
def runSSHCommand(host, username, password, command):
8+
""" Run a command on a remote host using SSH.
9+
10+
Args:
11+
host (str): The hostname to connect to.
12+
username (str): The username to use to connect.
13+
password (str): The password to use to connect.
14+
command (str): The command to run on the remote host.
15+
16+
Returns:
17+
dict: A dictionary with the success status and the output of the command.
18+
"""
19+
try:
20+
client = paramiko.SSHClient()
21+
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
22+
client.connect(host, port=SSH_PORT,
23+
username=username, password=password)
24+
stdin, stdout, stderr = client.exec_command(command)
25+
output = stdout.read().decode('utf-8')
26+
error = stderr.read().decode('utf-8')
27+
client.close()
28+
if error:
29+
return {'success': False, 'output': error}
30+
else:
31+
return {'success': True, 'output': output}
32+
except Exception as e:
33+
print(str(e))
34+
return {'success': False, 'output': str(e)}

0 commit comments

Comments
 (0)