Giter VIP home page Giter VIP logo

pynet's Introduction

pynet's People

Contributors

carlmontanari avatar d3nisko avatar ktbyers avatar wdennis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pynet's Issues

pynet/learnpy_ecourse/class1/ex1_ex2_ipv6_split.py solution

Hi Kirk,
In the solution for this assignment, when I use the join method, the result is not as I expect it to be. What am I missing?

a
'FE80:0000:0000:0000:0101:A3EF:EE1E:1719'
a.split(":")
['FE80', '0000', '0000', '0000', '0101', 'A3EF', 'EE1E', '1719']
":".join(a)
'F:E:8:0:::0:0:0:0:::0:0:0:0:::0:0:0:0:::0:1:0:1:::A:3:E:F:::E:E:1:E:::1:7:1:9'

nornir_utilities is giving error

Hi Kirk,

I was looking code at "pynet/nornir/os_upgrade/part1/netmiko_file_transfer.py" and i am getting error on below line on my Windows Machine.
from nornir_utilities import nornir_set_creds, std_print

Is there any issue with nornir_utilities?

image

SNMPv3 on linux(Ubuntu 16.04) with Python3 - script "snmp_helper.py"

Hi Kirk,

I tried to run this script "snmp_helper.py" in https://github.com/ktbyers/pynet/tree/master/snmp But I import error. Your script says "Requires the pysnmp4 library" but I see it is already there.

Do you have any idea what is missing?

mathew@Tools-SRV:~$ python2
Python 2.7.12 (default, Dec  4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from snmp_helper import snmp_get_oid_v3,snmp_extract
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named snmp_helper
>>> quit()
mathew@Tools-SRV:~$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from snmp_helper import snmp_get_oid,snmp_extract
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'snmp_helper'
>>> 

root@Tools-SRV:/home/mathew# pip3 install pysnmp
Requirement already satisfied: pysnmp in /usr/local/lib/python3.5/dist-packages (4.3.9)
Requirement already satisfied: pycryptodome in /usr/local/lib/python3.5/dist-packages (from pysnmp) (3.4.7)
Requirement already satisfied: pysmi in /usr/local/lib/python3.5/dist-packages (from pysnmp) (0.0.7)
Requirement already satisfied: pyasn1>=0.2.3 in /usr/local/lib/python3.5/dist-packages (from pysnmp) (0.4.2)
Requirement already satisfied: ply in /usr/local/lib/python3.5/dist-packages (from pysmi->pysnmp) (3.9)
root@Tools-SRV:/home/mathew# pip3 install snmp_helper
Collecting snmp_helper
  Could not find a version that satisfies the requirement snmp_helper (from versions: )
No matching distribution found for snmp_helper
root@Tools-SRV:/home/mathew#

Timeout while Transfering NXOS Bin file!!

Hi Kirk,
The file transfer of a nxos image (e.g.: I7(6).bin) takes longer than expected and it fails with following error:

paramiko.ssh_exception.SSHException: Key-exchange timed out waiting for key negotiation

Below is complete error :

complete_error.txt

Also are you aware of a way to track the progress of the file transfer as a background task, and show them the UI in django?

How do I go into enable mode for 'netmiko_file_transfer'?

I am not able to get the file transfer working with a user that doesn't have privilege 15. I set the "secret: password" in the groups.yaml file and tested that it works on a 'netmiko_send_config'.
I am new to programming but tried a few things but still no luck.

First attempt

from nornir import InitNornir
from nornir.plugins.tasks.networking import netmiko_file_transfer, netmiko_send_config, netmiko_send_command
from nornir_utilities import nornir_set_creds, std_print
import time

# Initialize Nornir object using default "SimpleInventory" plugin
nr = InitNornir()
# nornir_set_creds(nr)
host = nr.filter(hostname='172.30.1.1')
test_file = 'test_xfer.txt'

startTime = time.time()

result = host.run(task=netmiko_file_transfer,
                  source_file=test_file,
                  dest_file=test_file,
                  direction='put',
                  )

endTime = time.time()

print(f"Total time : {endTime - startTime} \n")
std_print(result)

First attempt result

\venv\lib\site-packages\netmiko\cisco_base_connection.py", line 186, in _autodetect_fs
    raise ValueError("Must be in enable mode to auto-detect the file-system.")
ValueError: Must be in enable mode to auto-detect the file-system.

Second attempt

from nornir import InitNornir
from nornir.plugins.tasks.networking import netmiko_file_transfer, netmiko_send_config, netmiko_send_command
from nornir_utilities import nornir_set_creds, std_print
import time

# Initialize Nornir object using default "SimpleInventory" plugin
nr = InitNornir()
# nornir_set_creds(nr)
host = nr.filter(hostname='172.30.1.1')
test_file = 'test_xfer.txt'

startTime = time.time()


def testup(task):
    task.run(task=netmiko_send_command,
             enable=True,
             command_string="sh ip int b"
             )
    task.run(task=netmiko_file_transfer,
             source_file=test_file,
             dest_file=test_file,
             direction='put',
             )


result = host.run(task=testup)
endTime = time.time()
print(f"Total time : {endTime - startTime} \n")
std_print(result)

Second attempt result

\NornirGudeTest\venv\lib\site-packages\scp.py", line 363, in _recv_confirm
    raise SCPException(asunicode(msg[1:]))
scp.SCPException: Privilege denied.

I also tried editing the netmiko_file_transfer.py by adding the line below. which result in a Privilege denied.

net_connect.enable()

Image Not Getting Copied for Arista 7010T switches!

Hi Kirk,

When i use the netmiko_file_transfer module, I am getting the following error:

OSError: Search pattern never detected in send_command_expect: [\$#]

Nornir Code:

nr_arista = nr.filter(F(hostname__in=device_urlArray))
nornir_set_creds(nr_arista ,fabricList,device_urlArray)
source_file = project_path + "/media/" + BinFile
result = nr_arista.run(
task=netmiko_file_transfer,
source_file=source_file,
dest_file=BinFile,
direction='put',
num_workers=len(NodeSwitch_tmp),
)

Python Script : How can I connect to Linux Jump server using RSA Token with ssh

Hi Eric ,

I read your book Python network automation hence thought to get an help on below issue.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
I am new in script world and have a requirement to automate network device. Please refer below connection and advise suitable scripts.
Linux(Machine)----->>>>>>>(RSA Token enabled)Linux(Jump Server)------>>>>>Device(Cisco)
Below is the code which gives me error.
from netmiko import ConnectHandler
RSA_PASSCODE = raw_input("Enter RSA passcode:")
Jump_server = {
'device_type': 'linux',
'ip': '10.10.10.227',
'username': 'cisco',
'password': 'cisco',
'passcode':'RSA_PASSCODE'
}
net_connect = ConnectHandler(**Jump_server)
net_connect.find_prompt()
output = net_connect.send_command("ls -l)
print output

No result returned from netmiko_send_command

I am following the post "Using Nornir for OS Upgrades (Part 2)" to upgrade a switch but at the section of the code to verify the boot variable, I don't get a print out on screen. I tried a couple of things to troubleshoot but haven't figured out the issue. one of my problems is I don't know how to debug :(. As for the testing I've done, I tested that section of the code by itself and it worked fine. i also move it above the set_boot_var task and that worked. so it seems to me something in the set_boot_var function is causing netmiko_send_command to not return a value. interestingly even though it doesn't return a value it still performs the command. i am using the script "nornir_os_upgrade.py" with few adjustments.

def main():
    print("************** Starting File Transfer *********************")
    # Initialize Nornir object using default "SimpleInventory" plugin
    nr = InitNornir().filter(hostname="172.30.14.5")

    result = nr.run(
        task=os_upgrade,
        num_workers=20,
    )
    std_print(result)

    # Filter to only a single device
    nr_ios = nr.filter(hostname="172.30.14.5")

    aggr_result = nr_ios.run(task=set_boot_var)

    # If setting the boot variable failed (assumes single device at this point)
    for hostname, val in aggr_result.items():
        if val[0].result is False:
            sys.exit("Setting the boot variable failed")
    

    # Verify the boot variable
    result = nr_ios.run(
        task=netmiko_send_command,
        command_string= f'send log "configured from Nornir {time.time()}"', 
        num_workers=20,
    )
    print(result) # print result to see what was returned
    std_print(result) #I dont get a result back
    continue_func()

Result


GudeTest2960-X

True


GudeTest2960-X


Any help with this will be appreciated. Thanks.

Python2/3 - ImportError: No module named snmp_helper

Hi,

I tried this SNMPv3 part and I get the below import error.

Any idea what is the python module missing in my system?
I use Ubuntu 16.04.

ython 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

from snmp_helper import snmp_get_oid_v3,snmp_extract
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named 'snmp_helper'

Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.

from snmp_helper import snmp_get_oid_v3,snmp_extract
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named snmp_helper

Mathew

Nornir support on windows 10?

Hi Kirk,

I read your article "Using Nornir for OS Upgrades (Part 1)" and it is really nice article.
During the reading, i have couple of question. I would appreciate if you can help me with these queries I am using Windows 10 machine.

  1. Where should i keep hosts.yaml and groups.yaml on windows path?
  2. Nornir is supported fully on windows?

I'm runing nornir 2.0 in a bad way that I couldn't identify the issue, need help.

Hi Kirk,,

I followed your document of "Introduction to nornir' and facing the issues on nornir with windows OS.

The debugger logs :

c:\users\tkmamja.pycharmce2019.1\venv\scripts\lpthw\test\ktbyers\hey\heyhey.py(1)()
-> from nornir import InitNornir
(Pdb) n

c:\users\tkmamja.pycharmce2019.1\venv\scripts\lpthw\test\ktbyers\hey\heyhey.py(3)()
-> nr = InitNornir()
(Pdb) p nr
*** NameError: name 'nr' is not defined
(Pdb) p
*** SyntaxError: unexpected EOF while parsing
(Pdb) p nr
*** NameError: name 'nr' is not defined
(Pdb) n
ruamel.yaml.scanner.ScannerError: mapping values are not allowed in this context
in "hosts.yaml", line 2, column 5
c:\users\tkmamja.pycharmce2019.1\venv\scripts\lpthw\test\ktbyers\hey\heyhey.py(3)()
-> nr = InitNornir()
(Pdb) n
--Return--
c:\users\tkmamja.pycharmce2019.1\venv\scripts\lpthw\test\ktbyers\hey\heyhey.py(3)()->None
-> nr = InitNornir()
(Pdb) n
ruamel.yaml.scanner.ScannerError: mapping values are not allowed in this context
in "hosts.yaml", line 2, column 5
(1)()->None
(Pdb) p nr.inventory.hosts
*** NameError: name 'nr' is not defined
(Pdb) exit

When I ran the program I get this :

$ python heyhey.py
Traceback (most recent call last):
File "heyhey.py", line 5, in
nr = InitNornir()
File "C:\Users\TKMAMJA.PyCharmCE2019.1\venv\lib\site-packages\nornir\init_nornir.py", line 78, in InitNornir
**conf.inventory.options,
File "C:\Users\TKMAMJA.PyCharmCE2019.1\venv\lib\site-packages\nornir\core\deserializer\inventory.py", line 129, in deserialize
deserialized = cls(*args, **kwargs)
File "C:\Users\TKMAMJA.PyCharmCE2019.1\venv\lib\site-packages\nornir\plugins\inventory\simple.py", line 55, in init
super().init(hosts=hosts, groups=groups, defaults=defaults, *args, **kwargs)
File "C:\Users\TKMAMJA.PyCharmCE2019.1\venv\lib\site-packages\pydantic\main.py", line 142, in init
self.setstate(self._process_values(data))
File "C:\Users\TKMAMJA.PyCharmCE2019.1\venv\lib\site-packages\pydantic\main.py", line 312, in _process_values
return validate_model(self, input_data)
File "C:\Users\TKMAMJA.PyCharmCE2019.1\venv\lib\site-packages\pydantic\main.py", line 474, in validate_model
raise ValidationError(errors)
pydantic.error_wrappers.ValidationError: 4 validation errors
hosts -> rtr1 -> nornir_host
extra fields not permitted (type=value_error.extra)
groups -> defaults -> nornir_password
extra fields not permitted (type=value_error.extra)
groups -> defaults -> nornir_username
extra fields not permitted (type=value_error.extra)
groups -> cisco_ios -> nornir_nos
extra fields not permitted (type=value_error.extra)

What am I doing wrong here?????????? Could be great help.

AWeber click tracking is disabled

Make sure this is disabled on all of the pynet and pynet-cl-beg list follow-up series emails. I am pretty sure that I already did this for pynet-cl-beg, but should double check it.

How to snmp v1

Can someone help me with example of using this with snmp v1 ? Default v2 works fine.
I have device that supports only v1.

Issue while installing requirements.txt

I am getting an error while installing packages from requirements.txt. The package I am having issue with is black.

  Downloading https://ci-repo.aexp.com/repository/python-proxy-internal/packages/2d/43/64205493cfb4c8e1720208d73502a121ace2a195cd4d1d49bd7470e4fd92/black-18.6b4.tar.gz (141kB)
    100% |████████████████████████████████| 143kB 1.8MB/s 
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-LVunnl/black/setup.py", line 13
        def get_long_description() -> str:
                                   ^
    SyntaxError: invalid syntax```

Any help is appreciated. Thanks!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.