The first glimpse of Netmiko

Source: Internet
Author: User

Paramiko and Pexpect were skipped in their notes.

Because, they can all be replaced by Netmiko, do not want to waste too much time on them

Netmiko

Overall is still very simple, because the more humane

  • Create Conn
  1 #!/usr/bin/env python  2  3  fromNetmikoImportConnecthandler4  5Pynet1 = {6 ' Device_type ':' Cisco_ios ',7 ' IP ':' 184.105.xx.xx ',8 ' username ':' Pyclass ',9 ' Password ':' ****** ',Ten} One  AConn1 = Connecthandler (**PYNET1) -OUTP = Conn1.send_command ("Show Run | inc Logging ") - PrintOutp

It's just so easy to output.

Be aware of the two asterisks in the connecthandler brackets, which are marked with no less

  • Use Dir () to explore a new library
>>>Dir (Netmiko) [' Connecthandler ',' Filetransfer ',' Netmikoauthenticationexception ',' Netmikotimeoutexception ',' Netmikoautherror ',' Netmikotimeouterror ',' Scpconn ',' __all__ ',' __builtins__ ',' __doc__ ',' __file__ ',' __name__ ',' __package__ ',' __path__ ',' __version__ ',' A10 ',' Alcatel ',' Arista ',' Avaya ',' Base_connection ',' brocade ',' Cisco ',' dell ',' Enterasys ',' Extreme ',' f5 ',' Fortinet ',' HP ',' Huawei ',' Juniper ',' Linux ',' Netmiko_globals ',' OvS ',' Paloalto ',' platforms ',' Quanta ',' Scp_handler ',' Ssh_connection ',' Ssh_dispatcher ',' Ssh_exception ']>>>
>>>Dir (Netmiko. Connecthandler) [' __call__ ',' __class__ ',' __closure__ ',' __code__ ',' __defaults__ ',' __delattr__ ',' __dict__ ',' __doc__ ',' __format__ ',' __get__ ',' __getattribute__ ',' __globals__ ',' __hash__ ',' __init__ ',' __module__ ',' __name__ ',' __new__ ',' __reduce__ ',' __reduce_ex__ ',' __repr__ ',' __setattr__ ',' __sizeof__ ',' __str__ ',' __subclasshook__ ',' Func_closure ',' Func_code ',' Func_defaults ',' Func_dict ',' Func_doc ',' Func_globals ',' Func_name ']>>>>>>
  • Find_prompt ()
 print conn1.find_prompt()
  • Send_config_set ()
    The command is in the form of an array pass in.
  18  config_commands = [ ' logging buffered 19999 ' ] 19  OUTP = Conn1.send_ Config_set (config_commands) 20  print  OUTP  
  • Connecting Juniper Devices

Take the SRX as an example

  +  ASRX = { at ' Device_type ':' Juniper ', - ' IP ':' 184.105.xx.xx ', - ' username ':' Pyclass ', - ' Port ': A, - ' Password ':' ****** ', -} in  -CONN2 = Connecthandler (**SRX) toOUTP = Conn2.send_command ("Show Arp") + PrintOutp -  the PrintDir (conn2) * PrintDir (conn1)

Can see CONN1 conn2 These two connection namespaces are not quite the same

Take a look at Config_mode () and Check_config_mode ()

  • Config_mode () and Check_config_mode ()
    Check_config_mode () returns a Boolean value, true to indicate that the config mode is now

Config_mode () Enter Cofig mode
Exit_config_mode Exit Config mode

  • Commit ()

This is Juniper's commit.

 conn2.commit()
?

The first glimpse of Netmiko

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.