refactored

This commit is contained in:
2021-03-13 16:12:36 +01:00
parent bce2d3bcb3
commit da8a70297b
2 changed files with 12 additions and 12 deletions

View File

@@ -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
View File

@@ -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)