syagent
This commit is contained in:
parent
42e0b233f3
commit
eb3b23e30f
Binary file not shown.
@ -1,13 +1,31 @@
|
|||||||
import paramiko
|
import paramiko
|
||||||
|
|
||||||
|
HOSTS_KEYS_PATH = '/home/luca/.ssh/known_hosts'
|
||||||
PKEY_PATH = '/home/luca/.ssh/notanamber_rsa'
|
PKEY_PATH = '/home/luca/.ssh/notanamber_rsa'
|
||||||
|
|
||||||
HOSTNAME = '107.152.32.78'
|
HOSTNAME = '107.152.32.78'
|
||||||
USERNAME = 'notanamber'
|
USERNAME = 'notanamber'
|
||||||
|
|
||||||
class ParaAgent():
|
class SyncAgent():
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pkey = paramiko.RSAKey.from_private_key_file(PKEY_PATH)
|
self.pkey = paramiko.RSAKey.from_private_key_file(PKEY_PATH)
|
||||||
self.client = paramiko.SSHClient()
|
self.client = paramiko.SSHClient()
|
||||||
_c = self.client
|
self.client.load_host_keys(filename=HOSTS_KEYS_PATH)
|
||||||
_c.connect(hostname=HOSTNAME, username=USERNAME, pkey=pkey, look_for_keys=False)
|
|
||||||
|
def connect(self):
|
||||||
|
self.client.connect(hostname=HOSTNAME, username=USERNAME, pkey=self.pkey, look_for_keys=False)
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.client.close()
|
||||||
|
|
||||||
|
def compute_hash(self, name):
|
||||||
|
self.connect()
|
||||||
|
stdin, stdout, stderr = self.client.exec_command("sha256sum %s | awk '{print $1}'" % (name, ))
|
||||||
|
# self.close()
|
||||||
|
ostream = stdout.read()
|
||||||
|
estream = stderr.read()
|
||||||
|
# stdout.read().strip() is the hash
|
||||||
|
if estream:
|
||||||
|
print("Command failed for this reason: %s" % (estream))
|
||||||
|
return ostream.strip()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user