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:
# 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:
print(switch['short_name'])
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})