if __name__ == '__main__' pour ne pas reflasher les switches dans un import

This commit is contained in:
Maxime Bombar 2019-07-29 18:09:00 +02:00
parent 58eb2bad62
commit 18d0c52e03

10
main.py
View file

@ -237,7 +237,11 @@ class Switch:
post_reboot = requests.post(url_reboot, data=json.dumps(data), headers=self.headers) post_reboot = requests.post(url_reboot, data=json.dumps(data), headers=self.headers)
if "--force" in sys.argv:
if __name__=='__main__':
if "--force" in sys.argv:
sw = Switch() sw = Switch()
for switch in all_switchs: for switch in all_switchs:
sw.switch = switch sw.switch = switch
@ -247,14 +251,14 @@ if "--force" in sys.argv:
except: except:
print("Erreur dans l'application de la conf pour " + switch["short_name"]) print("Erreur dans l'application de la conf pour " + switch["short_name"])
if "--upgrade" in sys.argv: if "--upgrade" in sys.argv:
sw = Switch() sw = Switch()
for switch in all_switchs: for switch in all_switchs:
sw.switch = switch sw.switch = switch
sw.upgrade() sw.upgrade()
for service in api_client.list("services/regen/"): for service in api_client.list("services/regen/"):
if service['hostname'] == client_hostname and \ if service['hostname'] == client_hostname and \
service['service_name'] == 'switchs' and \ service['service_name'] == 'switchs' and \
service['need_regen']: service['need_regen']: