|
|
|
@ -13,6 +13,31 @@ import json
|
|
|
|
|
import datetime
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
HELP_MESSAGE = """
|
|
|
|
|
Provisionning script from re2o.
|
|
|
|
|
|
|
|
|
|
python3 main.py [--help]
|
|
|
|
|
[--force] [--upgrade] [--limit <switchs>]
|
|
|
|
|
|
|
|
|
|
--help
|
|
|
|
|
Print this message
|
|
|
|
|
--force
|
|
|
|
|
Force rewrite the switch config. If not applied, the script only reconfigure the switchs that
|
|
|
|
|
re2o indicate as needing regeneration.
|
|
|
|
|
--upgrade
|
|
|
|
|
Upgrade the switch config
|
|
|
|
|
--limit <switchs>
|
|
|
|
|
Limit the scripts to the given list of switchs.
|
|
|
|
|
the list of switchs is a coma separated list of switch short name, whitout spaces.
|
|
|
|
|
exp: python3 --force --limit sw-ga-1,sw-ga-2
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# Yes, it's uggly, but we don't need to load all the mess bellow for just an help message.
|
|
|
|
|
if "--help" in sys.argv:
|
|
|
|
|
print(HELP_MESSAGE)
|
|
|
|
|
exit()
|
|
|
|
|
|
|
|
|
|
config = ConfigParser()
|
|
|
|
|
config.read('config.ini')
|
|
|
|
|
|
|
|
|
@ -237,35 +262,42 @@ class Switch:
|
|
|
|
|
|
|
|
|
|
post_reboot = requests.post(url_reboot, data=json.dumps(data), headers=self.headers)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 "--limit" in sys.argv:
|
|
|
|
|
list_index = sys.argv.index("--limit") + 1
|
|
|
|
|
if len(sys.argv) >= list_index:
|
|
|
|
|
raise RuntimeError("--limit must be followeb by a comma separated list of switch")
|
|
|
|
|
|
|
|
|
|
#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'])
|
|
|
|
|