implement --limit

This commit is contained in:
histausse 2021-09-25 12:52:00 +02:00
parent 33a3f20f89
commit 4b059c1e68

75
main.py
View file

@ -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: 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
# sw.gen_conf_and_write() sw.gen_conf_and_write()
# try: try:
# sw.apply_conf() sw.apply_conf()
# 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:
# sw = Switch() if "--upgrade" in sys.argv:
# for switch in all_switchs: sw = Switch()
# sw.switch = switch for switch in all_switchs:
# sw.upgrade() sw.switch = switch
# 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']:
# error = False error = False
# sw=Switch() sw=Switch()
# for switch in all_switchs: for switch in all_switchs:
# sw.switch = switch sw.switch = switch
# sw.gen_conf_and_write() sw.gen_conf_and_write()
# try: try:
# sw.apply_conf() sw.apply_conf()
# except: except:
# error = True error = True
# api_client.patch(service['api_url'], data={'need_regen': error}) api_client.patch(service['api_url'], data={'need_regen': error})
for switch in all_switchs:
print(switch['short_name'])