question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Specific attributes for netmiko in nornir inventory or call enable()

See original GitHub issue

Hello,

I have a lot of old Procurve switches only with telnet, where disable paging and enable mode doesn’t work in automatic way.

Reading a similar post, I could solve it using the next lines:

con = netmiko.ConnectHandler(
    device_type="hp_procurve_telnet" 
    ip=ip, username=username, 
    password=password, 
    secret=password
)
con.enable(default_username=user)
con.send_command ("terminal len 1000") //for disable paging
r = con.send_command (command)
print (r)

Now, I would like to use it with nornir (I am learning it yet). I guess if I can overwrite default_username for enable function, it is done (from nornir inventory, it would be perfect).

If it is not possible with inventory attributes, how can send it in the call to do something similar to next line? target_host.run (task=netmiko_send_command, command_string=command, enable=True, default_username=user)

At the same time, is there a doc with all possible netmiko attributes for nornir inventory?

Thanks.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
narcotico-gcommented, Apr 2, 2020

Summarizing,

I had 2 problems:

  1. It was hard to find how use attributes in nornir (basically the next lines). When I found them, no problem, working fine. connection_options: netmiko: extras: {"secret": xxx}

  2. I need to change enable default_username with these devices (it is not “manager”, it is the same as I use for login with radius authentication). The problem is that base_connection has no this option or param and I can not change it. So I overwrite netmiko_send_command and it is working fine. However I do not like to modify original files for next updates. In this case I can not see any issue or incompatibility, it is simple. I would like to take a look and you consider add it.

from typing import Any

from nornir.core.task import Result, Task

def netmiko_send_command(
    task: Task,
    command_string: str,
    use_timing: bool = False,
    enable: bool = False,
    default_username = 0,
    **kwargs: Any
) -> Result:
    """
    Execute Netmiko send_command method (or send_command_timing)

    Arguments:
        command_string: Command to execute on the remote network device.
        use_timing: Set to True to switch to send_command_timing method.
        enable: Set to True to force Netmiko .enable() call.
        kwargs: Additional arguments to pass to send_command method.

    Returns:
        Result object with the following attributes set:
          * result: Result of the show command (generally a string, but depends on use of TextFSM).
    """
    net_connect = task.host.get_connection("netmiko", task.nornir.config)
    if enable:
        if default_username:
          net_connect.enable (default_username=default_username)
        else:
          net_connect.enable()
    if use_timing:
        result = net_connect.send_command_timing(command_string, **kwargs)
    else:
        result = net_connect.send_command(command_string, **kwargs)
    return Result(host=task.host, result=result)

Explain of my procurve scenarios (all of them with radius authentication):

  1. Procurve 2524 and 2512 (only support ssh1, so I use with telnet). These devices need authenticate 2 times (login + enable). With radius authentication, enable user and password are the same in my case (these are I called old Procurve before) and not default user “manager”.

At the same time they use different command for disable paging. Do you have a method for testing a new device type for adding to Netmiko? or with this minimal difference, do you consider better another choice like another param? It would be similar at above case.

  1. All other models are working fine with telnet and ssh2. They have configured a command to enter in privilege mode after login (this command does not exist in the 2524 and 2512 models), so I do not need to use default_username in these cases.

Thanks.

0reactions
ktbyerscommented, Apr 27, 2020

I am going to close this–just re-open if there is some pending action here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nornir 101 - Network Automation - Packet Coders
The Nornir inventory structure consists of: hosts - individual hosts and any related attributes; groups - group definitions and any related ...
Read more >
4. Nornir Netmiko send command Configuration Example
Returns: Result object with the following attributes set: * result: Result of the show command (generally a string, but depends on use of...
Read more >
Connections — nornir 2.5.0 documentation
This plugin connects to the device using the Netmiko driver and sets the relevant connection. Inventory: extras: maps to argument passed to ConnectHandler...
Read more >
Nornir using an Ansible Inventory (Part2)
We'll also use Nornir plus NAPALM to retrieve and save the current ... a checkpoint file instead of simply using the get_config() method....
Read more >
Exploring Nornir, the Python Automation Framework
As you can see from the initial test, the username value can be accessed either as an attribute or as a key in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found