implement --limit
This commit is contained in:
parent
33a3f20f89
commit
4b059c1e68
1 changed files with 42 additions and 33 deletions
75
main.py
75
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:
|
||||
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})
|
||||
|
||||
|
|
Loading…
Reference in a new issue