Skip to Main Content
Python Network Programming
book

Python Network Programming

by Abhishek Ratan, Eric Chou, Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker
January 2019
Beginner to intermediate content levelBeginner to intermediate
776 pages
19h 58m
English
Packt Publishing
Content preview from Python Network Programming

Pyeapi examples

Now, we are ready to take a look around the usage. Let's start by connecting to the EOS node by creating an object in the interactive Python shell:

Python 3.5.2 (default, Nov 17 2016, 17:05:23)[GCC 5.4.0 20160609] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import pyeapi>>> arista1 = pyeapi.connect_to('Arista1')

We can execute show commands to the node and receive the output:

>>> import pprint>>> pprint.pprint(arista1.enable('show hostname'))[{'command': 'show hostname', 'encoding': 'json', 'result': {'fqdn': 'arista1', 'hostname': 'arista1'}}]

The configuration field can be either a single command or a list of commands using the config() method:

>>> arista1.config('hostname arista1-new') ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Network Programming for Network Engineers (Python 3)

Python Network Programming for Network Engineers (Python 3)

David Bombal

Publisher Resources

ISBN: 9781788835466Supplemental Content