示例#1
0
 def setup_class(cls):
     ConnectionPluginRegister.deregister_all()
     ConnectionPluginRegister.register("dummy", DummyConnectionPlugin)
     ConnectionPluginRegister.register("dummy2", DummyConnectionPlugin)
     ConnectionPluginRegister.register("dummy_no_overrides",
                                       DummyConnectionPlugin)
     ConnectionPluginRegister.register(FailedConnectionPlugin.name,
                                       FailedConnectionPlugin)
示例#2
0

19 Dec 2020 Ported to nornir 3 by paketb0te

"""

# Imports
from rich import print as rprint
from nornir import InitNornir
from nornir.core.task import Task
from nornir.core.plugins.connections import ConnectionPluginRegister
from nornir_netmiko.tasks import netmiko_send_command
from netaddr import EUI

# Register Plugins
ConnectionPluginRegister.register("connection-name", netmiko_send_command)


def get_interface_info(task: Task, target: EUI) -> None:
    """
    Get MAC addresses of all interfaces and compare to target.
    If present, identify Device and Interface
    """
    interfaces = task.run(task=netmiko_send_command,
                          command_string="show interfaces",
                          use_genie=True).result

    for intf in interfaces:
        mac_addr = EUI(interfaces[intf]["mac_address"])
        if target == mac_addr:
            print_info(task, intf, target)
示例#3
0
from nornir_pyez.plugins.tasks import pyez_get_config
import os
from nornir import InitNornir
from nornir_utils.plugins.functions import print_result
from rich import print
from nornir.core.plugins.connections import ConnectionPluginRegister
from nornir_pyez.plugins.connections import Pyez

ConnectionPluginRegister.register("pyez", Pyez)

script_dir = os.path.dirname(os.path.realpath(__file__))

nr = InitNornir(config_file=f"{script_dir}/config.yml")

# xpath = 'interfaces/interface'
# xml = '<interfaces></interfaces>'
# database = 'committed'

response = nr.run(task=pyez_get_config)

# response is an AggregatedResult, which behaves like a list
# there is a response object for each device in inventory
devices = []
for dev in response:
    print(response[dev].result)
示例#4
0
 def test_register_already_registered_new(self):
     with pytest.raises(PluginAlreadyRegistered):
         ConnectionPluginRegister.register("dummy",
                                           AnotherDummyConnectionPlugin)
示例#5
0
 def test_register_already_registered_same(self):
     ConnectionPluginRegister.register("dummy", DummyConnectionPlugin)
     assert ConnectionPluginRegister.available[
         "dummy"] == DummyConnectionPlugin
示例#6
0
 def test_register_new(self):
     ConnectionPluginRegister.register("new_dummy", DummyConnectionPlugin)
     assert "new_dummy" in ConnectionPluginRegister.available
示例#7
0
 def setup_method(self, method):
     ConnectionPluginRegister.deregister_all()
     ConnectionPluginRegister.register("dummy", DummyConnectionPlugin)
     ConnectionPluginRegister.register("another_dummy",
                                       AnotherDummyConnectionPlugin)