Fin du TP2
This commit is contained in:
@@ -139,6 +139,42 @@ def question_21():
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Erreur sur {device['hostname']} : {e}")
|
||||
def question_22():
|
||||
inventory = get_inventory()
|
||||
|
||||
for device in inventory:
|
||||
# On ne traite pas les routeurs dont le hostname != 'R1' de ESW1
|
||||
if 'R1' == device["hostname"] or 'ESW1' == device["hostname"]:
|
||||
continue
|
||||
|
||||
print(f"\n=== Connexion au routeur {device['hostname']} ({device['ip']}) ===")
|
||||
|
||||
try:
|
||||
# Paramètres de connexion
|
||||
device_params = {
|
||||
'device_type': device['device_type'],
|
||||
'host': device['ip'],
|
||||
'username': device['username'],
|
||||
'password': device['password']
|
||||
}
|
||||
net_connect = ConnectHandler(**device_params)
|
||||
net_connect.enable()
|
||||
|
||||
# affiche le hostname
|
||||
print(f"Connexion réussie sur {device['hostname']}")
|
||||
|
||||
config_file = f'config/vlan_{device["hostname"]}.conf'
|
||||
output = net_connect.send_config_from_file(config_file)
|
||||
print(f"\nRésultat de l'application de la configuration sur {device['hostname']} :\n{output}")
|
||||
|
||||
# Sauvegarde la configuration
|
||||
save_output = net_connect.save_config()
|
||||
print(f"\nSauvegarde de la configuration sur {device['hostname']} :\n{save_output}")
|
||||
|
||||
net_connect.disconnect()
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Erreur sur {device['hostname']} : {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -154,7 +190,7 @@ if __name__ == "__main__":
|
||||
#question_17(net_connect)
|
||||
#question_18(net_connect)
|
||||
hosts = get_inventory()
|
||||
print(hosts)
|
||||
#print(hosts)
|
||||
#question_20()
|
||||
#question_21()
|
||||
net_connect.disconnect()
|
||||
question_22()
|
||||
Reference in New Issue
Block a user