From 18d0c52e03d7df6d5eb63a460badf1f3cdda178f Mon Sep 17 00:00:00 2001 From: Maxime Bombar Date: Mon, 29 Jul 2019 18:09:00 +0200 Subject: [PATCH] if __name__ == '__main__' pour ne pas reflasher les switches dans un import --- main.py | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/main.py b/main.py index 1b5be8a..3209723 100644 --- a/main.py +++ b/main.py @@ -237,34 +237,38 @@ class Switch: post_reboot = requests.post(url_reboot, data=json.dumps(data), headers=self.headers) -if "--force" in sys.argv: - sw = Switch() - for switch in all_switchs: - sw.switch = switch - sw.gen_conf_and_write() - try: - sw.apply_conf() - except: - print("Erreur dans l'application de la conf pour " + switch["short_name"]) - -if "--upgrade" in sys.argv: - sw = Switch() - for switch in all_switchs: - sw.switch = switch - sw.upgrade() -for service in api_client.list("services/regen/"): - if service['hostname'] == client_hostname and \ - service['service_name'] == 'switchs' and \ - service['need_regen']: - error = False - sw=Switch() +if __name__=='__main__': + + if "--force" in sys.argv: + sw = Switch() for switch in all_switchs: sw.switch = switch sw.gen_conf_and_write() try: sw.apply_conf() except: - error = True - api_client.patch(service['api_url'], data={'need_regen': error}) + print("Erreur dans l'application de la conf pour " + switch["short_name"]) + + if "--upgrade" in sys.argv: + sw = Switch() + for switch in all_switchs: + sw.switch = switch + sw.upgrade() + + + for service in api_client.list("services/regen/"): + if service['hostname'] == client_hostname and \ + service['service_name'] == 'switchs' and \ + service['need_regen']: + error = False + sw=Switch() + for switch in all_switchs: + sw.switch = switch + sw.gen_conf_and_write() + try: + sw.apply_conf() + except: + error = True + api_client.patch(service['api_url'], data={'need_regen': error})