From 4b059c1e68d8448326d281233990d55015f88eb9 Mon Sep 17 00:00:00 2001 From: Jean-Marie Histausse Mineau Date: Sat, 25 Sep 2021 12:52:00 +0200 Subject: [PATCH] implement --limit --- main.py | 77 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/main.py b/main.py index 2509526..77028a2 100644 --- a/main.py +++ b/main.py @@ -277,38 +277,47 @@ if "--limit" in sys.argv: ) ) ) + found_switchs = { x['short_name'] for x in all_switchs } + all_switchs = list( + filter( + lambda x: x['short_name'] in limit_switchs, + all_switchs + ) + ) + if not limit_switchs.issubset(found_switchs): + print("WARNING: some switchs in the list have not been found in the re2o API and will not be processed") + for sw_name in limit_switchs - found_switchs: + print("{name} has not been found".format(name=sw_name)) + +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() + 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}) -#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() -# 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}) - -for switch in all_switchs: - print(switch['short_name'])