Commit acc56151 authored by Mineau Jean-Marie's avatar Mineau Jean-Marie
Browse files

Permet de passer en argument le noms des switchs sur les quels agir.

 Nouvelle option:
 passer l'argument --select, suivit par les nom de switchs,
 separes par des espaces, limite l'action du script aux switchs
 selectionnes. N'affecte pas le comportement du script autrement.
 exemple:
 ./main.py --select sw-ga-1 sw-ga-1 --force
parent 58eb2bad
......@@ -76,10 +76,10 @@ class Switch:
#Trie les ip par vlan, et les ajoute ainsi que les subnet
for ip, subnet in self.switch["interfaces_subnet"].items():
if not subnet[0]["vlan_id"] in vlans:
if not subnet["vlan_id"] in vlans:
raise RuntimeError("La config est dangeureuse, le vlan d'administration n'est pas propagé au switch !")
vlans[subnet[0]["vlan_id"]].setdefault("ipv4", {})
vlans[subnet[0]["vlan_id"]]["ipv4"][ip] = subnet
vlans[subnet["vlan_id"]].setdefault("ipv4", {})
vlans[subnet["vlan_id"]]["ipv4"][ip] = subnet
for ipv6, subnet in self.switch["interfaces6_subnet"].items():
vlans[subnet["vlan_id"]].setdefault("ipv6", {})
vlans[subnet["vlan_id"]]["ipv6"][ipv6] = subnet
......@@ -236,20 +236,42 @@ class Switch:
post_reboot = requests.post(url_reboot, data=json.dumps(data), headers=self.headers)
def find_switch(name):
"""Return the switch of the given name. Return None if the
switch is not found."""
for switch in all_switchs:
if switch["short_name"] == name:
return switch
return None
switchs = []
if "--select" in sys.argv:
i = sys.argv.index("--select") + 1
while i < len(sys.argv) and sys.argv[i][0] != '-':
name = sys.argv[i]
switch = find_switch(name)
if switch is None:
print("Erreur: le switch %s n'a pas ete trouve." %name)
else:
switchs.append(switch)
i += 1
else:
switchs = all_switchs
if "--force" in sys.argv:
sw = Switch()
for switch in all_switchs:
for switch in 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"])
#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:
for switch in switchs:
sw.switch = switch
sw.upgrade()
......@@ -260,7 +282,7 @@ for service in api_client.list("services/regen/"):
service['need_regen']:
error = False
sw=Switch()
for switch in all_switchs:
for switch in switchs:
sw.switch = switch
sw.gen_conf_and_write()
try:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment