mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #17220 from privateip/iosxr
updates iosxr shared module
This commit is contained in:
commit
ce6de1f64d
2 changed files with 81 additions and 28 deletions
|
@ -28,10 +28,14 @@
|
|||
|
||||
import re
|
||||
|
||||
from ansible.module_utils.network import Command, NetCli, NetworkError, get_module
|
||||
from ansible.module_utils.network import NetworkModule, NetworkError
|
||||
from ansible.module_utils.network import Command
|
||||
from ansible.module_utils.shell import CliBase
|
||||
from ansible.module_utils.network import register_transport, to_list
|
||||
|
||||
class Cli(NetCli):
|
||||
|
||||
class Cli(CliBase):
|
||||
|
||||
CLI_PROMPTS_RE = [
|
||||
re.compile(r"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"),
|
||||
re.compile(r"\[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$")
|
||||
|
@ -53,35 +57,56 @@ class Cli(NetCli):
|
|||
super(Cli, self).connect(params, kickstart=False, **kwargs)
|
||||
self.shell.send('terminal length 0')
|
||||
|
||||
### implementation of network.Cli ###
|
||||
|
||||
def configure(self, commands, **kwargs):
|
||||
cmds = ['configure']
|
||||
cmds.extend(to_list(commands))
|
||||
cmds.append('end')
|
||||
|
||||
responses = self.execute(cmds)
|
||||
return responses[1:-1]
|
||||
|
||||
def get_config(self, params, **kwargs):
|
||||
return self.run_commands('show running-config')[0]
|
||||
|
||||
def load_config(self, commands, commit=False, **kwargs):
|
||||
raise NotImplementedError
|
||||
|
||||
def replace_config(self, commands, **kwargs):
|
||||
raise NotImplementedError
|
||||
|
||||
def commit_config(self, **kwargs):
|
||||
command = 'commit'
|
||||
self.run_commands([command])
|
||||
|
||||
def abort_config(self, **kwargs):
|
||||
command = 'abort'
|
||||
self.run_commands([command])
|
||||
### implementation of netcli.Cli ###
|
||||
|
||||
def run_commands(self, commands):
|
||||
cmds = to_list(commands)
|
||||
responses = self.execute(cmds)
|
||||
return responses
|
||||
|
||||
### immplementation of netcfg.Config ###
|
||||
|
||||
def configure(self, commands, **kwargs):
|
||||
cmds = ['configure terminal']
|
||||
cmds.extend(to_list(commands))
|
||||
responses = self.execute(cmds)
|
||||
return responses[1:]
|
||||
|
||||
def get_config(self, flags=None, **kwargs):
|
||||
cmd = 'show running-config'
|
||||
if flags:
|
||||
if isinstance(flags, list):
|
||||
cmd += ' %s' % ' '.join(flags)
|
||||
else:
|
||||
cmd += ' %s' % flags
|
||||
return self.execute([cmd])[0]
|
||||
|
||||
def load_config(self, config, replace=False, commit=False, **kwargs):
|
||||
commands = ['configure terminal']
|
||||
commands.extend(config)
|
||||
|
||||
if commands[-1] == 'end':
|
||||
commands.pop()
|
||||
|
||||
try:
|
||||
self.execute(commands)
|
||||
diff = self.execute(['show commit changes diff'])
|
||||
if commit:
|
||||
if replace:
|
||||
prompt = re.compile(r'\[no\]:\s$')
|
||||
cmd = Command('commit replace', prompt=prompt,
|
||||
response='yes')
|
||||
self.execute([cmd, 'end'])
|
||||
else:
|
||||
self.execute(['commit', 'end'])
|
||||
except NetworkError:
|
||||
self.execute(['abort'])
|
||||
diff = None
|
||||
raise
|
||||
return diff[0]
|
||||
|
||||
def save_config(self):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
Cli = register_transport('cli', default=True)(Cli)
|
||||
|
|
28
lib/ansible/plugins/action/iosxr_config.py
Normal file
28
lib/ansible/plugins/action/iosxr_config.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
#
|
||||
# Copyright 2015 Peter Sprygada <psprygada@ansible.com>
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.plugins.action.net_config import ActionModule as NetActionModule
|
||||
|
||||
class ActionModule(NetActionModule, ActionBase):
|
||||
pass
|
||||
|
||||
|
Loading…
Reference in a new issue