From b43f1ad1dd224388ecd255bc2b935f7a6b1ae11c Mon Sep 17 00:00:00 2001 From: Sophie Axebane Date: Tue, 26 Dec 2023 17:03:52 -0600 Subject: [PATCH] complete refactor --- deploy.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/deploy.py b/deploy.py index cda664e..3ee8dfe 100644 --- a/deploy.py +++ b/deploy.py @@ -9,7 +9,35 @@ with open("conf.json", "r") as file: # yeah yeah i should probably use YAML but i don't really want to fool with it rn lol -64 sshc = paramiko.client.SSHClient() -sshc.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # so we don't get whined at and crash over a unrecognized host-key +healthstatus = "" +healthpassing = True +# define sshc so we don't have to type the whole thing every time we want a client as well as set our healthpassing variable -sshc.connect(cfg["server"],port=cfg["port"],password=cfg["ssh-password"]) -sshc.exec_command("wall it works!!!") \ No newline at end of file +def healthcheck(): + global healthstatus + response = os.system("ping -c 2 " + cfg["server"]) + if response != 0: + healthstatus = "err" + else: + healthstatus = "ok" + +def deploy(): + # deployment shit here + sshc.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # so we don't get whined at and crash over a unrecognized host-key + sshc.connect(cfg["server"],port=cfg["port"],password=cfg["ssh-password"]) + +while True: + healthcheck() + + if healthstatus != "ok": + print(healthstatus) + print("ONT is not responding!! Did we lose network connection, or is the ONT rebooting? Waiting for a successful ping then deploying!") + healthpassing = False + while healthpassing == False: + if healthcheck() == "ok": + print("ONT responded, deploying payload!") + healthpassing == True; + else: + print(healthstatus) + +