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
This commit is contained in:
Nathaniel Case 2016-09-06 13:49:48 -04:00 committed by GitHub
commit 972dc3fc97
9 changed files with 140 additions and 163 deletions

View file

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