Ejemplo n.º 1
0
def main():
    nr = InitNornir(config_file="nornir_config.yaml", core={'num_workers': 10})
    # register the ncclient connection plugin so that host-connections have access to it
    Connections.register("ncclient", Ncclient)

    nr2 = nr.filter(name='sr1.lab')

    print_title("Loading Service Intents")
    results = nr.run(task=load_service_intents,
                     name="Load Service Intents",
                     directory="intent2/services/eline/vars")
    print_result(results, vars="stdout")

    print_title("Updating inventory host data (partial)")
    resources_to_load = set()
    for _, host in nr.inventory.hosts.items():
        resources_needed = host.get("rsc_to_populate", None)
        if resources_needed:
            for rsc in resources_needed:
                resources_to_load.add(rsc)
    results = nr.run(task=download_configs,
                     name="Load relevant configs into Inventory",
                     resources=resources_to_load)
    print_result(results, vars="stdout")

    print_title("Ensuring Service Intents")
    results = nr.run(task=ensure_services, intent_dir="intent2/services")
    print_result(results, vars="diff")
Ejemplo n.º 2
0
 def __init__(
     self, name: str, defaults: Optional[Defaults] = None, **kwargs
 ) -> None:
     self.name = name
     self.defaults = defaults or Defaults()
     self.connections: Connections = Connections()
     super().__init__(**kwargs)
Ejemplo n.º 3
0
def register() -> None:
    """
    Register scrapli connection plugin to nornir

    Args:
        N/A

    Returns:
        N/A

    Raises:
        N/A

    """
    if CONNECTION_NAME not in Connections.available:
        Connections.register(CONNECTION_NAME, Scrapli)
Ejemplo n.º 4
0
def main():
    nr = InitNornir(
        config_file="nornir_config.yaml",
        core={
            'num_workers':10
        }
    )
    # register the ncclient connection plugin so that host-connections have access to it
    Connections.register("ncclient", Ncclient)

    nr2 = nr.filter(name='sr1.lab')

    results = nr.run(task=validate_intent, intent_dir="intents")
#    results = nr2.run(task=validate_intent, intent_dir="intents")

    print_title("Runbook to push intent")
    print_result(results, vars = "diff")
Ejemplo n.º 5
0
def register_connections():
    """
    register nornir connection plugins
    """
    from nornir.core.connections import Connections
    from netnir.core.connection.netmiko import Netmiko
    from netnir.core.connection.netconf import Netconf

    Connections.deregister_all()
    Connections.register(name="netconf", plugin=Netconf)
    Connections.register(name="netmiko", plugin=Netmiko)
Ejemplo n.º 6
0
 def setup_class(cls):
     Connections.deregister_all()
     Connections.register("dummy", DummyConnectionPlugin)
     Connections.register("dummy2", DummyConnectionPlugin)
     Connections.register("dummy_no_overrides", DummyConnectionPlugin)
Ejemplo n.º 7
0
 def test_nonexistent_plugin(self):
     with pytest.raises(ConnectionPluginNotRegistered):
         Connections.get_plugin("nonexistent_dummy")
Ejemplo n.º 8
0
 def test_get_plugin(self):
     assert Connections.get_plugin("dummy") == DummyConnectionPlugin
     assert Connections.get_plugin(
         "another_dummy") == AnotherDummyConnectionPlugin
     assert len(Connections.available) == 2
Ejemplo n.º 9
0
 def test_deregister_all(self):
     Connections.deregister_all()
     assert Connections.available == {}
Ejemplo n.º 10
0
 def test_deregister_existing(self):
     Connections.deregister("dummy")
     assert len(Connections.available) == 1
     assert "dummy" not in Connections.available
Ejemplo n.º 11
0
 def test_register_already_registered_new(self):
     with pytest.raises(ConnectionPluginAlreadyRegistered):
         Connections.register("dummy", AnotherDummyConnectionPlugin)
Ejemplo n.º 12
0
 def test_register_already_registered_same(self):
     Connections.register("dummy", DummyConnectionPlugin)
     assert Connections.available["dummy"] == DummyConnectionPlugin
Ejemplo n.º 13
0
 def test_register_new(self):
     Connections.register("new_dummy", DummyConnectionPlugin)
     assert "new_dummy" in Connections.available
Ejemplo n.º 14
0
 def teardown_method(self, method):
     Connections.deregister_all()
     register_default_connection_plugins()
Ejemplo n.º 15
0
 def setup_method(self, method):
     Connections.deregister_all()
     Connections.register("dummy", DummyConnectionPlugin)
     Connections.register("another_dummy", AnotherDummyConnectionPlugin)
Ejemplo n.º 16
0
def register_default_connection_plugins() -> None:
    Connections.register("napalm", Napalm)
    Connections.register("netmiko", Netmiko)
    Connections.register("paramiko", Paramiko)
Ejemplo n.º 17
0
 def test_deregister_nonexistent(self):
     with pytest.raises(ConnectionPluginNotRegistered):
         Connections.deregister("nonexistent_dummy")