refactor + add wake parameter

main
Alex 6 months ago
parent f97e43cdd9
commit 3205ba0887

@ -10,7 +10,6 @@ def assert_availibilty(target_host: str, wake_if_offline: bool = False):
ips = get_target_ips() ips = get_target_ips()
ip_target = ips[target_host] ip_target = ips[target_host]
target_node_route = f'http://{ip_target}:9713/status' target_node_route = f'http://{ip_target}:9713/status'
available = False
try: try:
response = requests.get(target_node_route, timeout=30) response = requests.get(target_node_route, timeout=30)
#print(f"{response =}") #print(f"{response =}")
@ -18,7 +17,7 @@ def assert_availibilty(target_host: str, wake_if_offline: bool = False):
print(f"{target_host} is online and ready.") print(f"{target_host} is online and ready.")
return True return True
else: else:
print(f"{target_host} is offline.") print(f"{target_host} is not responding correctly {response.status_code}.")
return False return False
except requests.exceptions.RequestException as re: except requests.exceptions.RequestException as re:
#print(f"Error: {str(re)}") #print(f"Error: {str(re)}")
@ -28,8 +27,7 @@ def assert_availibilty(target_host: str, wake_if_offline: bool = False):
print(f"Host {target_host} wird aufgeweckt. Warten auf Hochfaren...(1min)") print(f"Host {target_host} wird aufgeweckt. Warten auf Hochfaren...(1min)")
time.sleep(60) time.sleep(60)
return True return True
else: else:
print(f"{target_host} is offline.")
return False return False
@ -85,15 +83,17 @@ def process_arguments():
parser = argparse.ArgumentParser(description="Osiris Node Skript kommuniziert mit Osiris Listener bei Target Host.") parser = argparse.ArgumentParser(description="Osiris Node Skript kommuniziert mit Osiris Listener bei Target Host.")
parser.add_argument('target_host', type=str, choices=["nuc_morroc"], help='Profil des Ziel-Hostes') parser.add_argument('target_host', type=str, choices=["nuc_morroc"], help='Profil des Ziel-Hostes')
parser.add_argument('command', type=str, choices=['testcommand', 'shutdown', 'status'], help='Command to send to the target host') parser.add_argument('command', type=str, choices=['testcommand', 'shutdown', 'status'], help='Command to send to the target host')
parser.add_argument('-w', '--wake', action='store_true', help='Weckt Ziel-Host auf wenn offline')
args = parser.parse_args() args = parser.parse_args()
target_host = args.target_host target_host = args.target_host
#target_host = 'nuc_morroc' #target_host = 'nuc_morroc'
wake = args.wake
match args.command: match args.command:
case "status": case "status":
assert_availibilty(target_host) assert_availibilty(target_host,wake)
case "shutdown": case "shutdown":
assert_availibilty(target_host, wake_if_offline=True) assert_availibilty(target_host, wake_if_offline=True)
send_shutdown_command(target_host) send_shutdown_command(target_host)

Loading…
Cancel
Save