refactored
This commit is contained in:
12
monitor.py
12
monitor.py
@@ -4,19 +4,19 @@ import paramiko
|
|||||||
import threading
|
import threading
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
class taskThread(threading.Thread):
|
class task_thread(threading.Thread):
|
||||||
def __init__(self, host, keys):
|
def __init__(self, host, keys):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.host = host
|
self.host = host
|
||||||
self.keys = keys
|
self.keys = keys
|
||||||
def run(self):
|
def run(self):
|
||||||
updateKeys(self.host, self.keys)
|
update_keys(self.host, self.keys)
|
||||||
|
|
||||||
def readConfig():
|
def read_config():
|
||||||
with open('config.yaml', 'r') as stream:
|
with open('config.yaml', 'r') as stream:
|
||||||
return yaml.safe_load(stream)
|
return yaml.safe_load(stream)
|
||||||
|
|
||||||
def updateKeys(host, keys):
|
def update_keys(host, keys):
|
||||||
try:
|
try:
|
||||||
client = paramiko.SSHClient()
|
client = paramiko.SSHClient()
|
||||||
client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
|
client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
|
||||||
@@ -29,7 +29,7 @@ def updateKeys(host, keys):
|
|||||||
print('❌ ' + host)
|
print('❌ ' + host)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
config = readConfig()
|
config = read_config()
|
||||||
|
|
||||||
keys = []
|
keys = []
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ def main():
|
|||||||
|
|
||||||
for host in config['hosts']:
|
for host in config['hosts']:
|
||||||
try:
|
try:
|
||||||
thread = taskThread(host, keys)
|
thread = task_thread(host, keys)
|
||||||
thread.start()
|
thread.start()
|
||||||
except:
|
except:
|
||||||
print('❌ ' + host)
|
print('❌ ' + host)
|
||||||
|
|||||||
12
sync.py
12
sync.py
@@ -4,19 +4,19 @@ import paramiko
|
|||||||
import threading
|
import threading
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
class taskThread(threading.Thread):
|
class task_thread(threading.Thread):
|
||||||
def __init__(self, host, keys):
|
def __init__(self, host, keys):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.host = host
|
self.host = host
|
||||||
self.keys = keys
|
self.keys = keys
|
||||||
def run(self):
|
def run(self):
|
||||||
updateKeys(self.host, self.keys)
|
update_keys(self.host, self.keys)
|
||||||
|
|
||||||
def readConfig():
|
def read_config():
|
||||||
with open('config.yaml', 'r') as stream:
|
with open('config.yaml', 'r') as stream:
|
||||||
return yaml.safe_load(stream)
|
return yaml.safe_load(stream)
|
||||||
|
|
||||||
def updateKeys(host, keys):
|
def update_keys(host, keys):
|
||||||
try:
|
try:
|
||||||
client = paramiko.SSHClient()
|
client = paramiko.SSHClient()
|
||||||
client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
|
client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
|
||||||
@@ -28,7 +28,7 @@ def updateKeys(host, keys):
|
|||||||
print('❌ ' + host)
|
print('❌ ' + host)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
config = readConfig()
|
config = read_config()
|
||||||
|
|
||||||
keys = []
|
keys = []
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ def main():
|
|||||||
|
|
||||||
for host in config['hosts']:
|
for host in config['hosts']:
|
||||||
try:
|
try:
|
||||||
thread = taskThread(host, keys)
|
thread = task_thread(host, keys)
|
||||||
thread.start()
|
thread.start()
|
||||||
except:
|
except:
|
||||||
print('❌ ' + host)
|
print('❌ ' + host)
|
||||||
|
|||||||
Reference in New Issue
Block a user