Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Release v0.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
selfuryon committed Nov 4, 2017
2 parents 0c6337e + f502b90 commit 2d413d0
Show file tree
Hide file tree
Showing 20 changed files with 183 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Supports:
---------
* Cisco IOS
* Cisco IOS XE
* Cisco IOS XR
* Cisco ASA
* Cisco NX-OS
* HP Comware (like V1910 too)
Expand Down
15 changes: 11 additions & 4 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ JunOSLikeDevice
~~~~~~~~~~~~~~~

.. autoclass:: JunOSLikeDevice
:members:
:inherited-members:
:members:
:inherited-members:

End classes
-----------
Expand All @@ -65,6 +65,13 @@ CiscoIOS
:members:
:inherited-members:

CiscoIOSXR
~~~~~~~~~~

.. autoclass:: CiscoIOSXR
:members:
:inherited-members:

CiscoASA
~~~~~~~~

Expand Down Expand Up @@ -118,5 +125,5 @@ JuniperJunOS
~~~~~~~~~~~~

.. autoclass:: JuniperJunOS
:members:
:inherited-members:
:members:
:inherited-members:
4 changes: 4 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ IOS example
-----------
.. literalinclude:: ../examples/cisco_ios.py

IOS XR example
--------------
.. literalinclude:: ../examples/cisco_iosxr.py

Fujitsu example
---------------
.. literalinclude:: ../examples/fujitsu_switch.py
Expand Down
3 changes: 2 additions & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ All other classes are the end classes which you can use for working with particu
* :class:`MikrotikRouterOS`
* :class:`CiscoIOS`
* :class:`CiscoIOSXR`
* :class:`CiscoASA`
* :class:`CiscoNXOS`
* :class:`FujitsuSwitch`
* :class:`HPComware`
* :class:`HPComwareLimited`
* :class:`AristaEOS`
* :class:`JunOS`
* :class:`JuniperJunOS`
The particular class selected by parameter *device_type* in :func:`create`
Expand Down
36 changes: 36 additions & 0 deletions examples/cisco_iosxr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import asyncio
import logging

import yaml

import netdev

config_path = 'config.yaml'

logging.basicConfig(level=logging.INFO)
netdev.logger.setLevel(logging.DEBUG)


async def task(param):
async with netdev.create(**param) as iosxr:
# Testing sending simple command
out = await iosxr.send_command("show ver")
print(out)
# Testing sending configuration set
commands = ["interface loopback 0", "description TEST LOOPBACK"]
out = await iosxr.send_config_set(commands, with_commit=True)
print(out)
# Testing sending simple command with long output
out = await iosxr.send_command("show run")
print(out)


async def run():
config = yaml.load(open(config_path, 'r'))
devices = yaml.load(open(config['device_list'], 'r'))
tasks = [task(dev) for dev in devices if dev['device_type'] == 'cisco_ios_xr']
await asyncio.wait(tasks)


loop = asyncio.get_event_loop()
loop.run_until_complete(run())
3 changes: 2 additions & 1 deletion netdev/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .base import BaseDevice
from .cisco import CiscoASA
from .cisco import CiscoIOS
from .cisco import CiscoIOSXR
from .cisco import CiscoNXOS
from .comware_like import ComwareLikeDevice
from .dispatcher import create
Expand All @@ -18,7 +19,7 @@
from .version import __author__, __author_email__, __url__, __version__

__all__ = (
'create', 'platforms', 'DisconnectError', 'logger', 'CiscoASA', 'CiscoIOS', 'CiscoNXOS', 'HPComware',
'create', 'platforms', 'DisconnectError', 'logger', 'CiscoASA', 'CiscoIOS', 'CiscoIOSXR', 'CiscoNXOS', 'HPComware',
'HPComwareLimited', 'FujitsuSwitch', 'MikrotikRouterOS', 'JuniperJunOS', 'JunOSLikeDevice' 'AristaEOS',
'BaseDevice', 'IOSLikeDevice',
'ComwareLikeDevice')
3 changes: 2 additions & 1 deletion netdev/cisco/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .cisco_asa import CiscoASA
from .cisco_ios import CiscoIOS
from .cisco_iosxr import CiscoIOSXR
from .cisco_nxos import CiscoNXOS

__all__ = ['CiscoIOS', 'CiscoASA', 'CiscoNXOS']
__all__ = ['CiscoIOS', 'CiscoIOSXR', 'CiscoASA', 'CiscoNXOS']
41 changes: 41 additions & 0 deletions netdev/cisco/cisco_iosxr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from ..ios_like import IOSLikeDevice
from ..logger import logger


class CiscoIOSXR(IOSLikeDevice):
"""Class for working with Cisco IOS XR"""

_commit_command = 'commit'
"""Command for committing changes"""

_commit_comment_command = 'commit comment {}'
"""Command for committing changes with comment"""

async def send_config_set(self, config_commands=None, with_commit=True, commit_comment='', exit_config_mode=True):
"""
Sending configuration commands to device
By default automatically exits/enters configuration mode.
:param list config_commands: iterable string list with commands for applying to network devices in system view
:param bool with_commit: if true it commit all changes after applying all config_commands
:param string commit_comment: message for configuration commit
:param bool exit_config_mode: If true it will quit from configuration mode automatically
:return: The output of these commands
"""

# Send config commands by IOS Like Device
output = await super().send_config_set(config_commands=config_commands, exit_config_mode=False)
if with_commit:
commit = type(self)._commit_command
if commit_comment:
commit = type(self)._commit_comment_command.format(commit_comment)

self._stdin.write(self._normalize_cmd(commit))
output += await self._read_until_prompt()

if exit_config_mode:
output += await self.exit_config_mode()

output = self._normalize_linefeeds(output)
logger.debug("Host {}: Config commands output: {}".format(self._host, repr(output)))
return output
4 changes: 3 additions & 1 deletion netdev/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .arista import AristaEOS
from .cisco import CiscoASA
from .cisco import CiscoIOS
from .cisco import CiscoIOSXR
from .cisco import CiscoNXOS
from .fujitsu import FujitsuSwitch
from .hp import HPComware
Expand All @@ -15,7 +16,8 @@
# The keys of this dictionary are the supported device_types
CLASS_MAPPER = {
'cisco_ios': CiscoIOS,
'cisco_xe': CiscoIOS,
'cisco_ios_xe': CiscoIOS,
'cisco_ios_xr': CiscoIOSXR,
'cisco_asa': CiscoASA,
'cisco_nxos': CiscoNXOS,
'hp_comware': HPComware,
Expand Down
2 changes: 1 addition & 1 deletion netdev/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" Netdev Version information
"""

__version__ = '0.7.0'
__version__ = '0.7.1'
__author__ = 'Yakovlev Sergey'
__author_email__ = 'selfuryon@gmail.com'
__url__ = 'http://netdev.readthedocs.io/'
2 changes: 1 addition & 1 deletion tests/test_arista_eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import netdev

logging.basicConfig(filename='tests/unittest.log', level=logging.DEBUG)
logging.basicConfig(filename='unittest.log', level=logging.DEBUG)
config_path = 'config.yaml'


Expand Down
2 changes: 1 addition & 1 deletion tests/test_cisco_asa.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import netdev

logging.basicConfig(filename='tests/unittest.log', level=logging.DEBUG)
logging.basicConfig(filename='unittest.log', level=logging.DEBUG)
config_path = 'config.yaml'


Expand Down
2 changes: 1 addition & 1 deletion tests/test_cisco_ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import netdev

logging.basicConfig(filename='tests/unittest.log', level=logging.DEBUG)
logging.basicConfig(filename='unittest.log', level=logging.DEBUG)
config_path = 'config.yaml'


Expand Down
71 changes: 71 additions & 0 deletions tests/test_cisco_iosxr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import asyncio
import logging
import unittest

import yaml

import netdev

logging.basicConfig(filename='unittest.log', level=logging.DEBUG)
config_path = 'config.yaml'


class TestIOSXR(unittest.TestCase):
@staticmethod
def load_credits():
with open(config_path, 'r') as conf:
config = yaml.load(conf)
with open(config['device_list'], 'r') as devs:
devices = yaml.load(devs)
params = [p for p in devices if p['device_type'] == 'cisco_ios_xr']
return params

def setUp(self):
self.loop = asyncio.new_event_loop()
self.loop.set_debug(False)
asyncio.set_event_loop(self.loop)
self.devices = self.load_credits()
self.assertFalse(len(self.devices) == 0)

def test_show_run_hostname(self):
async def task():
for dev in self.devices:
async with netdev.create(**dev) as iosxr:
out = await iosxr.send_command('show run | i hostname')
self.assertIn("hostname", out)

self.loop.run_until_complete(task())

def test_show_several_commands(self):
async def task():
for dev in self.devices:
async with netdev.create(**dev) as iosxr:
commands = ["dir", "show ver", "show run", "show ssh"]
for cmd in commands:
out = await iosxr.send_command(cmd, strip_command=False)
self.assertIn(cmd, out)

self.loop.run_until_complete(task())

def test_config_set(self):
async def task():
for dev in self.devices:
async with netdev.create(**dev) as iosxr:
commands = ["line con 0", "exit"]
out = await iosxr.send_config_set(commands)
self.assertIn("line con 0", out)
self.assertIn("exit", out)

self.loop.run_until_complete(task())

def test_interactive_commands(self):
async def task():
for dev in self.devices:
async with netdev.create(**dev) as ios:
out = await ios.send_command("conf", strip_command=False)
out += await ios.send_command("hostname test", strip_command=False)
out += await ios.send_command("exit", pattern=r'Uncommitted changes found', strip_command=False)
out += await ios.send_command("no", strip_command=False)
self.assertIn('commit them before exiting', out)

self.loop.run_until_complete(task())
2 changes: 1 addition & 1 deletion tests/test_cisco_nxos.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import netdev

logging.basicConfig(filename='tests/unittest.log', level=logging.DEBUG)
logging.basicConfig(filename='unittest.log', level=logging.DEBUG)
netdev.logger.setLevel(logging.DEBUG)
config_path = 'config.yaml'

Expand Down
2 changes: 1 addition & 1 deletion tests/test_fujitsu_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import netdev

logging.basicConfig(filename='tests/unittest.log', level=logging.DEBUG)
logging.basicConfig(filename='unittest.log', level=logging.DEBUG)
config_path = 'config.yaml'


Expand Down
2 changes: 1 addition & 1 deletion tests/test_hp_comware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import netdev

logging.basicConfig(filename='tests/unittest.log', level=logging.DEBUG)
logging.basicConfig(filename='unittest.log', level=logging.DEBUG)
config_path = 'config.yaml'


Expand Down
2 changes: 1 addition & 1 deletion tests/test_hp_comware_limited.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import netdev

logging.basicConfig(filename='tests/unittest.log', level=logging.DEBUG)
logging.basicConfig(filename='unittest.log', level=logging.DEBUG)
config_path = 'config.yaml'


Expand Down
2 changes: 1 addition & 1 deletion tests/test_juniper_junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import netdev

logging.basicConfig(filename='tests/unittest.log', level=logging.DEBUG)
logging.basicConfig(filename='unittest.log', level=logging.DEBUG)
config_path = 'config.yaml'


Expand Down
2 changes: 1 addition & 1 deletion tests/test_mikrotik_routeros.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import netdev

logging.basicConfig(filename='tests/unittest.log', level=logging.DEBUG)
logging.basicConfig(filename='unittest.log', level=logging.DEBUG)
config_path = 'config.yaml'


Expand Down

0 comments on commit 2d413d0

Please sign in to comment.