nornir-automation / nornir

Pluggable multi-threaded framework with inventory management to help operate collections of devices
https://nornir.readthedocs.io/
Apache License 2.0
1.39k stars 235 forks source link

routeros support #533

Closed ognjen011 closed 4 years ago

ognjen011 commented 4 years ago

Does nornir have ability use napalm for routeros and get interfaces and interface data? When i try i end up with this error

nornir.core.exceptions.NornirSubTaskError: Subtask: <function napalm_get at 0x7fdc172ed6a8> (failed)

dbarrosop commented 4 years ago

all the drivers and functionality should work without any interference/issue. Given that's not included in the napalm core project you may need to install it manually though (via pip or whatever other method the community driver supports)

Closing this issue as this is not an issue related to nornir but feel free to reopen/comment if needed.

ognjen011 commented 4 years ago

Ok i just saw this now sorry for the late response but i have installed using pip napalm-ros driver and i cannot get facts or interfaces running below. If i try procurve or eos or ios or junos they all work fine except for the napalm-ros. This is why i thought it might be something to do with nornir itself.

result = mikro.run(task=networking.napalm_get, getters=["facts"]) print_result(result) napalm_get**

result = mikro.run(task=networking.napalm_get, getters=["interfaces"]) print_result(result) napalm_get**

ktbyers commented 4 years ago

@ognjen011 You probably need to re-test this in straight napalm-ros and see if those getters are working outside of Nornir.

ognjen011 commented 4 years ago

Ok i am not much of programmer but below this basic script works fine with straight napalm-ros. If i try and use networking.napalm_get i am not seeing anything and i don't really know why...

from napalm import get_network_driver from pprint import pprint

driver = get_network_driver('ros') conn_method = {'transport': 'ssh'} host = '192.168.0.10' user ='admin' passwd = 'passs1'

with driver(hostname=host, username=user, password=passwd, optional_args=conn_method) as device: pprint(device.get_interfaces())

Getting facts {'fqdn': '', 'hostname': 'mikrotik1', 'interface_list': ['STPTEST', 'SUBTEST', 'bridge1_srcnat', 'bridge2', 'bridge_lan', 'ether1', 'ether2', 'ether3', 'ether4', 'ether5', 'ether6', 'ether7', 'ether8', 'ether9', 'ether10', 'lo0', 'sfp1', 'vlan55-internet', 'vlan23-failover', 'vlan903''], 'model': 'RB3011UiAS', 'os_version': '6.44.6 (long-term)', 'serial_number': '3AAC097BF9764', 'uptime': 3136303, 'vendor': 'MikroTik'}

Interfaces are also successful.

ktbyers commented 4 years ago

What exception do you get in Nornir when it fails (need the full actual exception...not just NornirSubTaskError)

ognjen011 commented 4 years ago

2020-04-26 23:29:18,703 - nornir.core.task - ERROR - start() - Host 'MIKROTIK1': task 'napalm_get' failed with traceback: Traceback (most recent call last): File "/Users/ognjen/Nornir/nornir-netbox-napalm/venv/lib/python3.7/site-packages/nornir/core/task.py", line 85, in start r = self.task(self, **self.params) File "/Users/ognjen/Nornir/nornir-netbox-napalm/venv/lib/python3.7/site-packages/nornir/plugins/tasks/networking/napalm_get.py", line 49, in napalm_get device = task.host.get_connection("napalm", task.nornir.config) File "/Users/ognjen/Nornir/nornir-netbox-napalm/venv/lib/python3.7/site-packages/nornir/core/inventory.py", line 302, in get_connection extras=conn.extras, File "/Users/ognjen/Nornir/nornir-netbox-napalm/venv/lib/python3.7/site-packages/nornir/core/inventory.py", line 352, in open_connection configuration=configuration, File "/Users/ognjen/Nornir/nornir-netbox-napalm/venv/lib/python3.7/site-packages/nornir/plugins/connections/napalm.py", line 49, in open network_driver = get_network_driver(platform) File "/Users/ognjen/Nornir/nornir-netbox-napalm/venv/lib/python3.7/site-packages/napalm/base/init.py", line 105, in get_network_driver install_name=name napalm.base.exceptions.ModuleImportError: Cannot import "routeros". Is the library installed?

2020-04-26 23:29:18,704 - nornir.core.task - ERROR - start() - MIKROTIK1'': task 'Create Netbox Interfaces' failed with traceback: Traceback (most recent call last): File "/Users/ognjen/Nornir/nornir-netbox-napalm/venv/lib/python3.7/site-packages/nornir/core/task.py", line 85, in start r = self.task(self, **self.params) File "scripts/create_interfaces.py", line 22, in create_netbox_interface r = task.run(task=networking.napalm_get, getters=["interfaces"]) File "/Users/ognjen/Nornir/nornir-netbox-napalm/venv/lib/python3.7/site-packages/nornir/core/task.py", line 147, in run raise NornirSubTaskError(task=task, result=r) nornir.core.exceptions.NornirSubTaskError: Subtask: <function napalm_get at 0x10d32d620> (failed)

It says no routeros installed. But

if i run pip3 install routeros

Requirement already satisfied: routeros in /Users/ognjen/nornir-netbox-napalm/venv/lib/python3.7/site-packages (1.1)

dbarrosop commented 4 years ago

Please, format things with markdown so they are legible.

Also, in your napalm snippet you used ros and here you are using routeros so I suspect you are not setting the platform correctly

ktbyers commented 4 years ago

Yeah, I agree with David. I would suspect you are not specifying the platform correctly in Nornir inventory.

ognjen011 commented 4 years ago

Ok you are absolutely right this was a mission to troubleshoot. I have been using Netbox for a few years and have napalm mapped to ros in netbox for Mikrotik devices but the device platform was set to routeros not ros because of other systems that connect to Netbox. I have been using it for a while with Ansible without any problems but i now realised that the platform slug needs to be set to ros. Thank you very much for the assistance.