mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 13:50:22 -07:00
updates iosxr modules to support socket (#21231)
* updates all iosxr modules to support persistent socket * adds iosxr action plugin to connect to device * adds exec_command() to iosxr shared module * fixes iosxr_config and iosxr_template local action * update all unit test cases * adds base test module for iosxr module testing
This commit is contained in:
parent
635e3fe9ee
commit
eb1453a366
17 changed files with 466 additions and 623 deletions
|
@ -26,9 +26,29 @@
|
|||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
from ansible.module_utils.basic import env_fallback
|
||||
from ansible.module_utils.network_common import to_list
|
||||
from ansible.module_utils.connection import exec_command
|
||||
|
||||
_DEVICE_CONFIGS = {}
|
||||
|
||||
iosxr_argument_spec = {
|
||||
'host': dict(),
|
||||
'port': dict(type='int'),
|
||||
'username': dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])),
|
||||
'password': dict(fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), no_log=True),
|
||||
'ssh_keyfile': dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'),
|
||||
'timeout': dict(type='int', default=10),
|
||||
'provider': dict(type='dict')
|
||||
}
|
||||
|
||||
def check_args(module, warnings):
|
||||
provider = module.params['provider'] or {}
|
||||
for key in iosxr_argument_spec:
|
||||
if key != 'provider' and module.params[key]:
|
||||
warnings.append('argument %s has been deprecated and will be '
|
||||
'removed in a future version' % key)
|
||||
|
||||
def get_config(module, flags=[]):
|
||||
cmd = 'show running-config '
|
||||
cmd += ' '.join(flags)
|
||||
|
@ -37,7 +57,7 @@ def get_config(module, flags=[]):
|
|||
try:
|
||||
return _DEVICE_CONFIGS[cmd]
|
||||
except KeyError:
|
||||
rc, out, err = module.exec_command(cmd)
|
||||
rc, out, err = exec_command(module, cmd)
|
||||
if rc != 0:
|
||||
module.fail_json(msg='unable to retrieve current config', stderr=err)
|
||||
cfg = str(out).strip()
|
||||
|
@ -45,38 +65,35 @@ def get_config(module, flags=[]):
|
|||
return cfg
|
||||
|
||||
def run_commands(module, commands, check_rc=True):
|
||||
assert isinstance(commands, list), 'commands must be a list'
|
||||
responses = list()
|
||||
|
||||
for cmd in commands:
|
||||
rc, out, err = module.exec_command(cmd)
|
||||
for cmd in to_list(commands):
|
||||
rc, out, err = exec_command(module, cmd)
|
||||
if check_rc and rc != 0:
|
||||
module.fail_json(msg=err, rc=rc)
|
||||
responses.append(out)
|
||||
return responses
|
||||
|
||||
def load_config(module, commands, commit=False, replace=False, comment=None):
|
||||
assert isinstance(commands, list), 'commands must be a list'
|
||||
|
||||
rc, out, err = module.exec_command('configure terminal')
|
||||
rc, out, err = exec_command(module, 'configure terminal')
|
||||
if rc != 0:
|
||||
module.fail_json(msg='unable to enter configuration mode', err=err)
|
||||
|
||||
failed = False
|
||||
for command in commands:
|
||||
for command in to_list(commands):
|
||||
if command == 'end':
|
||||
pass
|
||||
|
||||
rc, out, err = module.exec_command(command)
|
||||
rc, out, err = exec_command(module, command)
|
||||
if rc != 0:
|
||||
failed = True
|
||||
break
|
||||
|
||||
if failed:
|
||||
module.exec_command('abort')
|
||||
exec_command(module, 'abort')
|
||||
module.fail_json(msg=err, commands=commands, rc=rc)
|
||||
|
||||
rc, diff, err = module.exec_command('show commit changes diff')
|
||||
rc, diff, err = exec_command(module, 'show commit changes diff')
|
||||
if commit:
|
||||
cmd = 'commit'
|
||||
if comment:
|
||||
|
@ -84,6 +101,6 @@ def load_config(module, commands, commit=False, replace=False, comment=None):
|
|||
else:
|
||||
cmd = 'abort'
|
||||
diff = None
|
||||
module.exec_command(cmd)
|
||||
exec_command(module, cmd)
|
||||
|
||||
return diff
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue