Compare commits

..

2 Commits

Author SHA1 Message Date
ff878558f9 Fin TP3 2025-11-19 21:18:33 +01:00
f3f157318a TP3-Question 13 2025-11-18 19:31:26 +01:00
13 changed files with 1641 additions and 90 deletions

View File

@@ -6,6 +6,9 @@ name = "pypi"
[packages]
jinja2 = "*"
nornir = "*"
nornir-utils = "*"
nornir-napalm = "*"
nornir-netmiko = "*"
[dev-packages]

976
TP_03/Pipfile.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
interface g2/0.10
vrrp 10 ip 172.16.10.252
vrrp 10 priority 100
interface g2/0.20
vrrp 20 ip 172.16.20.252
vrrp 20 priority 100

View File

@@ -0,0 +1,10 @@
interface g3/0.10
vrrp 10 ip 172.16.30.252
vrrp 10 priority 100
interface g3/0.20
vrrp 20 ip 172.16.40.252
vrrp 20 priority 100

View File

@@ -0,0 +1,10 @@
interface g2/0.10
vrrp 10 ip 172.16.10.252
vrrp 10 priority 100
interface g2/0.20
vrrp 20 ip 172.16.20.252
vrrp 20 priority 100

View File

@@ -0,0 +1,10 @@
interface g3/0.10
vrrp 10 ip 172.16.30.252
vrrp 10 priority 100
interface g3/0.20
vrrp 20 ip 172.16.40.252
vrrp 20 priority 100

View File

@@ -0,0 +1,14 @@
interface g2/0.10
vrrp 10 ip 172.16.10.252
vrrp 10 priority 110
vrrp 10 preempt
exit
interface g2/0.20
vrrp 20 ip 172.16.20.252
vrrp 20 priority 110
vrrp 20 preempt
exit

View File

@@ -0,0 +1,14 @@
interface g3/0.10
vrrp 10 ip 172.16.30.252
vrrp 10 priority 110
vrrp 10 preempt
exit
interface g3/0.20
vrrp 20 ip 172.16.40.252
vrrp 20 priority 110
vrrp 20 preempt
exit

View File

@@ -9,6 +9,7 @@ R1-CPE-BAT-A:
device_model: C7200
locality: lyon
building: A
room: 001
R2-CPE-BAT-A:
hostname: 172.16.100.126

466
TP_03/nornir.log Normal file
View File

@@ -0,0 +1,466 @@
2025-11-19 18:40:40,438 - nornir.core - INFO - run() - Running task 'hello_world' with args {} on 6 hosts
2025-11-19 18:44:15,944 - nornir.core - INFO - run() - Running task 'hello_world' with args {} on 6 hosts
2025-11-19 19:00:56,214 - nornir.core - INFO - run() - Running task 'hello_world' with args {} on 6 hosts
2025-11-19 19:01:16,972 - nornir.core - INFO - run() - Running task 'hello_world' with args {} on 6 hosts
2025-11-19 19:08:22,746 - nornir.core - INFO - run() - Running task 'hello_world' with args {} on 2 hosts
2025-11-19 19:11:11,915 - nornir.core - INFO - run() - Running task 'hello_world' with args {} on 2 hosts
2025-11-19 19:18:15,120 - nornir.core - INFO - run() - Running task 'display_interfaces' with args {} on 4 hosts
2025-11-19 19:18:38,345 - nornir.core - INFO - run() - Running task 'display_interfaces' with args {} on 4 hosts
2025-11-19 19:18:50,044 - nornir.core - INFO - run() - Running task 'display_interfaces' with args {} on 4 hosts
2025-11-19 19:19:28,411 - nornir.core - INFO - run() - Running task 'display_interfaces' with args {} on 4 hosts
2025-11-19 19:19:40,474 - nornir.core - INFO - run() - Running task 'display_interfaces' with args {} on 4 hosts
2025-11-19 19:29:14,970 - nornir.core - WARNING - run() - Task 'get_arp_table' has not been run 0 hosts selected
2025-11-19 19:29:48,405 - nornir.core - WARNING - run() - Task 'get_arp_table' has not been run 0 hosts selected
2025-11-19 19:29:50,140 - nornir.core - WARNING - run() - Task 'get_arp_table' has not been run 0 hosts selected
2025-11-19 19:30:16,537 - nornir.core - INFO - run() - Running task 'get_arp_table' with args {} on 2 hosts
2025-11-19 19:40:38,152 - nornir.core - INFO - run() - Running task 'configure_loopback_r1' with args {} on 1 hosts
2025-11-19 19:40:39,238 - nornir.core.task - ERROR - start() - Host 'R1-CPE-BAT-A': task 'napalm_configure' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir_napalm/plugins/tasks/napalm_configure.py", line 36, in napalm_configure
device.load_merge_candidate(filename=filename, config=configuration)
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/napalm/ios/ios.py", line 319, in load_merge_candidate
return_status, msg = self._load_candidate_wrapper(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/napalm/ios/ios.py", line 272, in _load_candidate_wrapper
tmp_file = self._create_tmp_file(source_config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/napalm/ios/ios.py", line 247, in _create_tmp_file
fobj.write(config)
TypeError: write() argument must be str, not list
2025-11-19 19:40:39,238 - nornir.core.task - ERROR - start() - Host 'R1-CPE-BAT-A': task 'configure_loopback_r1' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/workspace/devnet/TP_03/scripts/run_nornir.py", line 101, in configure_loopback_r1
task.run(
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 173, in run
raise NornirSubTaskError(task=run_task, result=r)
nornir.core.exceptions.NornirSubTaskError: Subtask: napalm_configure (failed)
2025-11-19 19:40:39,239 - nornir.core - INFO - run() - Running task 'configure_loopback_r2' with args {} on 1 hosts
2025-11-19 19:40:41,156 - nornir.core.task - ERROR - start() - Host 'R2-CPE-BAT-A': task 'napalm_configure' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir_napalm/plugins/tasks/napalm_configure.py", line 36, in napalm_configure
device.load_merge_candidate(filename=filename, config=configuration)
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/napalm/ios/ios.py", line 319, in load_merge_candidate
return_status, msg = self._load_candidate_wrapper(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/napalm/ios/ios.py", line 272, in _load_candidate_wrapper
tmp_file = self._create_tmp_file(source_config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/napalm/ios/ios.py", line 247, in _create_tmp_file
fobj.write(config)
TypeError: write() argument must be str, not list
2025-11-19 19:40:41,156 - nornir.core.task - ERROR - start() - Host 'R2-CPE-BAT-A': task 'configure_loopback_r2' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/workspace/devnet/TP_03/scripts/run_nornir.py", line 111, in configure_loopback_r2
task.run(
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 173, in run
raise NornirSubTaskError(task=run_task, result=r)
nornir.core.exceptions.NornirSubTaskError: Subtask: napalm_configure (failed)
2025-11-19 19:41:49,679 - nornir.core - INFO - run() - Running task 'configure_loopback_r1' with args {} on 1 hosts
2025-11-19 19:41:56,084 - nornir.core - INFO - run() - Running task 'configure_loopback_r2' with args {} on 1 hosts
2025-11-19 19:45:42,758 - nornir.core - INFO - run() - Running task 'save_running_config' with args {} on 2 hosts
2025-11-19 19:49:19,505 - nornir.core - INFO - run() - Running task 'save_running_config' with args {} on 6 hosts
2025-11-19 19:54:42,624 - nornir.core - INFO - run() - Running task 'netmiko_send_command' with args {'command_string': 'show ip interface brief'} on 6 hosts
2025-11-19 19:56:30,536 - nornir.core - INFO - run() - Running task 'netmiko_send_command' with args {'command_string': 'show ip interface brief'} on 4 hosts
2025-11-19 20:01:19,677 - nornir.core - INFO - run() - Running task 'netmiko_send_command' with args {'command_string': 'show ip interface brief'} on 4 hosts
2025-11-19 20:02:38,196 - nornir.core - INFO - run() - Running task 'netmiko_send_command' with args {'command_string': 'show ip interface brief'} on 4 hosts
2025-11-19 20:03:02,633 - nornir.core - INFO - run() - Running task 'netmiko_send_command' with args {'command_string': 'show ip interface brief'} on 4 hosts
2025-11-19 20:06:31,508 - nornir.core - WARNING - run() - Task 'configure_loopback2_r1' has not been run 0 hosts selected
2025-11-19 20:06:31,509 - nornir.core - WARNING - run() - Task 'configure_loopback2_r2' has not been run 0 hosts selected
2025-11-19 20:06:39,269 - nornir.core - WARNING - run() - Task 'save_running_config_netmiko' has not been run 0 hosts selected
2025-11-19 20:06:46,944 - nornir.core - WARNING - run() - Task 'save_running_config_netmiko' has not been run 0 hosts selected
2025-11-19 20:08:17,189 - nornir.core - WARNING - run() - Task 'configure_loopback2_r1' has not been run 0 hosts selected
2025-11-19 20:08:17,190 - nornir.core - WARNING - run() - Task 'configure_loopback2_r2' has not been run 0 hosts selected
2025-11-19 20:09:22,392 - nornir.core - INFO - run() - Running task 'conf_lo2_R1' with args {} on 1 hosts
2025-11-19 20:09:23,460 - nornir.core - INFO - run() - Running task 'conf_lo2_R2' with args {} on 1 hosts
2025-11-19 20:11:48,272 - nornir.core - INFO - run() - Running task 'configure_loopback2_r1' with args {} on 1 hosts
2025-11-19 20:11:49,239 - nornir.core - INFO - run() - Running task 'configure_loopback2_r2' with args {} on 1 hosts
2025-11-19 20:12:56,701 - nornir.core - WARNING - run() - Task 'save_running_config_netmiko' has not been run 0 hosts selected
2025-11-19 20:13:46,437 - nornir.core - WARNING - run() - Task 'save_running_config' has not been run 0 hosts selected
2025-11-19 20:13:57,617 - nornir.core - WARNING - run() - Task 'save_running_config' has not been run 0 hosts selected
2025-11-19 20:14:28,120 - nornir.core - INFO - run() - Running task 'netmiko_save_config' with args {} on 1 hosts
2025-11-19 20:14:29,499 - nornir.core - INFO - run() - Running task 'netmiko_save_config' with args {} on 1 hosts
2025-11-19 20:15:02,804 - nornir.core - INFO - run() - Running task 'netmiko_save_config' with args {} on 1 hosts
2025-11-19 20:15:04,166 - nornir.core - INFO - run() - Running task 'netmiko_save_config' with args {} on 1 hosts
2025-11-19 20:40:18,565 - nornir.core - INFO - run() - Running task 'Déploiement config R1-CPE-BAT-A' with args {'config_file': 'config/R1_CPE_LYON_BAT_A.conf'} on 1 hosts
2025-11-19 20:42:07,177 - nornir.core - INFO - run() - Running task 'Déploiement config R1-CPE-BAT-A' with args {'config_file': 'config/R1_CPE_LYON_BAT_A.conf'} on 1 hosts
2025-11-19 20:42:08,992 - nornir.core - INFO - run() - Running task 'Déploiement config R2-CPE-BAT-A' with args {'config_file': 'config/R2_CPE_LYON_BAT_A.conf'} on 1 hosts
2025-11-19 20:42:13,603 - nornir.core - INFO - run() - Running task 'Déploiement config R1-CPE-BAT-B' with args {'config_file': 'config/R1_CPE_LYON_BAT_B.conf'} on 1 hosts
2025-11-19 20:42:20,317 - nornir.core - INFO - run() - Running task 'Déploiement config R2-CPE-BAT-B' with args {'config_file': 'config/R2_CPE_LYON_BAT_B.conf'} on 1 hosts
2025-11-19 20:43:14,195 - nornir.core - INFO - run() - Running task 'Déploiement config R1-CPE-BAT-A' with args {'config_file': 'config/R1_CPE_LYON_BAT_A.conf'} on 1 hosts
2025-11-19 20:43:16,056 - nornir.core - INFO - run() - Running task 'Déploiement config R2-CPE-BAT-A' with args {'config_file': 'config/R2_CPE_LYON_BAT_A.conf'} on 1 hosts
2025-11-19 20:43:20,870 - nornir.core - INFO - run() - Running task 'Déploiement config R1-CPE-BAT-B' with args {'config_file': 'config/R1_CPE_LYON_BAT_B.conf'} on 1 hosts
2025-11-19 20:43:27,725 - nornir.core - INFO - run() - Running task 'Déploiement config R2-CPE-BAT-B' with args {'config_file': 'config/R2_CPE_LYON_BAT_B.conf'} on 1 hosts
2025-11-19 20:43:35,074 - nornir.core - INFO - run() - Running task 'Déploiement config ESW1-CPE-BAT-A' with args {'config_file': 'config/ESW1_CPE_LYON_BAT_A.conf'} on 1 hosts
2025-11-19 20:43:46,828 - nornir.core - INFO - run() - Running task 'Déploiement config ESW1-CPE-BAT-B' with args {'config_file': 'config/ESW1_CPE_LYON_BAT_B.conf'} on 1 hosts
2025-11-19 21:05:10,379 - nornir.core - INFO - run() - Running task 'Déploiement config R1-CPE-BAT-A' with args {'config_file': 'config/R1_CPE_LYON_BAT_A.conf'} on 1 hosts
2025-11-19 21:05:12,171 - nornir.core - INFO - run() - Running task 'Déploiement config R2-CPE-BAT-A' with args {'config_file': 'config/R2_CPE_LYON_BAT_A.conf'} on 1 hosts
2025-11-19 21:05:16,888 - nornir.core - INFO - run() - Running task 'Déploiement config R1-CPE-BAT-B' with args {'config_file': 'config/R1_CPE_LYON_BAT_B.conf'} on 1 hosts
2025-11-19 21:05:23,651 - nornir.core - INFO - run() - Running task 'Déploiement config R2-CPE-BAT-B' with args {'config_file': 'config/R2_CPE_LYON_BAT_B.conf'} on 1 hosts
2025-11-19 21:05:30,862 - nornir.core - INFO - run() - Running task 'Déploiement config ESW1-CPE-BAT-A' with args {'config_file': 'config/ESW1_CPE_LYON_BAT_A.conf'} on 1 hosts
2025-11-19 21:05:43,181 - nornir.core - INFO - run() - Running task 'Déploiement VRRP R1-CPE-BAT-A' with args {'config_file': 'config/R1_CPE_LYON_BAT_A_VRRP.conf'} on 4 hosts
2025-11-19 21:05:47,818 - nornir.core - INFO - run() - Running task 'Déploiement VRRP R2-CPE-BAT-A' with args {'config_file': 'config/R2_CPE_LYON_BAT_A_VRRP.conf'} on 4 hosts
2025-11-19 21:06:06,972 - nornir.core.task - ERROR - start() - Host 'R1-CPE-BAT-B': task 'netmiko_send_config' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir_netmiko/tasks/netmiko_send_config.py", line 38, in netmiko_send_config
result = net_connect.send_config_set(config_commands=config_commands, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 111, in wrapper_decorator
return_val = func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 2341, in send_config_set
output += self.read_until_pattern(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 755, in read_until_pattern
raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout:
Pattern not detected: '(?:R3.*$|#.*$)' in output.
Things you might try to fix this:
1. Adjust the regex pattern to better identify the terminating string. Note, in
many situations the pattern is automatically based on the network device's prompt.
2. Increase the read_timeout to a larger value.
You can also look at the Netmiko session_log or debug log for more information.
2025-11-19 21:06:06,973 - nornir.core.task - ERROR - start() - Host 'R1-CPE-BAT-B': task 'Déploiement VRRP R2-CPE-BAT-A' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/workspace/devnet/TP_03/scripts/run_nornir.py", line 174, in deploy_config_from_file
result = task.run(task=netmiko_send_config, config_commands=commands)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 173, in run
raise NornirSubTaskError(task=run_task, result=r)
nornir.core.exceptions.NornirSubTaskError: Subtask: netmiko_send_config (failed)
2025-11-19 21:06:07,086 - nornir.core.task - ERROR - start() - Host 'R2-CPE-BAT-B': task 'netmiko_send_config' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir_netmiko/tasks/netmiko_send_config.py", line 38, in netmiko_send_config
result = net_connect.send_config_set(config_commands=config_commands, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 111, in wrapper_decorator
return_val = func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 2341, in send_config_set
output += self.read_until_pattern(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 755, in read_until_pattern
raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout:
Pattern not detected: '(?:R4.*$|#.*$)' in output.
Things you might try to fix this:
1. Adjust the regex pattern to better identify the terminating string. Note, in
many situations the pattern is automatically based on the network device's prompt.
2. Increase the read_timeout to a larger value.
You can also look at the Netmiko session_log or debug log for more information.
2025-11-19 21:06:07,087 - nornir.core.task - ERROR - start() - Host 'R2-CPE-BAT-B': task 'Déploiement VRRP R2-CPE-BAT-A' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/workspace/devnet/TP_03/scripts/run_nornir.py", line 174, in deploy_config_from_file
result = task.run(task=netmiko_send_config, config_commands=commands)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 173, in run
raise NornirSubTaskError(task=run_task, result=r)
nornir.core.exceptions.NornirSubTaskError: Subtask: netmiko_send_config (failed)
2025-11-19 21:06:07,087 - nornir.core - INFO - run() - Running task 'Déploiement VRRP R1-CPE-BAT-B' with args {'config_file': 'config/R1_CPE_LYON_BAT_B_VRRP.conf'} on 2 hosts
2025-11-19 21:06:09,387 - nornir.core - INFO - run() - Running task 'Déploiement VRRP R2-CPE-BAT-B' with args {'config_file': 'config/R2_CPE_LYON_BAT_B_VRRP.conf'} on 2 hosts
2025-11-19 21:06:24,723 - nornir.core.task - ERROR - start() - Host 'R1-CPE-BAT-A': task 'netmiko_send_config' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir_netmiko/tasks/netmiko_send_config.py", line 38, in netmiko_send_config
result = net_connect.send_config_set(config_commands=config_commands, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 111, in wrapper_decorator
return_val = func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 2341, in send_config_set
output += self.read_until_pattern(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 755, in read_until_pattern
raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout:
Pattern not detected: '(?:R1\\-CPE\\-BAT\\-A.*$|#.*$)' in output.
Things you might try to fix this:
1. Adjust the regex pattern to better identify the terminating string. Note, in
many situations the pattern is automatically based on the network device's prompt.
2. Increase the read_timeout to a larger value.
You can also look at the Netmiko session_log or debug log for more information.
2025-11-19 21:06:24,724 - nornir.core.task - ERROR - start() - Host 'R1-CPE-BAT-A': task 'Déploiement VRRP R2-CPE-BAT-B' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/workspace/devnet/TP_03/scripts/run_nornir.py", line 174, in deploy_config_from_file
result = task.run(task=netmiko_send_config, config_commands=commands)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 173, in run
raise NornirSubTaskError(task=run_task, result=r)
nornir.core.exceptions.NornirSubTaskError: Subtask: netmiko_send_config (failed)
2025-11-19 21:06:26,274 - nornir.core.task - ERROR - start() - Host 'R2-CPE-BAT-A': task 'netmiko_send_config' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir_netmiko/tasks/netmiko_send_config.py", line 38, in netmiko_send_config
result = net_connect.send_config_set(config_commands=config_commands, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 111, in wrapper_decorator
return_val = func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 2341, in send_config_set
output += self.read_until_pattern(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 755, in read_until_pattern
raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout:
Pattern not detected: '(?:R2\\-CPE\\-BAT\\-A.*$|#.*$)' in output.
Things you might try to fix this:
1. Adjust the regex pattern to better identify the terminating string. Note, in
many situations the pattern is automatically based on the network device's prompt.
2. Increase the read_timeout to a larger value.
You can also look at the Netmiko session_log or debug log for more information.
2025-11-19 21:06:26,274 - nornir.core.task - ERROR - start() - Host 'R2-CPE-BAT-A': task 'Déploiement VRRP R2-CPE-BAT-B' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/workspace/devnet/TP_03/scripts/run_nornir.py", line 174, in deploy_config_from_file
result = task.run(task=netmiko_send_config, config_commands=commands)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 173, in run
raise NornirSubTaskError(task=run_task, result=r)
nornir.core.exceptions.NornirSubTaskError: Subtask: netmiko_send_config (failed)
2025-11-19 21:10:21,422 - nornir.core - INFO - run() - Running task 'Déploiement config R1-CPE-BAT-A' with args {'config_file': 'config/R1_CPE_LYON_BAT_A.conf'} on 1 hosts
2025-11-19 21:10:22,898 - nornir.core - INFO - run() - Running task 'Déploiement config R2-CPE-BAT-A' with args {'config_file': 'config/R2_CPE_LYON_BAT_A.conf'} on 1 hosts
2025-11-19 21:10:27,396 - nornir.core - INFO - run() - Running task 'Déploiement config R1-CPE-BAT-B' with args {'config_file': 'config/R1_CPE_LYON_BAT_B.conf'} on 1 hosts
2025-11-19 21:10:33,880 - nornir.core - INFO - run() - Running task 'Déploiement config R2-CPE-BAT-B' with args {'config_file': 'config/R2_CPE_LYON_BAT_B.conf'} on 1 hosts
2025-11-19 21:10:41,130 - nornir.core - INFO - run() - Running task 'Déploiement config ESW1-CPE-BAT-A' with args {'config_file': 'config/ESW1_CPE_LYON_BAT_A.conf'} on 1 hosts
2025-11-19 21:10:52,301 - nornir.core - INFO - run() - Running task 'Déploiement VRRP R1-CPE-BAT-A' with args {'config_file': 'config/R1_CPE_LYON_BAT_A_VRRP.conf'} on 4 hosts
2025-11-19 21:10:56,518 - nornir.core - INFO - run() - Running task 'Déploiement VRRP R2-CPE-BAT-A' with args {'config_file': 'config/R2_CPE_LYON_BAT_A_VRRP.conf'} on 4 hosts
2025-11-19 21:11:15,616 - nornir.core.task - ERROR - start() - Host 'R1-CPE-BAT-B': task 'netmiko_send_config' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir_netmiko/tasks/netmiko_send_config.py", line 38, in netmiko_send_config
result = net_connect.send_config_set(config_commands=config_commands, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 111, in wrapper_decorator
return_val = func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 2341, in send_config_set
output += self.read_until_pattern(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 755, in read_until_pattern
raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout:
Pattern not detected: '(?:R3.*$|#.*$)' in output.
Things you might try to fix this:
1. Adjust the regex pattern to better identify the terminating string. Note, in
many situations the pattern is automatically based on the network device's prompt.
2. Increase the read_timeout to a larger value.
You can also look at the Netmiko session_log or debug log for more information.
2025-11-19 21:11:15,617 - nornir.core.task - ERROR - start() - Host 'R1-CPE-BAT-B': task 'Déploiement VRRP R2-CPE-BAT-A' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/workspace/devnet/TP_03/scripts/run_nornir.py", line 174, in deploy_config_from_file
result = task.run(task=netmiko_send_config, config_commands=commands)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 173, in run
raise NornirSubTaskError(task=run_task, result=r)
nornir.core.exceptions.NornirSubTaskError: Subtask: netmiko_send_config (failed)
2025-11-19 21:11:15,787 - nornir.core.task - ERROR - start() - Host 'R2-CPE-BAT-B': task 'netmiko_send_config' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir_netmiko/tasks/netmiko_send_config.py", line 38, in netmiko_send_config
result = net_connect.send_config_set(config_commands=config_commands, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 111, in wrapper_decorator
return_val = func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 2341, in send_config_set
output += self.read_until_pattern(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 755, in read_until_pattern
raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout:
Pattern not detected: '(?:R4.*$|#.*$)' in output.
Things you might try to fix this:
1. Adjust the regex pattern to better identify the terminating string. Note, in
many situations the pattern is automatically based on the network device's prompt.
2. Increase the read_timeout to a larger value.
You can also look at the Netmiko session_log or debug log for more information.
2025-11-19 21:11:15,787 - nornir.core.task - ERROR - start() - Host 'R2-CPE-BAT-B': task 'Déploiement VRRP R2-CPE-BAT-A' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/workspace/devnet/TP_03/scripts/run_nornir.py", line 174, in deploy_config_from_file
result = task.run(task=netmiko_send_config, config_commands=commands)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 173, in run
raise NornirSubTaskError(task=run_task, result=r)
nornir.core.exceptions.NornirSubTaskError: Subtask: netmiko_send_config (failed)
2025-11-19 21:11:15,788 - nornir.core - INFO - run() - Running task 'Déploiement VRRP R1-CPE-BAT-B' with args {'config_file': 'config/R1_CPE_LYON_BAT_B_VRRP.conf'} on 2 hosts
2025-11-19 21:11:17,906 - nornir.core - INFO - run() - Running task 'Déploiement VRRP R2-CPE-BAT-B' with args {'config_file': 'config/R2_CPE_LYON_BAT_B_VRRP.conf'} on 2 hosts
2025-11-19 21:11:33,189 - nornir.core.task - ERROR - start() - Host 'R1-CPE-BAT-A': task 'netmiko_send_config' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir_netmiko/tasks/netmiko_send_config.py", line 38, in netmiko_send_config
result = net_connect.send_config_set(config_commands=config_commands, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 111, in wrapper_decorator
return_val = func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 2341, in send_config_set
output += self.read_until_pattern(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 755, in read_until_pattern
raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout:
Pattern not detected: '(?:R1\\-CPE\\-BAT\\-A.*$|#.*$)' in output.
Things you might try to fix this:
1. Adjust the regex pattern to better identify the terminating string. Note, in
many situations the pattern is automatically based on the network device's prompt.
2. Increase the read_timeout to a larger value.
You can also look at the Netmiko session_log or debug log for more information.
2025-11-19 21:11:33,189 - nornir.core.task - ERROR - start() - Host 'R1-CPE-BAT-A': task 'Déploiement VRRP R2-CPE-BAT-B' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/workspace/devnet/TP_03/scripts/run_nornir.py", line 174, in deploy_config_from_file
result = task.run(task=netmiko_send_config, config_commands=commands)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 173, in run
raise NornirSubTaskError(task=run_task, result=r)
nornir.core.exceptions.NornirSubTaskError: Subtask: netmiko_send_config (failed)
2025-11-19 21:11:34,809 - nornir.core.task - ERROR - start() - Host 'R2-CPE-BAT-A': task 'netmiko_send_config' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir_netmiko/tasks/netmiko_send_config.py", line 38, in netmiko_send_config
result = net_connect.send_config_set(config_commands=config_commands, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 111, in wrapper_decorator
return_val = func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 2341, in send_config_set
output += self.read_until_pattern(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/netmiko/base_connection.py", line 755, in read_until_pattern
raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout:
Pattern not detected: '(?:R2\\-CPE\\-BAT\\-A.*$|#.*$)' in output.
Things you might try to fix this:
1. Adjust the regex pattern to better identify the terminating string. Note, in
many situations the pattern is automatically based on the network device's prompt.
2. Increase the read_timeout to a larger value.
You can also look at the Netmiko session_log or debug log for more information.
2025-11-19 21:11:34,809 - nornir.core.task - ERROR - start() - Host 'R2-CPE-BAT-A': task 'Déploiement VRRP R2-CPE-BAT-B' failed with traceback:
Traceback (most recent call last):
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 98, in start
r = self.task(self, **self.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/workspace/devnet/TP_03/scripts/run_nornir.py", line 174, in deploy_config_from_file
result = task.run(task=netmiko_send_config, config_commands=commands)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cpe/.local/share/virtualenvs/TP_03-khcHFeCv/lib/python3.12/site-packages/nornir/core/task.py", line 173, in run
raise NornirSubTaskError(task=run_task, result=r)
nornir.core.exceptions.NornirSubTaskError: Subtask: netmiko_send_config (failed)

View File

@@ -28,10 +28,15 @@ def create_config_cpe_lyon_batA():
R1_LYON_BAT_A_data = load_json_data_from_file(file_path='data/R1_CPE_LYON_BAT_A.json')
R1_LYON_BAT_A_config = render_network_config(template_name='vlan_router.j2', data=R1_LYON_BAT_A_data)
R2_LYON_BAT_A_config_vrrp = render_network_config(template_name='vrrp_router.j2', data=R2_LYON_BAT_A_data)
R1_LYON_BAT_A_config_vrrp = render_network_config(template_name='vrrp_router.j2', data=R1_LYON_BAT_A_data)
return {
'esw1': ESW1_CPE_LYON_BAT_A_config,
'r1': R1_LYON_BAT_A_config,
'r2': R2_LYON_BAT_A_config
'r2': R2_LYON_BAT_A_config,
'r1_vrrp' : R1_LYON_BAT_A_config_vrrp,
'r2_vrrp' : R2_LYON_BAT_A_config_vrrp
}
def create_config_cpe_lyon_batB():
@@ -44,10 +49,14 @@ def create_config_cpe_lyon_batB():
R1_LYON_BAT_B_data = load_json_data_from_file(file_path='data/R1_CPE_LYON_BAT_B.json')
R1_LYON_BAT_B_config = render_network_config(template_name='vlan_router.j2', data=R1_LYON_BAT_B_data)
R2_LYON_BAT_B_config_vrrp = render_network_config(template_name='vrrp_router.j2', data=R2_LYON_BAT_B_data)
R1_LYON_BAT_B_config_vrrp = render_network_config(template_name='vrrp_router.j2', data=R1_LYON_BAT_B_data)
return {
'esw1': ESW1_CPE_LYON_BAT_B_config,
'r1': R1_LYON_BAT_B_config,
'r2': R2_LYON_BAT_B_config
'r2': R2_LYON_BAT_B_config,
'r1_vrrp' : R1_LYON_BAT_B_config_vrrp,
'r2_vrrp' : R2_LYON_BAT_B_config_vrrp
}
if __name__ == "__main__":
@@ -61,10 +70,14 @@ if __name__ == "__main__":
save_built_config('config/R1_CPE_LYON_BAT_A.conf', config.get('r1'))
save_built_config('config/R2_CPE_LYON_BAT_A.conf', config.get('r2'))
save_built_config('config/ESW1_CPE_LYON_BAT_A.conf', config.get('esw1'))
save_built_config('config/R1_CPE_LYON_BAT_A_VRRP.conf', config.get('r1_vrrp'))
save_built_config('config/R2_CPE_LYON_BAT_A_VRRP.conf', config.get('r2_vrrp'))
#question 5:
config = create_config_cpe_lyon_batB()
save_built_config('config/R1_CPE_LYON_BAT_B.conf', config.get('r1'))
save_built_config('config/R2_CPE_LYON_BAT_B.conf', config.get('r2'))
save_built_config('config/ESW1_CPE_LYON_BAT_B.conf', config.get('esw1'))
save_built_config('config/R1_CPE_LYON_BAT_B_VRRP.conf', config.get('r1_vrrp'))
save_built_config('config/R2_CPE_LYON_BAT_B_VRRP.conf', config.get('r2_vrrp'))

View File

@@ -1,46 +1,66 @@
from nornir import InitNornir
from nornir.core.task import Task, Result
from nornir_utils.plugins.functions import print_result
from nornir_napalm.plugins.tasks import napalm_get,napalm_configure, napalm_cli
from nornir_netmiko.tasks import netmiko_send_config,netmiko_send_command, netmiko_save_config, netmiko_commit
def question_13(nr):
pass
for key in nr.__dict__.keys():
print(f" - {key}")
def question_14(nr):
pass
print(nr.inventory.hosts)
print(type(nr.inventory.hosts))
def question_15(nr):
pass
print(nr.inventory.hosts["R1-CPE-BAT-A"])
print(type(nr.inventory.hosts["R1-CPE-BAT-A"]))
def question_16(nr):
pass
print(dir(nr.inventory.hosts["R1-CPE-BAT-A"]))
first_host = list(nr.inventory.hosts.values())[0]
print(f"Adresse IP (hostname): {first_host.hostname}")
print(f"Username: {first_host.username}")
print(f"Password: {first_host.password}")
def question_17(nr):
pass
print(dir(nr.inventory.hosts["R1-CPE-BAT-A"]))
def question_18(nr):
pass
print(nr.inventory.hosts["R1-CPE-BAT-A"].data["room"])
def question_19(nr):
pass
print(nr.inventory.groups)
def question_20(nr):
pass
print(nr.inventory.hosts.get('R1-CPE-BAT-A').groups)
def question_21(nr):
pass
print(nr.inventory.hosts.get('R1-CPE-BAT-A').groups[0].keys())
def question_22(nr):
pass
print(nr.inventory.hosts.get('R1-CPE-BAT-A').groups[0].get('vendor'))
def question_23(nr):
pass
for host_name in nr.inventory.hosts:
print(nr.inventory.hosts.get(host_name).hostname)
def question_24(nr):
pass
print(nr.filter(device_type='router').inventory.hosts.keys())
def question_25(nr):
pass
print(nr.filter(device_type='router_switch').inventory.hosts.keys())
def hello_world(task: Task) -> Result:
return Result(
host=task.host,
result=f"{task.host.name} says hello world!"
)
def question_26(nr):
pass
result = nr.run(task=hello_world)
print(result)
def question_27(nr):
result = nr.run(task=hello_world)
@@ -51,31 +71,153 @@ def question_29(nr):
print_result(result)
def question_30(nr):
pass
host = nr.filter(device_type='router_switch')
print_result(host.run(task=hello_world))
def display_interfaces(task):
task.run(
task=napalm_cli,
commands=["show ip interface brief"]
)
def question_32(nr):
pass
filtre = nr.filter(device_type='router')
result = filtre.run(task=display_interfaces)
print_result(result)
def get_arp_table(task):
task.run(
task=napalm_get,
getters=["arp_table"]
)
def configure_loopback_r1(task):
task.run(
task=napalm_configure,
configuration="""
interface Lo1
ip address 1.1.1.1 255.255.255.255
description Loopback pour R1-CPE-BAT-A
"""
)
def configure_loopback_r2(task):
task.run(
task=napalm_configure,
configuration="""
interface Lo1
ip address 2.2.2.2 255.255.255.255
description Loopback pour R2-CPE-BAT-A
"""
)
def question_33(nr):
pass
def question_34(nr):
pass
R1 = nr.filter(name='R1-CPE-BAT-A')
result_R1 = R1.run(task=configure_loopback_r1)
R2 = nr.filter(name='R2-CPE-BAT-A')
result_R2 = R2.run(task=configure_loopback_r2)
print_result(result_R1)
print_result(result_R2)
def save_running_config(task):
# Exécute la commande de sauvegarde de la configuration
task.run(
task=napalm_cli,
commands=["wr"]
)
def question_35(nr):
pass
result = nr.run(task=save_running_config)
print_result(result)
def question_36(nr):
pass
filtre = nr.filter(device_type='router')
result = filtre.run(task=netmiko_send_command,command_string="show ip interface brief")
print_result(result)
def configure_loopback2_r1(task):
config_commands = [
"interface loopback 2",
"ip address 1.1.1.2 255.255.255.255",
"description Loopback2 pour R1-CPE-BAT-A"
]
task.run(task=netmiko_send_config, config_commands=config_commands)
def configure_loopback2_r2(task):
config_commands = [
"interface loopback 2",
"ip address 2.2.2.3 255.255.255.255",
"description Loopback2 pour R2-CPE-BAT-A"
]
task.run(task=netmiko_send_config, config_commands=config_commands)
def question_37(nr):
pass
result_r1 = nr.filter(name='R1-CPE-BAT-A').run(task=configure_loopback2_r1)
result_r2 = nr.filter(name='R2-CPE-BAT-A').run(task=configure_loopback2_r2)
print_result(result_r1)
print_result(result_r2)
def question_38(nr):
pass
filtreR1 = nr.filter(name='R1-CPE-BAT-A')
resultR1 = filtreR1.run(task=netmiko_save_config)
filtreR2 = nr.filter(name='R2-CPE-BAT-A')
resultR2 = filtreR2.run(task=netmiko_save_config)
print_result(resultR1)
print_result(resultR2)
def deploy_config_from_file(task: Task, config_file: str) -> Result:
"""Déploie la configuration depuis un fichier sur un équipement via Nornir/Netmiko."""
with open(config_file, "r") as f:
commands = f.read().splitlines()
result = task.run(task=netmiko_send_config, config_commands=commands)
print_result(result)
result = task.run(task=netmiko_save_config)
print_result(result)
return result
def deploy_to_hosts(nr, host_patterns):
"""Déploie les configurations pour tous les hôtes et ajoute le fichier VRRP pour les routers."""
for pattern in host_patterns:
# Filtrer uniquement par nom pour tous
filtered_hosts = nr.filter(name=pattern)
if not filtered_hosts.inventory.hosts:
print(f"Aucun hôte correspondant à '{pattern}'")
continue
for host_name, host_obj in filtered_hosts.inventory.hosts.items():
# Nom de fichier principal
filename = host_obj.name.replace("-", "_").replace("CPE", "CPE_LYON")
# Déploiement du fichier principal
filtered_hosts.run(
task=deploy_config_from_file,
config_file=f"config/{filename}.conf",
name=f"Déploiement config {host_obj.name}"
)
# Déploiement des fichiers VRRP uniquement pour les routers
routers = nr.filter(device_type='router')
for host_name, host_obj in routers.inventory.hosts.items():
vrrp_filename = host_obj.name.replace("-", "_").replace("CPE", "CPE_LYON") + "_VRRP.conf"
routers.run(
task=deploy_config_from_file,
config_file=f"config/{vrrp_filename}",
name=f"Déploiement VRRP {host_obj.name}"
)
def question_39(nr):
pass
host_patterns = [
'R1-CPE-BAT-A',
'R2-CPE-BAT-A',
'R1-CPE-BAT-B',
'R2-CPE-BAT-B',
'ESW1-CPE-BAT-A',
'ESW1-CPE-BAT-BS'
]
deploy_to_hosts(nr, host_patterns)
def question_39_d(nr):
pass
@@ -101,7 +243,7 @@ if __name__ == "__main__":
#question_24(nr)
#question_25(nr)
#question_26(nr)
question_27(nr)
#question_27(nr)
#question_29(nr)
#question_30(nr)
@@ -112,7 +254,7 @@ if __name__ == "__main__":
#question_36(nr)
#question_37(nr)
#question_38(nr)
#question_39(nr)
question_39(nr)
#question_39_d(nr)
#question_40(nr)