This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
183 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters