Network module cleanup (#17334)

* Clean up EOS, IOS, IOS-XR, Junos, NX-OS, and OpenSwitch

* Cleanup net* files

* Re-add NetworkModule import to network module_utils files

This will trick modules into importing code from module_utils code, thus
including it in the final Ansiballz zipfile.

* Give asa a look over, too
pull/17420/head
Nathaniel Case 8 years ago committed by GitHub
parent 9fe4308670
commit 972dc3fc97

@ -29,7 +29,7 @@
import re import re
from ansible.module_utils.network import NetworkModule, NetworkError from ansible.module_utils.network import NetworkError, NetworkModule
from ansible.module_utils.network import add_argument, register_transport, to_list from ansible.module_utils.network import add_argument, register_transport, to_list
from ansible.module_utils.shell import CliBase from ansible.module_utils.shell import CliBase
from ansible.module_utils.netcli import Command from ansible.module_utils.netcli import Command
@ -72,11 +72,6 @@ class Cli(CliBase):
cmd = Command('enable', prompt=self.NET_PASSWD_RE, response=passwd) cmd = Command('enable', prompt=self.NET_PASSWD_RE, response=passwd)
self.execute([cmd, 'no terminal pager']) self.execute([cmd, 'no terminal pager'])
### Cli methods ###
def run_commands(self, commands):
return self.execute(to_list(commands))
def change_context(self, params, **kwargs): def change_context(self, params, **kwargs):
context = params['context'] context = params['context']
if context == 'system': if context == 'system':

@ -28,11 +28,9 @@
import re import re
from ansible.module_utils.basic import json, get_exception from ansible.module_utils.basic import json
from ansible.module_utils.network import NetworkModule, NetworkError, ModuleStub from ansible.module_utils.network import ModuleStub, NetworkError, NetworkModule
from ansible.module_utils.network import add_argument, register_transport, to_list from ansible.module_utils.network import add_argument, register_transport, to_list
from ansible.module_utils.netcfg import NetworkConfig
from ansible.module_utils.netcli import Command
from ansible.module_utils.shell import CliBase from ansible.module_utils.shell import CliBase
from ansible.module_utils.urls import fetch_url, url_argument_spec from ansible.module_utils.urls import fetch_url, url_argument_spec
@ -41,9 +39,10 @@ EAPI_FORMATS = ['json', 'text']
add_argument('use_ssl', dict(default=True, type='bool')) add_argument('use_ssl', dict(default=True, type='bool'))
add_argument('validate_certs', dict(default=True, type='bool')) add_argument('validate_certs', dict(default=True, type='bool'))
class EosConfigMixin(object): class EosConfigMixin(object):
### implementation of netcfg.Config ### ### Config methods ###
def configure(self, commands, **kwargs): def configure(self, commands, **kwargs):
cmds = ['configure terminal'] cmds = ['configure terminal']
@ -93,8 +92,6 @@ class EosConfigMixin(object):
def save_config(self): def save_config(self):
self.execute(['copy running-config startup-config']) self.execute(['copy running-config startup-config'])
### end netcfg.Config ###
def diff_config(self, session): def diff_config(self, session):
commands = ['configure session %s' % session, commands = ['configure session %s' % session,
'show session-config diffs', 'show session-config diffs',
@ -166,24 +163,32 @@ class Eapi(EosConfigMixin):
else: else:
self.enable = 'enable' self.enable = 'enable'
### Command methods ###
def execute(self, commands, output='json', **kwargs):
"""Send commands to the device.
"""
if self.url is None:
raise NetworkError('Not connected to endpoint.')
### implementation of network.Cli ### if self.enable is not None:
commands.insert(0, self.enable)
def run_commands(self, commands): def run_commands(self, commands, **kwargs):
output = None output = None
cmds = list() cmds = list()
responses = list() responses = list()
for cmd in commands: for cmd in commands:
if output and output != cmd.output: if output and output != cmd.output:
responses.extend(self.execute(cmds, format=output)) responses.extend(self.execute(cmds, output=output))
cmds = list() cmds = list()
output = cmd.output output = cmd.output
cmds.append(str(cmd)) cmds.append(str(cmd))
if cmds: if cmds:
responses.extend(self.execute(cmds, format=output)) responses.extend(self.execute(cmds, output=output))
for index, cmd in enumerate(commands): for index, cmd in enumerate(commands):
if cmd.output == 'text': if cmd.output == 'text':
@ -191,15 +196,6 @@ class Eapi(EosConfigMixin):
return responses return responses
def execute(self, commands, format='json', **kwargs):
"""Send commands to the device.
"""
if self.url is None:
raise NetworkError('Not connected to endpoint.')
if self.enable is not None:
commands.insert(0, self.enable)
data = self._get_body(commands, format) data = self._get_body(commands, format)
data = json.dumps(data) data = json.dumps(data)
@ -230,8 +226,10 @@ class Eapi(EosConfigMixin):
return response['result'] return response['result']
### Config methods ###
def get_config(self, **kwargs): def get_config(self, **kwargs):
return self.execute(['show running-config'], format='text')[0]['output'] return self.execute(['show running-config'], output='text')[0]['output']
Eapi = register_transport('eapi')(Eapi) Eapi = register_transport('eapi')(Eapi)
@ -265,7 +263,7 @@ class Cli(EosConfigMixin, CliBase):
passwd = params['auth_pass'] passwd = params['auth_pass']
self.execute(Command('enable', prompt=self.NET_PASSWD_RE, response=passwd)) self.execute(Command('enable', prompt=self.NET_PASSWD_RE, response=passwd))
### implementation of network.Cli ### ### Command methods ###
def run_commands(self, commands): def run_commands(self, commands):
"""execute the ordered set of commands on the remote host """execute the ordered set of commands on the remote host
@ -300,6 +298,7 @@ def prepare_config(commands):
commands.append('end') commands.append('end')
return commands return commands
def prepare_commands(commands): def prepare_commands(commands):
""" transforms a list of Command objects to dict """ transforms a list of Command objects to dict

@ -18,78 +18,19 @@
# #
import re import re
import urlparse
from ansible.module_utils.basic import json from ansible.module_utils.basic import json
from ansible.module_utils.network import NetworkModule, NetworkError, ModuleStub from ansible.module_utils.netcli import Command
from ansible.module_utils.network import ModuleStub, NetworkError, NetworkModule
from ansible.module_utils.network import add_argument, register_transport, to_list from ansible.module_utils.network import add_argument, register_transport, to_list
from ansible.module_utils.shell import CliBase from ansible.module_utils.shell import CliBase
from ansible.module_utils.netcli import Command from ansible.module_utils.six.moves.urllib.parse import urlparse
from ansible.module_utils.urls import fetch_url, url_argument_spec from ansible.module_utils.urls import fetch_url, url_argument_spec
add_argument('use_ssl', dict(default=True, type='bool')) add_argument('use_ssl', dict(default=True, type='bool'))
add_argument('validate_certs', dict(default=True, type='bool')) add_argument('validate_certs', dict(default=True, type='bool'))
class Cli(CliBase):
NET_PASSWD_RE = re.compile(r"[\r\n]?password: $", re.I)
CLI_PROMPTS_RE = [
re.compile(r"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"),
re.compile(r"\[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$")
]
CLI_ERRORS_RE = [
re.compile(r"% ?Error"),
re.compile(r"% ?Bad secret"),
re.compile(r"invalid input", re.I),
re.compile(r"(?:incomplete|ambiguous) command", re.I),
re.compile(r"connection timed out", re.I),
re.compile(r"[^\r\n]+ not found", re.I),
re.compile(r"'[^']' +returned error code: ?\d+"),
]
def connect(self, params, **kwargs):
super(Cli, self).connect(params, kickstart=False, **kwargs)
self.shell.send('terminal length 0')
self._connected = True
def authorize(self, params, **kwargs):
passwd = params['auth_pass']
cmd = Command('enable', prompt=self.NET_PASSWD_RE, response=passwd)
self.execute([cmd])
### implementation of netcli.Cli ###
def run_commands(self, commands):
return self.execute(to_list(commands))
### implementation of netcfg.Config ###
def configure(self, commands):
cmds = ['configure terminal']
cmds.extend(to_list(commands))
if cmds[-1] != 'end':
cmds.append('end')
responses = self.execute(cmds)
return responses[1:]
def get_config(self, include_defaults=False, **kwargs):
cmd = 'show running-config'
if include_defaults:
cmd += ' all'
return self.run_commands(cmd)[0]
def load_config(self, commands, **kwargs):
return self.configure(commands)
def save_config(self):
self.execute(['copy running-config startup-config'])
Cli = register_transport('cli', default=True)(Cli)
class Restconf(object): class Restconf(object):
DEFAULT_HEADERS = { DEFAULT_HEADERS = {
@ -99,7 +40,6 @@ class Restconf(object):
def __init__(self): def __init__(self):
self.url = None self.url = None
self.url_args = ModuleStub(url_argument_spec(), self._error) self.url_args = ModuleStub(url_argument_spec(), self._error)
self.token = None self.token = None
@ -115,6 +55,7 @@ class Restconf(object):
host = params['host'] host = params['host']
port = params['port'] or 55443 port = params['port'] or 55443
# sets the module_utils/urls.py req parameters
self.url_args.params['url_username'] = params['username'] self.url_args.params['url_username'] = params['username']
self.url_args.params['url_password'] = params['password'] self.url_args.params['url_password'] = params['password']
self.url_args.params['validate_certs'] = params['validate_certs'] self.url_args.params['validate_certs'] = params['validate_certs']
@ -127,13 +68,13 @@ class Restconf(object):
self.link = response['link'] self.link = response['link']
self._connected = True self._connected = True
def disconnect(self): def disconnect(self, **kwargs):
self.delete(self.link) self.delete(self.link)
self.url = None
self._connected = False self._connected = False
def authorize(self): def authorize(self, params, **kwargs):
pass raise NotImplementedError
### REST methods ### ### REST methods ###
@ -178,10 +119,9 @@ class Restconf(object):
def delete(self, path, data=None, headers=None): def delete(self, path, data=None, headers=None):
return self.request('DELETE', path, data, headers) return self.request('DELETE', path, data, headers)
### Command methods ###
### implementation of netcli.Cli ### def run_commands(self, commands, **kwargs):
def run_commands(self, commands):
responses = list() responses = list()
commands = [str(c) for c in commands] commands = [str(c) for c in commands]
for cmd in commands: for cmd in commands:
@ -190,13 +130,12 @@ class Restconf(object):
responses.append(self.execute(str(cmd))) responses.append(self.execute(str(cmd)))
return responses return responses
def execute(self, command): def execute(self, command, **kwargs):
data = dict(show=command) data = dict(show=command)
response = self.put('global/cli', data=data) response = self.put('global/cli', data=data)
return response['results'] return response['results']
### Config methods ###
### implementation of netcfg.Config ###
def configure(self, commands): def configure(self, commands):
config = list() config = list()
@ -216,3 +155,55 @@ class Restconf(object):
self.put('/api/v1/global/save-config') self.put('/api/v1/global/save-config')
Restconf = register_transport('restconf')(Restconf) Restconf = register_transport('restconf')(Restconf)
class Cli(CliBase):
CLI_PROMPTS_RE = [
re.compile(r"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"),
re.compile(r"\[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$")
]
CLI_ERRORS_RE = [
re.compile(r"% ?Error"),
re.compile(r"% ?Bad secret"),
re.compile(r"invalid input", re.I),
re.compile(r"(?:incomplete|ambiguous) command", re.I),
re.compile(r"connection timed out", re.I),
re.compile(r"[^\r\n]+ not found", re.I),
re.compile(r"'[^']' +returned error code: ?\d+"),
]
NET_PASSWD_RE = re.compile(r"[\r\n]?password: $", re.I)
def connect(self, params, **kwargs):
super(Cli, self).connect(params, kickstart=False, **kwargs)
self.shell.send('terminal length 0')
def authorize(self, params, **kwargs):
passwd = params['auth_pass']
self.execute(Command('enable', prompt=self.NET_PASSWD_RE, response=passwd))
### Config methods ###
def configure(self, commands, **kwargs):
cmds = ['configure terminal']
cmds.extend(to_list(commands))
if cmds[-1] != 'end':
cmds.append('end')
responses = self.execute(cmds)
return responses[1:]
def get_config(self, include_defaults=False, **kwargs):
cmd = 'show running-config'
if include_defaults:
cmd += ' all'
return self.execute([cmd])[0]
def load_config(self, commands, **kwargs):
return self.configure(commands)
def save_config(self):
self.execute(['copy running-config startup-config'])
Cli = register_transport('cli', default=True)(Cli)

@ -28,10 +28,10 @@
import re import re
from ansible.module_utils.network import NetworkModule, NetworkError from ansible.module_utils.netcli import Command
from ansible.module_utils.network import Command from ansible.module_utils.network import NetworkError, NetworkModule
from ansible.module_utils.shell import CliBase
from ansible.module_utils.network import register_transport, to_list from ansible.module_utils.network import register_transport, to_list
from ansible.module_utils.shell import CliBase
class Cli(CliBase): class Cli(CliBase):
@ -55,17 +55,9 @@ class Cli(CliBase):
def connect(self, params, **kwargs): def connect(self, params, **kwargs):
super(Cli, self).connect(params, kickstart=False, **kwargs) super(Cli, self).connect(params, kickstart=False, **kwargs)
self.shell.send(['terminal length 0', self.shell.send(['terminal length 0', 'terminal exec prompt no-timestamp'])
'terminal exec prompt no-timestamp'])
### implementation of netcli.Cli ###
def run_commands(self, commands):
cmds = to_list(commands)
responses = self.execute(cmds)
return responses
### implementation of netcfg.Config ### ### Config methods ###
def configure(self, commands, **kwargs): def configure(self, commands, **kwargs):
cmds = ['configure terminal'] cmds = ['configure terminal']

@ -19,10 +19,11 @@
import re import re
import shlex import shlex
import re
from distutils.version import LooseVersion from distutils.version import LooseVersion
from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.network import NetworkModule, NetworkError from ansible.module_utils.network import NetworkError, NetworkModule
from ansible.module_utils.network import register_transport, to_list from ansible.module_utils.network import register_transport, to_list
from ansible.module_utils.shell import CliBase from ansible.module_utils.shell import CliBase
from ansible.module_utils.six import string_types from ansible.module_utils.six import string_types
@ -307,4 +308,3 @@ def rpc_args(args):
else: else:
kwargs[key] = str(value) kwargs[key] = str(value)
return (name, kwargs) return (name, kwargs)

@ -28,12 +28,9 @@
import itertools import itertools
import re import re
import shlex
import time
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
from ansible.module_utils.six import string_types from ansible.module_utils.six import string_types
from ansible.module_utils.six.moves import zip_longest from ansible.module_utils.six.moves import zip, zip_longest
DEFAULT_COMMENT_TOKENS = ['#', '!', '/*', '*/'] DEFAULT_COMMENT_TOKENS = ['#', '!', '/*', '*/']
@ -46,6 +43,7 @@ def to_list(val):
else: else:
return list() return list()
class Config(object): class Config(object):
def __init__(self, connection): def __init__(self, connection):
@ -299,7 +297,7 @@ class NetworkConfig(object):
if len(other.items) != len(self.items): if len(other.items) != len(self.items):
diff.extend(self.items) diff.extend(self.items)
else: else:
for ours, theirs in itertools.izip(self.items, other.items): for ours, theirs in zip(self.items, other.items):
if ours != theirs: if ours != theirs:
diff.extend(self.items) diff.extend(self.items)
break break
@ -406,5 +404,3 @@ class NetworkConfig(object):
item.parents = ancestors item.parents = ancestors
ancestors[-1].children.append(item) ancestors[-1].children.append(item)
self.items.append(item) self.items.append(item)

@ -298,4 +298,3 @@ class Conditional(object):
def matches(self, value): def matches(self, value):
match = re.search(value, self.value, re.M) match = re.search(value, self.value, re.M)
return match is not None return match is not None

@ -20,12 +20,10 @@
import re import re
import collections import collections
from ansible.module_utils.basic import json, get_exception from ansible.module_utils.basic import json
from ansible.module_utils.network import NetworkModule, NetworkError, ModuleStub from ansible.module_utils.network import ModuleStub, NetworkError, NetworkModule
from ansible.module_utils.network import add_argument, register_transport, to_list from ansible.module_utils.network import add_argument, register_transport, to_list
from ansible.module_utils.shell import CliBase from ansible.module_utils.shell import CliBase
from ansible.module_utils.netcfg import NetworkConfig
from ansible.module_utils.netcli import Command
from ansible.module_utils.urls import fetch_url, url_argument_spec from ansible.module_utils.urls import fetch_url, url_argument_spec
add_argument('use_ssl', dict(default=False, type='bool')) add_argument('use_ssl', dict(default=False, type='bool'))
@ -102,6 +100,8 @@ class Nxapi(object):
self._nxapi_auth = None self._nxapi_auth = None
self._connected = False self._connected = False
### Command methods ###
def execute(self, commands, output=None, **kwargs): def execute(self, commands, output=None, **kwargs):
commands = collections.deque(commands) commands = collections.deque(commands)
output = output or self.default_output output = output or self.default_output
@ -153,9 +153,7 @@ class Nxapi(object):
return result return result
### implemention of netcli.Cli ### def run_commands(self, commands, **kwargs):
def run_commands(self, commands):
output = None output = None
cmds = list() cmds = list()
responses = list() responses = list()
@ -164,6 +162,7 @@ class Nxapi(object):
if output and output != cmd.output: if output and output != cmd.output:
responses.extend(self.execute(cmds, output=output)) responses.extend(self.execute(cmds, output=output))
cmds = list() cmds = list()
output = cmd.output output = cmd.output
cmds.append(str(cmd)) cmds.append(str(cmd))
@ -173,13 +172,13 @@ class Nxapi(object):
return responses return responses
### implemention of netcfg.Config ### ### Config methods ###
def configure(self, commands): def configure(self, commands):
commands = to_list(commands) commands = to_list(commands)
return self.execute(commands, output='config') return self.execute(commands, output='config')
def get_config(self, include_defaults=False): def get_config(self, include_defaults=False, **kwargs):
cmd = 'show running-config' cmd = 'show running-config'
if include_defaults: if include_defaults:
cmd += ' all' cmd += ' all'
@ -191,8 +190,6 @@ class Nxapi(object):
def save_config(self, **kwargs): def save_config(self, **kwargs):
self.execute(['copy running-config startup-config']) self.execute(['copy running-config startup-config'])
### end netcfg.Config ###
def _jsonify(self, data): def _jsonify(self, data):
for encoding in ("utf-8", "latin-1"): for encoding in ("utf-8", "latin-1"):
try: try:
@ -213,8 +210,6 @@ Nxapi = register_transport('nxapi')(Nxapi)
class Cli(CliBase): class Cli(CliBase):
NET_PASSWD_RE = re.compile(r"[\r\n]?password: $", re.I)
CLI_PROMPTS_RE = [ CLI_PROMPTS_RE = [
re.compile(r'[\r\n]?[a-zA-Z]{1}[a-zA-Z0-9-]*[>|#|%](?:\s*)$'), re.compile(r'[\r\n]?[a-zA-Z]{1}[a-zA-Z0-9-]*[>|#|%](?:\s*)$'),
re.compile(r'[\r\n]?[a-zA-Z]{1}[a-zA-Z0-9-]*\(.+\)#(?:\s*)$') re.compile(r'[\r\n]?[a-zA-Z]{1}[a-zA-Z0-9-]*\(.+\)#(?:\s*)$')
@ -233,11 +228,13 @@ class Cli(CliBase):
re.compile(r"unknown command") re.compile(r"unknown command")
] ]
NET_PASSWD_RE = re.compile(r"[\r\n]?password: $", re.I)
def connect(self, params, **kwargs): def connect(self, params, **kwargs):
super(Cli, self).connect(params, kickstart=False, **kwargs) super(Cli, self).connect(params, kickstart=False, **kwargs)
self.shell.send('terminal length 0') self.shell.send('terminal length 0')
### implementation of netcli.Cli ### ### Command methods ###
def run_commands(self, commands): def run_commands(self, commands):
cmds = list(prepare_commands(commands)) cmds = list(prepare_commands(commands))
@ -253,7 +250,7 @@ class Cli(CliBase):
) )
return responses return responses
### implemented by netcfg.Config ### ### Config methods ###
def configure(self, commands, **kwargs): def configure(self, commands, **kwargs):
commands = prepare_config(commands) commands = prepare_config(commands)

@ -29,7 +29,7 @@ except ImportError:
HAS_OPS = False HAS_OPS = False
from ansible.module_utils.basic import json, json_dict_bytes_to_unicode from ansible.module_utils.basic import json, json_dict_bytes_to_unicode
from ansible.module_utils.network import NetworkModule, ModuleStub, NetworkError from ansible.module_utils.network import ModuleStub, NetworkError, NetworkModule
from ansible.module_utils.network import add_argument, register_transport, to_list from ansible.module_utils.network import add_argument, register_transport, to_list
from ansible.module_utils.shell import CliBase from ansible.module_utils.shell import CliBase
from ansible.module_utils.urls import fetch_url, url_argument_spec from ansible.module_utils.urls import fetch_url, url_argument_spec
@ -78,12 +78,19 @@ class Response(object):
class Rest(object): class Rest(object):
DEFAULT_HEADERS = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
def __init__(self): def __init__(self):
self.url = None self.url = None
self.url_args = ModuleStub(url_argument_spec(), self._error) self.url_args = ModuleStub(url_argument_spec(), self._error)
self.headers = dict({'Content-Type': 'application/json', 'Accept': 'application/json'})
self.default_output = 'json' self.headers = self.DEFAULT_HEADERS
self._connected = False self._connected = False
self.default_output = 'json'
def _error(self, msg): def _error(self, msg):
raise NetworkError(msg, url=self.url) raise NetworkError(msg, url=self.url)
@ -107,7 +114,7 @@ class Rest(object):
port = 80 port = 80
baseurl = '%s://%s:%s' % (proto, host, port) baseurl = '%s://%s:%s' % (proto, host, port)
headers = dict({'Content-Type': 'application/x-www-form-urlencoded'}) headers = {'Content-Type': 'application/x-www-form-urlencoded'}
# Get a cookie and save it the rest of the operations. # Get a cookie and save it the rest of the operations.
url = '%s/%s' % (baseurl, 'login') url = '%s/%s' % (baseurl, 'login')
data = 'username=%s&password=%s' % (params['username'], params['password']) data = 'username=%s&password=%s' % (params['username'], params['password'])
@ -124,6 +131,8 @@ class Rest(object):
def authorize(self, params, **kwargs): def authorize(self, params, **kwargs):
raise NotImplementedError raise NotImplementedError
### REST methods ###
def _url_builder(self, path): def _url_builder(self, path):
if path[0] == '/': if path[0] == '/':
path = path[1:] path = path[1:]
@ -153,9 +162,13 @@ class Rest(object):
def delete(self, path, data=None, headers=None): def delete(self, path, data=None, headers=None):
return self.request('DELETE', path, data, headers) return self.request('DELETE', path, data, headers)
### Command methods ###
def run_commands(self, commands): def run_commands(self, commands):
raise NotImplementedError raise NotImplementedError
### Config methods ###
def configure(self, commands): def configure(self, commands):
path = '/system/full-configuration' path = '/system/full-configuration'
return self.put(path, data=commands) return self.put(path, data=commands)
@ -190,8 +203,6 @@ Rest = register_transport('rest')(Rest)
class Cli(CliBase): class Cli(CliBase):
NET_PASSWD_RE = re.compile(r"[\r\n]?password: $", re.I)
CLI_PROMPTS_RE = [ CLI_PROMPTS_RE = [
re.compile(r"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"), re.compile(r"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"),
re.compile(r"\[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$") re.compile(r"\[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$")
@ -207,12 +218,9 @@ class Cli(CliBase):
re.compile(r"'[^']' +returned error code: ?\d+"), re.compile(r"'[^']' +returned error code: ?\d+"),
] ]
### implementation of netcli.Cli NET_PASSWD_RE = re.compile(r"[\r\n]?password: $", re.I)
def run_commands(self, commands):
return self.execute(to_list(commands))
### implementation of netcfg.Config ### Config methods ###
def configure(self, commands, **kwargs): def configure(self, commands, **kwargs):
cmds = ['configure terminal'] cmds = ['configure terminal']
@ -225,7 +233,7 @@ class Cli(CliBase):
def get_config(self): def get_config(self):
return self.execute('show running-config')[0] return self.execute('show running-config')[0]
def load_config(self, commands): def load_config(self, commands, **kwargs):
return self.configure(commands) return self.configure(commands)
def save_config(self): def save_config(self):

Loading…
Cancel
Save