trying to use paramiki

This commit is contained in:
Amber 2023-11-27 09:23:47 +01:00
parent 519ade0e99
commit 42e0b233f3
4 changed files with 36 additions and 1 deletions

Binary file not shown.

13
src/client/agent.py Normal file
View File

@ -0,0 +1,13 @@
import paramiko
PKEY_PATH = '/home/luca/.ssh/notanamber_rsa'
HOSTNAME = '107.152.32.78'
USERNAME = 'notanamber'
class ParaAgent():
def __init__(self):
pkey = paramiko.RSAKey.from_private_key_file(PKEY_PATH)
self.client = paramiko.SSHClient()
_c = self.client
_c.connect(hostname=HOSTNAME, username=USERNAME, pkey=pkey, look_for_keys=False)

View File

@ -10,10 +10,17 @@ def dcsnap(path: str, filename=None):
def diffsnap(snapshot_a, snapshot_b, path='./'):
'''
snapshot is a tree represented by dictionary {k, val} when k can be folder or file
and val can be a dictionary or an hash
@param snapshot_a snapshot computed at time t0
@param snapshot_b snapshot computed at time t1
'''
for name_a, hsh_a in snapshot_a.items():
hsh_b = snapshot_b.get(name_a)
if hsh_b is None:
print(f'{path}{name_a} present in snapshot_a but removed in snapshot_b, subtree {hsh_b} removed in snapshot_b')
print(f'{path}{name_a} present in snapshot_a but removed in snapshot_b, subtree {name_a} removed in snapshot_b')
continue
if type(hsh_a) != type(hsh_a):
print(f'{path}{name_a} present in snapshot_a and in snapshot_b, but different type')
@ -32,3 +39,18 @@ def diffsnap(snapshot_a, snapshot_b, path='./'):
else:
print(f'{path}{name_a} present in snapshot_a and in snapshot_b, snapshot_a: {hsh_a}, snapshot_b: {hsh_b}, unchanged')
def findsubtree(snapshot, subtree, path='./'):
'''
@param subtree dict
'''
subtree_key = list(subtree.keys())[0]
subtree_val = list(subtree.values())[0]
for snap_key, snap_val in snapshot.items():
if snap_key != subtree_key:
if isinstance(snap_val, dict):
path = '%s%s/' % (path, snap_key)
findsubtree(snap_val, subtree, path)
else:
if snap_val == subtree_val:
print(f'subtree found in snapshot in path {path}')