mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fix bugs for ce (#54750)
* Update ce.py while to_text(out, errors='surrogate_then_replace').strip().endswith(']'): display.vvvv('wrong context, sending exit to device', self._play_context.remote_addr) conn.exec_command('return') out = conn.get_prompt() connetion has no send_command function and ce device has no 'exit' command to return user-view(a correct context),but 'return' .command. * Add files via upload Some bugs fix. * Add files via upload fix some bugs * fix a bug for ce_command Running a command with prompt via ce_command, It doesn't work.The reason is that the key word for network_cli recognition is answer not response. * fix bugs fix bugs for ce modules * Update ce.py * Delete ce_ftp.py need modify * Delete ce_lacp.py * Add files via upload * Delete ce_aaa_server.py * Delete ce_aaa_server_host.py * Compatible with Python 3 Compatible with Python 3 and fix bugs for ce * Update ce_aaa_server.py * Add files via upload modify doc * Add files via upload Compatible with Python 3 and fix bugs * Add files via upload Compatible with Python 3 and fix bugs * Add files via upload Cancellation of change * Update ce_netconf.py It is a bug that response has no xml attribute:line 183 * Add files via upload * Add files via upload Compatible with Python 3 and fix bugs * updatp ce_config.py a bug for this module.
This commit is contained in:
parent
f8bebc61c8
commit
1017f15c38
9 changed files with 315 additions and 269 deletions
|
@ -80,7 +80,7 @@ ce_argument_spec.update(ce_top_spec)
|
||||||
|
|
||||||
|
|
||||||
def to_string(data):
|
def to_string(data):
|
||||||
return re.sub(r'<data.+?(/>|>)', r'<data\1', data)
|
return re.sub(r'<data\s+.+?(/>|>)', r'<data\1', data)
|
||||||
|
|
||||||
|
|
||||||
def check_args(module, warnings):
|
def check_args(module, warnings):
|
||||||
|
@ -164,12 +164,11 @@ class Cli:
|
||||||
responses = list()
|
responses = list()
|
||||||
|
|
||||||
for item in to_list(commands):
|
for item in to_list(commands):
|
||||||
cmd = item['command']
|
|
||||||
|
|
||||||
rc, out, err = self.exec_command(cmd)
|
rc, out, err = self.exec_command(item)
|
||||||
|
|
||||||
if check_rc and rc != 0:
|
if check_rc and rc != 0:
|
||||||
self._module.fail_json(msg=cli_err_msg(cmd.strip(), err))
|
self._module.fail_json(msg=cli_err_msg(item['command'].strip(), err))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
out = self._module.from_json(out)
|
out = self._module.from_json(out)
|
||||||
|
@ -234,7 +233,7 @@ def to_command(module, commands):
|
||||||
command=dict(key=True),
|
command=dict(key=True),
|
||||||
output=dict(default=default_output),
|
output=dict(default=default_output),
|
||||||
prompt=dict(),
|
prompt=dict(),
|
||||||
response=dict()
|
answer=dict()
|
||||||
), module)
|
), module)
|
||||||
|
|
||||||
commands = transform(to_list(commands))
|
commands = transform(to_list(commands))
|
||||||
|
|
|
@ -46,6 +46,7 @@ options:
|
||||||
- Preferred authentication mode.
|
- Preferred authentication mode.
|
||||||
type: str
|
type: str
|
||||||
choices: ['invalid', 'local', 'hwtacacs', 'radius', 'none']
|
choices: ['invalid', 'local', 'hwtacacs', 'radius', 'none']
|
||||||
|
default: local
|
||||||
author_scheme_name:
|
author_scheme_name:
|
||||||
description:
|
description:
|
||||||
- Name of an authorization scheme.
|
- Name of an authorization scheme.
|
||||||
|
@ -56,6 +57,7 @@ options:
|
||||||
- Preferred authorization mode.
|
- Preferred authorization mode.
|
||||||
type: str
|
type: str
|
||||||
choices: ['invalid', 'local', 'hwtacacs', 'if-authenticated', 'none']
|
choices: ['invalid', 'local', 'hwtacacs', 'if-authenticated', 'none']
|
||||||
|
default: local
|
||||||
acct_scheme_name:
|
acct_scheme_name:
|
||||||
description:
|
description:
|
||||||
- Accounting scheme name.
|
- Accounting scheme name.
|
||||||
|
@ -66,6 +68,7 @@ options:
|
||||||
- Accounting Mode.
|
- Accounting Mode.
|
||||||
type: str
|
type: str
|
||||||
choices: ['invalid', 'hwtacacs', 'radius', 'none']
|
choices: ['invalid', 'hwtacacs', 'radius', 'none']
|
||||||
|
default: none
|
||||||
domain_name:
|
domain_name:
|
||||||
description:
|
description:
|
||||||
- Name of a domain.
|
- Name of a domain.
|
||||||
|
@ -762,16 +765,15 @@ class AaaServer(object):
|
||||||
conf_str = CE_GET_AUTHENTICATION_SCHEME
|
conf_str = CE_GET_AUTHENTICATION_SCHEME
|
||||||
|
|
||||||
xml_str = self.netconf_get_config(module=module, conf_str=conf_str)
|
xml_str = self.netconf_get_config(module=module, conf_str=conf_str)
|
||||||
|
|
||||||
result = list()
|
result = list()
|
||||||
|
|
||||||
if "<data/>" in xml_str:
|
if "<data/>" in xml_str:
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
re_find = re.findall(
|
re_find = re.findall(
|
||||||
r'.*<firstAuthenMode>(.*)</firstAuthenMode>.*\s*'
|
r'.*<authenSchemeName>(.*)</authenSchemeName>.*\s*'
|
||||||
r'<secondAuthenMode>(.*)</secondAuthenMode>.*\s*'
|
r'<firstAuthenMode>(.*)</firstAuthenMode>.*\s*'
|
||||||
r'<authenSchemeName>(.*)</authenSchemeName>.*', xml_str)
|
r'<secondAuthenMode>(.*)</secondAuthenMode>.*\s*', xml_str)
|
||||||
|
|
||||||
if re_find:
|
if re_find:
|
||||||
return re_find
|
return re_find
|
||||||
|
@ -947,16 +949,15 @@ class AaaServer(object):
|
||||||
conf_str = CE_GET_AUTHORIZATION_SCHEME
|
conf_str = CE_GET_AUTHORIZATION_SCHEME
|
||||||
|
|
||||||
xml_str = self.netconf_get_config(module=module, conf_str=conf_str)
|
xml_str = self.netconf_get_config(module=module, conf_str=conf_str)
|
||||||
|
|
||||||
result = list()
|
result = list()
|
||||||
|
|
||||||
if "<data/>" in xml_str:
|
if "<data/>" in xml_str:
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
re_find = re.findall(
|
re_find = re.findall(
|
||||||
r'.*<firstAuthorMode>(.*)</firstAuthorMode>.*\s*'
|
r'.*<authorSchemeName>(.*)</authorSchemeName>.*\s*'
|
||||||
r'<secondAuthorMode>(.*)</secondAuthorMode>.*\s*'
|
r'<firstAuthorMode>(.*)</firstAuthorMode>.*\s*'
|
||||||
r'<authorSchemeName>(.*)</authorSchemeName>.*', xml_str)
|
r'<secondAuthorMode>(.*)</secondAuthorMode>.*\s*', xml_str)
|
||||||
|
|
||||||
if re_find:
|
if re_find:
|
||||||
return re_find
|
return re_find
|
||||||
|
@ -1132,16 +1133,12 @@ class AaaServer(object):
|
||||||
conf_str = CE_GET_ACCOUNTING_SCHEME
|
conf_str = CE_GET_ACCOUNTING_SCHEME
|
||||||
|
|
||||||
xml_str = self.netconf_get_config(module=module, conf_str=conf_str)
|
xml_str = self.netconf_get_config(module=module, conf_str=conf_str)
|
||||||
|
|
||||||
result = list()
|
result = list()
|
||||||
|
|
||||||
if "<data/>" in xml_str:
|
if "<data/>" in xml_str:
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
re_find = re.findall(
|
re_find = re.findall(r'.*<acctSchemeName>(.*)</acctSchemeName>\s*<accountingMode>(.*)</accountingMode>', xml_str)
|
||||||
r'.*<accountingMode>(.*)</accountingMode>.*\s*'
|
|
||||||
r'<acctSchemeName>(.*)</acctSchemeName>.*', xml_str)
|
|
||||||
|
|
||||||
if re_find:
|
if re_find:
|
||||||
return re_find
|
return re_find
|
||||||
else:
|
else:
|
||||||
|
@ -1676,25 +1673,20 @@ def check_module_argument(**kwargs):
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Error: local_user_group %s '
|
msg='Error: local_user_group %s '
|
||||||
'is large than 32.' % local_user_group)
|
'is large than 32.' % local_user_group)
|
||||||
check_name(module=module, name=local_user_group,
|
check_name(module=module, name=local_user_group, invalid_char=INVALID_GROUP_CHAR)
|
||||||
invalid_char=INVALID_GROUP_CHAR)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
""" Module main """
|
""" Module main """
|
||||||
|
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
state=dict(choices=['present', 'absent'],
|
state=dict(choices=['present', 'absent'], default='present'),
|
||||||
default='present'),
|
|
||||||
authen_scheme_name=dict(type='str'),
|
authen_scheme_name=dict(type='str'),
|
||||||
first_authen_mode=dict(choices=['invalid', 'local',
|
first_authen_mode=dict(default='local', choices=['invalid', 'local', 'hwtacacs', 'radius', 'none']),
|
||||||
'hwtacacs', 'radius', 'none']),
|
|
||||||
author_scheme_name=dict(type='str'),
|
author_scheme_name=dict(type='str'),
|
||||||
first_author_mode=dict(choices=['invalid', 'local',
|
first_author_mode=dict(default='local', choices=['invalid', 'local', 'hwtacacs', 'if-authenticated', 'none']),
|
||||||
'hwtacacs', 'if-authenticated', 'none']),
|
|
||||||
acct_scheme_name=dict(type='str'),
|
acct_scheme_name=dict(type='str'),
|
||||||
accounting_mode=dict(choices=['invalid', 'hwtacacs',
|
accounting_mode=dict(default='none', choices=['invalid', 'hwtacacs', 'radius', 'none']),
|
||||||
'radius', 'none']),
|
|
||||||
domain_name=dict(type='str'),
|
domain_name=dict(type='str'),
|
||||||
radius_server_group=dict(type='str'),
|
radius_server_group=dict(type='str'),
|
||||||
hwtacas_template=dict(type='str'),
|
hwtacas_template=dict(type='str'),
|
||||||
|
@ -1758,8 +1750,7 @@ def main():
|
||||||
if authen_scheme_name:
|
if authen_scheme_name:
|
||||||
|
|
||||||
scheme_exist = ce_aaa_server.get_authentication_scheme(module=module)
|
scheme_exist = ce_aaa_server.get_authentication_scheme(module=module)
|
||||||
scheme_new = (first_authen_mode.lower(), "invalid",
|
scheme_new = (authen_scheme_name.lower(), first_authen_mode.lower(), "invalid")
|
||||||
authen_scheme_name.lower())
|
|
||||||
|
|
||||||
existing["authentication scheme"] = scheme_exist
|
existing["authentication scheme"] = scheme_exist
|
||||||
|
|
||||||
|
@ -1843,8 +1834,7 @@ def main():
|
||||||
if author_scheme_name:
|
if author_scheme_name:
|
||||||
|
|
||||||
scheme_exist = ce_aaa_server.get_authorization_scheme(module=module)
|
scheme_exist = ce_aaa_server.get_authorization_scheme(module=module)
|
||||||
scheme_new = (first_author_mode.lower(), "invalid",
|
scheme_new = (author_scheme_name.lower(), first_author_mode.lower(), "invalid")
|
||||||
author_scheme_name.lower())
|
|
||||||
|
|
||||||
existing["authorization scheme"] = scheme_exist
|
existing["authorization scheme"] = scheme_exist
|
||||||
|
|
||||||
|
@ -1925,7 +1915,7 @@ def main():
|
||||||
if acct_scheme_name:
|
if acct_scheme_name:
|
||||||
|
|
||||||
scheme_exist = ce_aaa_server.get_accounting_scheme(module=module)
|
scheme_exist = ce_aaa_server.get_accounting_scheme(module=module)
|
||||||
scheme_new = (accounting_mode.lower(), acct_scheme_name.lower())
|
scheme_new = (acct_scheme_name.lower(), accounting_mode.lower())
|
||||||
|
|
||||||
existing["accounting scheme"] = scheme_exist
|
existing["accounting scheme"] = scheme_exist
|
||||||
|
|
||||||
|
|
|
@ -788,7 +788,7 @@ class AaaServerHost(object):
|
||||||
replace('xmlns="http://www.huawei.com/netconf/vrp"', "")
|
replace('xmlns="http://www.huawei.com/netconf/vrp"', "")
|
||||||
|
|
||||||
root = ElementTree.fromstring(xml_str)
|
root = ElementTree.fromstring(xml_str)
|
||||||
local_user_info = root.findall("data/aaa/lam/users/user")
|
local_user_info = root.findall("aaa/lam/users/user")
|
||||||
if local_user_info:
|
if local_user_info:
|
||||||
for tmp in local_user_info:
|
for tmp in local_user_info:
|
||||||
tmp_dict = dict()
|
tmp_dict = dict()
|
||||||
|
@ -1042,7 +1042,7 @@ class AaaServerHost(object):
|
||||||
|
|
||||||
root = ElementTree.fromstring(xml_str)
|
root = ElementTree.fromstring(xml_str)
|
||||||
radius_server_ip_v4 = root.findall(
|
radius_server_ip_v4 = root.findall(
|
||||||
"data/radius/rdsTemplates/rdsTemplate/rdsServerIPV4s/rdsServerIPV4")
|
"radius/rdsTemplates/rdsTemplate/rdsServerIPV4s/rdsServerIPV4")
|
||||||
if radius_server_ip_v4:
|
if radius_server_ip_v4:
|
||||||
for tmp in radius_server_ip_v4:
|
for tmp in radius_server_ip_v4:
|
||||||
tmp_dict = dict()
|
tmp_dict = dict()
|
||||||
|
@ -1053,43 +1053,42 @@ class AaaServerHost(object):
|
||||||
result["radius_server_ip_v4"].append(tmp_dict)
|
result["radius_server_ip_v4"].append(tmp_dict)
|
||||||
|
|
||||||
if result["radius_server_ip_v4"]:
|
if result["radius_server_ip_v4"]:
|
||||||
for tmp in result["radius_server_ip_v4"]:
|
cfg = dict()
|
||||||
if "serverType" in tmp.keys():
|
config_list = list()
|
||||||
if state == "present":
|
if radius_server_type:
|
||||||
if tmp["serverType"] != radius_server_type:
|
cfg["serverType"] = radius_server_type.lower()
|
||||||
need_cfg = True
|
if radius_server_ip:
|
||||||
else:
|
cfg["serverIPAddress"] = radius_server_ip.lower()
|
||||||
if tmp["serverType"] == radius_server_type:
|
if radius_server_port:
|
||||||
need_cfg = True
|
cfg["serverPort"] = radius_server_port.lower()
|
||||||
if "serverIPAddress" in tmp.keys():
|
if radius_server_mode:
|
||||||
if state == "present":
|
cfg["serverMode"] = radius_server_mode.lower()
|
||||||
if tmp["serverIPAddress"] != radius_server_ip:
|
if radius_vpn_name:
|
||||||
need_cfg = True
|
cfg["vpnName"] = radius_vpn_name.lower()
|
||||||
else:
|
|
||||||
if tmp["serverIPAddress"] == radius_server_ip:
|
|
||||||
need_cfg = True
|
|
||||||
if "serverPort" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["serverPort"] != radius_server_port:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["serverPort"] == radius_server_port:
|
|
||||||
need_cfg = True
|
|
||||||
if "serverMode" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["serverMode"] != radius_server_mode:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["serverMode"] == radius_server_mode:
|
|
||||||
need_cfg = True
|
|
||||||
if "vpnName" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["vpnName"] != radius_vpn_name:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["vpnName"] == radius_vpn_name:
|
|
||||||
need_cfg = True
|
|
||||||
|
|
||||||
|
for tmp in result["radius_server_ip_v4"]:
|
||||||
|
exist_cfg = dict()
|
||||||
|
if radius_server_type:
|
||||||
|
exist_cfg["serverType"] = tmp.get("serverType").lower()
|
||||||
|
if radius_server_ip:
|
||||||
|
exist_cfg["serverIPAddress"] = tmp.get("serverIPAddress").lower()
|
||||||
|
if radius_server_port:
|
||||||
|
exist_cfg["serverPort"] = tmp.get("serverPort").lower()
|
||||||
|
if radius_server_mode:
|
||||||
|
exist_cfg["serverMode"] = tmp.get("serverMode").lower()
|
||||||
|
if radius_vpn_name:
|
||||||
|
exist_cfg["vpnName"] = tmp.get("vpnName").lower()
|
||||||
|
config_list.append(exist_cfg)
|
||||||
|
if cfg in config_list:
|
||||||
|
if state == "present":
|
||||||
|
need_cfg = False
|
||||||
|
else:
|
||||||
|
need_cfg = True
|
||||||
|
else:
|
||||||
|
if state == "present":
|
||||||
|
need_cfg = True
|
||||||
|
else:
|
||||||
|
need_cfg = False
|
||||||
result["need_cfg"] = need_cfg
|
result["need_cfg"] = need_cfg
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -1221,7 +1220,7 @@ class AaaServerHost(object):
|
||||||
|
|
||||||
root = ElementTree.fromstring(xml_str)
|
root = ElementTree.fromstring(xml_str)
|
||||||
radius_server_ip_v6 = root.findall(
|
radius_server_ip_v6 = root.findall(
|
||||||
"data/radius/rdsTemplates/rdsTemplate/rdsServerIPV6s/rdsServerIPV6")
|
"radius/rdsTemplates/rdsTemplate/rdsServerIPV6s/rdsServerIPV6")
|
||||||
if radius_server_ip_v6:
|
if radius_server_ip_v6:
|
||||||
for tmp in radius_server_ip_v6:
|
for tmp in radius_server_ip_v6:
|
||||||
tmp_dict = dict()
|
tmp_dict = dict()
|
||||||
|
@ -1232,35 +1231,38 @@ class AaaServerHost(object):
|
||||||
result["radius_server_ip_v6"].append(tmp_dict)
|
result["radius_server_ip_v6"].append(tmp_dict)
|
||||||
|
|
||||||
if result["radius_server_ip_v6"]:
|
if result["radius_server_ip_v6"]:
|
||||||
|
cfg = dict()
|
||||||
|
config_list = list()
|
||||||
|
if radius_server_type:
|
||||||
|
cfg["serverType"] = radius_server_type.lower()
|
||||||
|
if radius_server_ipv6:
|
||||||
|
cfg["serverIPAddress"] = radius_server_ipv6.lower()
|
||||||
|
if radius_server_port:
|
||||||
|
cfg["serverPort"] = radius_server_port.lower()
|
||||||
|
if radius_server_mode:
|
||||||
|
cfg["serverMode"] = radius_server_mode.lower()
|
||||||
|
|
||||||
for tmp in result["radius_server_ip_v6"]:
|
for tmp in result["radius_server_ip_v6"]:
|
||||||
if "serverType" in tmp.keys():
|
exist_cfg = dict()
|
||||||
if state == "present":
|
if radius_server_type:
|
||||||
if tmp["serverType"] != radius_server_type:
|
exist_cfg["serverType"] = tmp.get("serverType").lower()
|
||||||
need_cfg = True
|
if radius_server_ipv6:
|
||||||
else:
|
exist_cfg["serverIPAddress"] = tmp.get("serverIPAddress").lower()
|
||||||
if tmp["serverType"] == radius_server_type:
|
if radius_server_port:
|
||||||
need_cfg = True
|
exist_cfg["serverPort"] = tmp.get("serverPort").lower()
|
||||||
if "serverIPAddress" in tmp.keys():
|
if radius_server_mode:
|
||||||
if state == "present":
|
exist_cfg["serverMode"] = tmp.get("serverMode").lower()
|
||||||
if tmp["serverIPAddress"] != radius_server_ipv6:
|
config_list.append(exist_cfg)
|
||||||
need_cfg = True
|
if cfg in config_list:
|
||||||
else:
|
if state == "present":
|
||||||
if tmp["serverIPAddress"] == radius_server_ipv6:
|
need_cfg = False
|
||||||
need_cfg = True
|
else:
|
||||||
if "serverPort" in tmp.keys():
|
need_cfg = True
|
||||||
if state == "present":
|
else:
|
||||||
if tmp["serverPort"] != radius_server_port:
|
if state == "present":
|
||||||
need_cfg = True
|
need_cfg = True
|
||||||
else:
|
else:
|
||||||
if tmp["serverPort"] == radius_server_port:
|
need_cfg = False
|
||||||
need_cfg = True
|
|
||||||
if "serverMode" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["serverMode"] != radius_server_mode:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["serverMode"] == radius_server_mode:
|
|
||||||
need_cfg = True
|
|
||||||
|
|
||||||
result["need_cfg"] = need_cfg
|
result["need_cfg"] = need_cfg
|
||||||
return result
|
return result
|
||||||
|
@ -1380,7 +1382,7 @@ class AaaServerHost(object):
|
||||||
|
|
||||||
root = ElementTree.fromstring(xml_str)
|
root = ElementTree.fromstring(xml_str)
|
||||||
radius_server_name_cfg = root.findall(
|
radius_server_name_cfg = root.findall(
|
||||||
"data/radius/rdsTemplates/rdsTemplate/rdsServerNames/rdsServerName")
|
"radius/rdsTemplates/rdsTemplate/rdsServerNames/rdsServerName")
|
||||||
if radius_server_name_cfg:
|
if radius_server_name_cfg:
|
||||||
for tmp in radius_server_name_cfg:
|
for tmp in radius_server_name_cfg:
|
||||||
tmp_dict = dict()
|
tmp_dict = dict()
|
||||||
|
@ -1391,43 +1393,42 @@ class AaaServerHost(object):
|
||||||
result["radius_server_name_cfg"].append(tmp_dict)
|
result["radius_server_name_cfg"].append(tmp_dict)
|
||||||
|
|
||||||
if result["radius_server_name_cfg"]:
|
if result["radius_server_name_cfg"]:
|
||||||
for tmp in result["radius_server_name_cfg"]:
|
cfg = dict()
|
||||||
if "serverType" in tmp.keys():
|
config_list = list()
|
||||||
if state == "present":
|
if radius_server_type:
|
||||||
if tmp["serverType"] != radius_server_type:
|
cfg["serverType"] = radius_server_type.lower()
|
||||||
need_cfg = True
|
if radius_server_name:
|
||||||
else:
|
cfg["serverName"] = radius_server_name.lower()
|
||||||
if tmp["serverType"] == radius_server_type:
|
if radius_server_port:
|
||||||
need_cfg = True
|
cfg["serverPort"] = radius_server_port.lower()
|
||||||
if "serverName" in tmp.keys():
|
if radius_server_mode:
|
||||||
if state == "present":
|
cfg["serverMode"] = radius_server_mode.lower()
|
||||||
if tmp["serverName"] != radius_server_name:
|
if radius_vpn_name:
|
||||||
need_cfg = True
|
cfg["vpnName"] = radius_vpn_name.lower()
|
||||||
else:
|
|
||||||
if tmp["serverName"] == radius_server_name:
|
|
||||||
need_cfg = True
|
|
||||||
if "serverPort" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["serverPort"] != radius_server_port:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["serverPort"] == radius_server_port:
|
|
||||||
need_cfg = True
|
|
||||||
if "serverMode" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["serverMode"] != radius_server_mode:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["serverMode"] == radius_server_mode:
|
|
||||||
need_cfg = True
|
|
||||||
if "vpnName" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["vpnName"] != radius_vpn_name:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["vpnName"] == radius_vpn_name:
|
|
||||||
need_cfg = True
|
|
||||||
|
|
||||||
|
for tmp in result["radius_server_name_cfg"]:
|
||||||
|
exist_cfg = dict()
|
||||||
|
if radius_server_type:
|
||||||
|
exist_cfg["serverType"] = tmp.get("serverType").lower()
|
||||||
|
if radius_server_name:
|
||||||
|
exist_cfg["serverName"] = tmp.get("serverName").lower()
|
||||||
|
if radius_server_port:
|
||||||
|
exist_cfg["serverPort"] = tmp.get("serverPort").lower()
|
||||||
|
if radius_server_mode:
|
||||||
|
exist_cfg["serverMode"] = tmp.get("serverMode").lower()
|
||||||
|
if radius_vpn_name:
|
||||||
|
exist_cfg["vpnName"] = tmp.get("vpnName").lower()
|
||||||
|
config_list.append(exist_cfg)
|
||||||
|
if cfg in config_list:
|
||||||
|
if state == "present":
|
||||||
|
need_cfg = False
|
||||||
|
else:
|
||||||
|
need_cfg = True
|
||||||
|
else:
|
||||||
|
if state == "present":
|
||||||
|
need_cfg = True
|
||||||
|
else:
|
||||||
|
need_cfg = False
|
||||||
result["need_cfg"] = need_cfg
|
result["need_cfg"] = need_cfg
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -1559,7 +1560,7 @@ class AaaServerHost(object):
|
||||||
|
|
||||||
root = ElementTree.fromstring(xml_str)
|
root = ElementTree.fromstring(xml_str)
|
||||||
hwtacacs_server_cfg_ipv4 = root.findall(
|
hwtacacs_server_cfg_ipv4 = root.findall(
|
||||||
"data/hwtacacs/hwTacTempCfgs/hwTacTempCfg/hwTacSrvCfgs/hwTacSrvCfg")
|
"hwtacacs/hwTacTempCfgs/hwTacTempCfg/hwTacSrvCfgs/hwTacSrvCfg")
|
||||||
if hwtacacs_server_cfg_ipv4:
|
if hwtacacs_server_cfg_ipv4:
|
||||||
for tmp in hwtacacs_server_cfg_ipv4:
|
for tmp in hwtacacs_server_cfg_ipv4:
|
||||||
tmp_dict = dict()
|
tmp_dict = dict()
|
||||||
|
@ -1570,43 +1571,43 @@ class AaaServerHost(object):
|
||||||
result["hwtacacs_server_cfg_ipv4"].append(tmp_dict)
|
result["hwtacacs_server_cfg_ipv4"].append(tmp_dict)
|
||||||
|
|
||||||
if result["hwtacacs_server_cfg_ipv4"]:
|
if result["hwtacacs_server_cfg_ipv4"]:
|
||||||
for tmp in result["hwtacacs_server_cfg_ipv4"]:
|
cfg = dict()
|
||||||
if "serverIpAddress" in tmp.keys():
|
config_list = list()
|
||||||
if state == "present":
|
|
||||||
if tmp["serverIpAddress"] != hwtacacs_server_ip:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["serverIpAddress"] == hwtacacs_server_ip:
|
|
||||||
need_cfg = True
|
|
||||||
if "serverType" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["serverType"] != hwtacacs_server_type:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["serverType"] == hwtacacs_server_type:
|
|
||||||
need_cfg = True
|
|
||||||
if "isSecondaryServer" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["isSecondaryServer"] != str(hwtacacs_is_secondary_server).lower():
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["isSecondaryServer"] == str(hwtacacs_is_secondary_server).lower():
|
|
||||||
need_cfg = True
|
|
||||||
if "isPublicNet" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["isPublicNet"] != str(hwtacacs_is_public_net).lower():
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["isPublicNet"] == str(hwtacacs_is_public_net).lower():
|
|
||||||
need_cfg = True
|
|
||||||
if "vpnName" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["vpnName"] != hwtacacs_vpn_name:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["vpnName"] == hwtacacs_vpn_name:
|
|
||||||
need_cfg = True
|
|
||||||
|
|
||||||
|
if hwtacacs_server_ip:
|
||||||
|
cfg["serverIpAddress"] = hwtacacs_server_ip.lower()
|
||||||
|
if hwtacacs_server_type:
|
||||||
|
cfg["serverType"] = hwtacacs_server_type.lower()
|
||||||
|
if hwtacacs_is_secondary_server:
|
||||||
|
cfg["isSecondaryServer"] = str(hwtacacs_is_secondary_server).lower()
|
||||||
|
if hwtacacs_is_public_net:
|
||||||
|
cfg["isPublicNet"] = str(hwtacacs_is_public_net).lower()
|
||||||
|
if hwtacacs_vpn_name:
|
||||||
|
cfg["vpnName"] = hwtacacs_vpn_name.lower()
|
||||||
|
|
||||||
|
for tmp in result["hwtacacs_server_cfg_ipv4"]:
|
||||||
|
exist_cfg = dict()
|
||||||
|
if hwtacacs_server_ip:
|
||||||
|
exist_cfg["serverIpAddress"] = tmp.get("serverIpAddress").lower()
|
||||||
|
if hwtacacs_server_type:
|
||||||
|
exist_cfg["serverType"] = tmp.get("serverType").lower()
|
||||||
|
if hwtacacs_is_secondary_server:
|
||||||
|
exist_cfg["isSecondaryServer"] = tmp.get("isSecondaryServer").lower()
|
||||||
|
if hwtacacs_is_public_net:
|
||||||
|
exist_cfg["isPublicNet"] = tmp.get("isPublicNet").lower()
|
||||||
|
if hwtacacs_vpn_name:
|
||||||
|
exist_cfg["vpnName"] = tmp.get("vpnName").lower()
|
||||||
|
config_list.append(exist_cfg)
|
||||||
|
if cfg in config_list:
|
||||||
|
if state == "present":
|
||||||
|
need_cfg = False
|
||||||
|
else:
|
||||||
|
need_cfg = True
|
||||||
|
else:
|
||||||
|
if state == "present":
|
||||||
|
need_cfg = True
|
||||||
|
else:
|
||||||
|
need_cfg = False
|
||||||
result["need_cfg"] = need_cfg
|
result["need_cfg"] = need_cfg
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -1775,7 +1776,7 @@ class AaaServerHost(object):
|
||||||
|
|
||||||
root = ElementTree.fromstring(xml_str)
|
root = ElementTree.fromstring(xml_str)
|
||||||
hwtacacs_server_cfg_ipv6 = root.findall(
|
hwtacacs_server_cfg_ipv6 = root.findall(
|
||||||
"data/hwtacacs/hwTacTempCfgs/hwTacTempCfg/hwTacIpv6SrvCfgs/hwTacIpv6SrvCfg")
|
"hwtacacs/hwTacTempCfgs/hwTacTempCfg/hwTacIpv6SrvCfgs/hwTacIpv6SrvCfg")
|
||||||
if hwtacacs_server_cfg_ipv6:
|
if hwtacacs_server_cfg_ipv6:
|
||||||
for tmp in hwtacacs_server_cfg_ipv6:
|
for tmp in hwtacacs_server_cfg_ipv6:
|
||||||
tmp_dict = dict()
|
tmp_dict = dict()
|
||||||
|
@ -1786,36 +1787,39 @@ class AaaServerHost(object):
|
||||||
result["hwtacacs_server_cfg_ipv6"].append(tmp_dict)
|
result["hwtacacs_server_cfg_ipv6"].append(tmp_dict)
|
||||||
|
|
||||||
if result["hwtacacs_server_cfg_ipv6"]:
|
if result["hwtacacs_server_cfg_ipv6"]:
|
||||||
for tmp in result["hwtacacs_server_cfg_ipv6"]:
|
cfg = dict()
|
||||||
if "serverIpAddress" in tmp.keys():
|
config_list = list()
|
||||||
if state == "present":
|
|
||||||
if tmp["serverIpAddress"] != hwtacacs_server_ipv6:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["serverIpAddress"] == hwtacacs_server_ipv6:
|
|
||||||
need_cfg = True
|
|
||||||
if "serverType" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["serverType"] != hwtacacs_server_type:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["serverType"] == hwtacacs_server_type:
|
|
||||||
need_cfg = True
|
|
||||||
if "isSecondaryServer" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["isSecondaryServer"] != str(hwtacacs_is_secondary_server).lower():
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["isSecondaryServer"] == str(hwtacacs_is_secondary_server).lower():
|
|
||||||
need_cfg = True
|
|
||||||
if "vpnName" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["vpnName"] != hwtacacs_vpn_name:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["vpnName"] == hwtacacs_vpn_name:
|
|
||||||
need_cfg = True
|
|
||||||
|
|
||||||
|
if hwtacacs_server_ipv6:
|
||||||
|
cfg["serverIpAddress"] = hwtacacs_server_ipv6.lower()
|
||||||
|
if hwtacacs_server_type:
|
||||||
|
cfg["serverType"] = hwtacacs_server_type.lower()
|
||||||
|
if hwtacacs_is_secondary_server:
|
||||||
|
cfg["isSecondaryServer"] = str(hwtacacs_is_secondary_server).lower()
|
||||||
|
if hwtacacs_vpn_name:
|
||||||
|
cfg["vpnName"] = hwtacacs_vpn_name.lower()
|
||||||
|
|
||||||
|
for tmp in result["hwtacacs_server_cfg_ipv6"]:
|
||||||
|
exist_cfg = dict()
|
||||||
|
if hwtacacs_server_ipv6:
|
||||||
|
exist_cfg["serverIpAddress"] = tmp.get("serverIpAddress").lower()
|
||||||
|
if hwtacacs_server_type:
|
||||||
|
exist_cfg["serverType"] = tmp.get("serverType").lower()
|
||||||
|
if hwtacacs_is_secondary_server:
|
||||||
|
exist_cfg["isSecondaryServer"] = tmp.get("isSecondaryServer").lower()
|
||||||
|
if hwtacacs_vpn_name:
|
||||||
|
exist_cfg["vpnName"] = tmp.get("vpnName").lower()
|
||||||
|
config_list.append(exist_cfg)
|
||||||
|
if cfg in config_list:
|
||||||
|
if state == "present":
|
||||||
|
need_cfg = False
|
||||||
|
else:
|
||||||
|
need_cfg = True
|
||||||
|
else:
|
||||||
|
if state == "present":
|
||||||
|
need_cfg = True
|
||||||
|
else:
|
||||||
|
need_cfg = False
|
||||||
result["need_cfg"] = need_cfg
|
result["need_cfg"] = need_cfg
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -1967,7 +1971,7 @@ class AaaServerHost(object):
|
||||||
|
|
||||||
root = ElementTree.fromstring(xml_str)
|
root = ElementTree.fromstring(xml_str)
|
||||||
hwtacacs_server_name_cfg = root.findall(
|
hwtacacs_server_name_cfg = root.findall(
|
||||||
"data/hwtacacs/hwTacTempCfgs/hwTacTempCfg/hwTacHostSrvCfgs/hwTacHostSrvCfg")
|
"hwtacacs/hwTacTempCfgs/hwTacTempCfg/hwTacHostSrvCfgs/hwTacHostSrvCfg")
|
||||||
if hwtacacs_server_name_cfg:
|
if hwtacacs_server_name_cfg:
|
||||||
for tmp in hwtacacs_server_name_cfg:
|
for tmp in hwtacacs_server_name_cfg:
|
||||||
tmp_dict = dict()
|
tmp_dict = dict()
|
||||||
|
@ -1978,43 +1982,43 @@ class AaaServerHost(object):
|
||||||
result["hwtacacs_server_name_cfg"].append(tmp_dict)
|
result["hwtacacs_server_name_cfg"].append(tmp_dict)
|
||||||
|
|
||||||
if result["hwtacacs_server_name_cfg"]:
|
if result["hwtacacs_server_name_cfg"]:
|
||||||
for tmp in result["hwtacacs_server_name_cfg"]:
|
cfg = dict()
|
||||||
if "serverHostName" in tmp.keys():
|
config_list = list()
|
||||||
if state == "present":
|
|
||||||
if tmp["serverHostName"] != hwtacacs_server_host_name:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["serverHostName"] == hwtacacs_server_host_name:
|
|
||||||
need_cfg = True
|
|
||||||
if "serverType" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["serverType"] != hwtacacs_server_type:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["serverType"] == hwtacacs_server_type:
|
|
||||||
need_cfg = True
|
|
||||||
if "isSecondaryServer" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["isSecondaryServer"] != str(hwtacacs_is_secondary_server).lower():
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["isSecondaryServer"] == str(hwtacacs_is_secondary_server).lower():
|
|
||||||
need_cfg = True
|
|
||||||
if "isPublicNet" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["isPublicNet"] != str(hwtacacs_is_public_net).lower():
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["isPublicNet"] == str(hwtacacs_is_public_net).lower():
|
|
||||||
need_cfg = True
|
|
||||||
if "vpnName" in tmp.keys():
|
|
||||||
if state == "present":
|
|
||||||
if tmp["vpnName"] != hwtacacs_vpn_name:
|
|
||||||
need_cfg = True
|
|
||||||
else:
|
|
||||||
if tmp["vpnName"] == hwtacacs_vpn_name:
|
|
||||||
need_cfg = True
|
|
||||||
|
|
||||||
|
if hwtacacs_server_host_name:
|
||||||
|
cfg["serverHostName"] = hwtacacs_server_host_name.lower()
|
||||||
|
if hwtacacs_server_type:
|
||||||
|
cfg["serverType"] = hwtacacs_server_type.lower()
|
||||||
|
if hwtacacs_is_secondary_server:
|
||||||
|
cfg["isSecondaryServer"] = str(hwtacacs_is_secondary_server).lower()
|
||||||
|
if hwtacacs_is_public_net:
|
||||||
|
cfg["isPublicNet"] = str(hwtacacs_is_public_net).lower()
|
||||||
|
if hwtacacs_vpn_name:
|
||||||
|
cfg["vpnName"] = hwtacacs_vpn_name.lower()
|
||||||
|
|
||||||
|
for tmp in result["hwtacacs_server_name_cfg"]:
|
||||||
|
exist_cfg = dict()
|
||||||
|
if hwtacacs_server_host_name:
|
||||||
|
exist_cfg["serverHostName"] = tmp.get("serverHostName").lower()
|
||||||
|
if hwtacacs_server_type:
|
||||||
|
exist_cfg["serverType"] = tmp.get("serverType").lower()
|
||||||
|
if hwtacacs_is_secondary_server:
|
||||||
|
exist_cfg["isSecondaryServer"] = tmp.get("isSecondaryServer").lower()
|
||||||
|
if hwtacacs_is_public_net:
|
||||||
|
exist_cfg["isPublicNet"] = tmp.get("isPublicNet").lower()
|
||||||
|
if hwtacacs_vpn_name:
|
||||||
|
exist_cfg["vpnName"] = tmp.get("vpnName").lower()
|
||||||
|
config_list.append(exist_cfg)
|
||||||
|
if cfg in config_list:
|
||||||
|
if state == "present":
|
||||||
|
need_cfg = False
|
||||||
|
else:
|
||||||
|
need_cfg = True
|
||||||
|
else:
|
||||||
|
if state == "present":
|
||||||
|
need_cfg = True
|
||||||
|
else:
|
||||||
|
need_cfg = False
|
||||||
result["need_cfg"] = need_cfg
|
result["need_cfg"] = need_cfg
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ DOCUMENTATION = """
|
||||||
|
|
||||||
module: ce_command
|
module: ce_command
|
||||||
version_added: "2.3"
|
version_added: "2.3"
|
||||||
author: "JackyGao2016 (@JackyGao2016)"
|
author: "JackyGao2016 (@CloudEngine-Ansible)"
|
||||||
short_description: Run arbitrary command on HUAWEI CloudEngine devices.
|
short_description: Run arbitrary command on HUAWEI CloudEngine devices.
|
||||||
description:
|
description:
|
||||||
- Sends an arbitrary command to an HUAWEI CloudEngine node and returns
|
- Sends an arbitrary command to an HUAWEI CloudEngine node and returns
|
||||||
|
@ -168,7 +168,7 @@ def parse_commands(module, warnings):
|
||||||
command=dict(key=True),
|
command=dict(key=True),
|
||||||
output=dict(),
|
output=dict(),
|
||||||
prompt=dict(),
|
prompt=dict(),
|
||||||
response=dict()
|
answer=dict()
|
||||||
), module)
|
), module)
|
||||||
|
|
||||||
commands = transform(module.params['commands'])
|
commands = transform(module.params['commands'])
|
||||||
|
|
|
@ -224,6 +224,7 @@ from ansible.module_utils.network.common.config import NetworkConfig, dumps
|
||||||
from ansible.module_utils.network.cloudengine.ce import get_config, load_config, run_commands
|
from ansible.module_utils.network.cloudengine.ce import get_config, load_config, run_commands
|
||||||
from ansible.module_utils.network.cloudengine.ce import ce_argument_spec
|
from ansible.module_utils.network.cloudengine.ce import ce_argument_spec
|
||||||
from ansible.module_utils.network.cloudengine.ce import check_args as ce_check_args
|
from ansible.module_utils.network.cloudengine.ce import check_args as ce_check_args
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
def check_args(module, warnings):
|
def check_args(module, warnings):
|
||||||
|
@ -240,10 +241,45 @@ def get_running_config(module):
|
||||||
return NetworkConfig(indent=1, contents=contents)
|
return NetworkConfig(indent=1, contents=contents)
|
||||||
|
|
||||||
|
|
||||||
|
def conversion_src(module):
|
||||||
|
src_list = module.params['src'].split('\n')
|
||||||
|
src_list_organize = []
|
||||||
|
exit_list = [' return', ' system-view']
|
||||||
|
if src_list[0].strip() == '#':
|
||||||
|
src_list.pop(0)
|
||||||
|
for per_config in src_list:
|
||||||
|
if per_config.strip() == '#':
|
||||||
|
if per_config.rstrip() == '#':
|
||||||
|
src_list_organize.extend(exit_list)
|
||||||
|
else:
|
||||||
|
src_list_organize.append('quit')
|
||||||
|
else:
|
||||||
|
src_list_organize.append(per_config)
|
||||||
|
src_str = '\n'.join(src_list_organize)
|
||||||
|
return src_str
|
||||||
|
|
||||||
|
|
||||||
|
def conversion_lines(commands):
|
||||||
|
all_config = []
|
||||||
|
exit_list = [' return', ' system-view']
|
||||||
|
for per_command in commands:
|
||||||
|
if re.search(r',', per_command):
|
||||||
|
all_config.extend(exit_list)
|
||||||
|
per_config = per_command.split(',')
|
||||||
|
for config in per_config:
|
||||||
|
if config:
|
||||||
|
all_config.append(config)
|
||||||
|
all_config.extend(exit_list)
|
||||||
|
else:
|
||||||
|
all_config.append(per_command)
|
||||||
|
return all_config
|
||||||
|
|
||||||
|
|
||||||
def get_candidate(module):
|
def get_candidate(module):
|
||||||
candidate = NetworkConfig(indent=1)
|
candidate = NetworkConfig(indent=1)
|
||||||
if module.params['src']:
|
if module.params['src']:
|
||||||
candidate.load(module.params['src'])
|
config = conversion_src(module)
|
||||||
|
candidate.load(config)
|
||||||
elif module.params['lines']:
|
elif module.params['lines']:
|
||||||
parents = module.params['parents'] or list()
|
parents = module.params['parents'] or list()
|
||||||
candidate.add(module.params['lines'], parents=parents)
|
candidate.add(module.params['lines'], parents=parents)
|
||||||
|
@ -253,7 +289,6 @@ def get_candidate(module):
|
||||||
def run(module, result):
|
def run(module, result):
|
||||||
match = module.params['match']
|
match = module.params['match']
|
||||||
replace = module.params['replace']
|
replace = module.params['replace']
|
||||||
|
|
||||||
candidate = get_candidate(module)
|
candidate = get_candidate(module)
|
||||||
|
|
||||||
if match != 'none':
|
if match != 'none':
|
||||||
|
@ -265,21 +300,27 @@ def run(module, result):
|
||||||
|
|
||||||
if configobjs:
|
if configobjs:
|
||||||
commands = dumps(configobjs, 'commands').split('\n')
|
commands = dumps(configobjs, 'commands').split('\n')
|
||||||
|
|
||||||
if module.params['lines']:
|
if module.params['lines']:
|
||||||
|
|
||||||
|
commands = conversion_lines(commands)
|
||||||
|
|
||||||
if module.params['before']:
|
if module.params['before']:
|
||||||
commands[:0] = module.params['before']
|
commands[:0] = module.params['before']
|
||||||
|
|
||||||
if module.params['after']:
|
if module.params['after']:
|
||||||
commands.extend(module.params['after'])
|
commands.extend(module.params['after'])
|
||||||
|
|
||||||
result['commands'] = commands
|
command_display = []
|
||||||
result['updates'] = commands
|
for per_command in commands:
|
||||||
|
if per_command.strip() not in ['quit', 'return', 'system-view']:
|
||||||
|
command_display.append(per_command)
|
||||||
|
|
||||||
|
result['commands'] = command_display
|
||||||
|
result['updates'] = command_display
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
load_config(module, commands)
|
load_config(module, commands)
|
||||||
|
if result['commands']:
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -205,11 +205,14 @@ class Default(FactsBase):
|
||||||
data = self.responses[0]
|
data = self.responses[0]
|
||||||
if data:
|
if data:
|
||||||
version = data.split("\n")
|
version = data.split("\n")
|
||||||
tmp_version = version[11:]
|
for item in version:
|
||||||
for item in tmp_version:
|
if re.findall(r"^\d+\S\s+", item.strip()):
|
||||||
tmp_item = item.split()
|
tmp_item = item.split()
|
||||||
tmp_key = tmp_item[1] + " " + tmp_item[2]
|
tmp_key = tmp_item[1] + " " + tmp_item[2]
|
||||||
self.facts[tmp_key] = tmp_item[4]
|
if len(tmp_item) > 5:
|
||||||
|
self.facts[tmp_key] = " ".join(tmp_item[4:])
|
||||||
|
else:
|
||||||
|
self.facts[tmp_key] = tmp_item[4]
|
||||||
|
|
||||||
data = self.responses[1]
|
data = self.responses[1]
|
||||||
if data:
|
if data:
|
||||||
|
@ -293,12 +296,17 @@ class Interfaces(FactsBase):
|
||||||
super(Interfaces, self).populate()
|
super(Interfaces, self).populate()
|
||||||
|
|
||||||
data = self.responses[0]
|
data = self.responses[0]
|
||||||
|
begin = False
|
||||||
if data:
|
if data:
|
||||||
interface_info = data.split("\n")
|
interface_info = data.split("\n")
|
||||||
tmp_interface = interface_info[12:]
|
for item in interface_info:
|
||||||
for item in tmp_interface:
|
if begin:
|
||||||
tmp_item = item.split()
|
tmp_item = item.split()
|
||||||
interface_dict[tmp_item[0]] = tmp_item[1]
|
interface_dict[tmp_item[0]] = tmp_item[1]
|
||||||
|
|
||||||
|
if re.findall(r"^Interface", item.strip()):
|
||||||
|
begin = True
|
||||||
|
|
||||||
self.facts['interfaces'] = interface_dict
|
self.facts['interfaces'] = interface_dict
|
||||||
|
|
||||||
data = self.responses[1]
|
data = self.responses[1]
|
||||||
|
|
|
@ -180,7 +180,7 @@ def main():
|
||||||
if "<data/>" in response:
|
if "<data/>" in response:
|
||||||
end_state["result"] = "<data/>"
|
end_state["result"] = "<data/>"
|
||||||
else:
|
else:
|
||||||
tmp1 = response.xml.split(r"<data>")
|
tmp1 = response.split(r"<data>")
|
||||||
tmp2 = tmp1[1].split(r"</data>")
|
tmp2 = tmp1[1].split(r"</data>")
|
||||||
result = tmp2[0].split("\n")
|
result = tmp2[0].split("\n")
|
||||||
|
|
||||||
|
|
|
@ -384,13 +384,17 @@ class Vlan(object):
|
||||||
if "<data/>" in xml_str:
|
if "<data/>" in xml_str:
|
||||||
return attr
|
return attr
|
||||||
else:
|
else:
|
||||||
re_find = re.findall(r'.*<vlanId>(.*)</vlanId>.*\s*'
|
re_find_id = re.findall(r'.*<vlanId>(.*)</vlanId>.*\s*', xml_str)
|
||||||
r'<vlanName>(.*)</vlanName>.*\s*'
|
re_find_name = re.findall(r'.*<vlanName>(.*)</vlanName>.*\s*', xml_str)
|
||||||
r'<vlanDesc>(.*)</vlanDesc>.*', xml_str)
|
re_find_desc = re.findall(r'.*<vlanDesc>(.*)</vlanDesc>.*\s*', xml_str)
|
||||||
if re_find:
|
|
||||||
attr = dict(vlan_id=re_find[0][0], name=re_find[0][1],
|
|
||||||
description=re_find[0][2])
|
|
||||||
|
|
||||||
|
if re_find_id:
|
||||||
|
if re_find_name:
|
||||||
|
attr = dict(vlan_id=re_find_id[0], name=re_find_name[0],
|
||||||
|
description=re_find_desc[0])
|
||||||
|
else:
|
||||||
|
attr = dict(vlan_id=re_find_id[0], name=None,
|
||||||
|
description=re_find_desc[0])
|
||||||
return attr
|
return attr
|
||||||
|
|
||||||
def get_vlans_name(self):
|
def get_vlans_name(self):
|
||||||
|
@ -477,7 +481,7 @@ class Vlan(object):
|
||||||
if tagged_vlans <= 0 or tagged_vlans > 4094:
|
if tagged_vlans <= 0 or tagged_vlans > 4094:
|
||||||
self.module.fail_json(
|
self.module.fail_json(
|
||||||
msg='Error: Vlan id is not in the range from 1 to 4094.')
|
msg='Error: Vlan id is not in the range from 1 to 4094.')
|
||||||
j = tagged_vlans / 4
|
j = tagged_vlans // 4
|
||||||
bit_int[j] |= 0x8 >> (tagged_vlans % 4)
|
bit_int[j] |= 0x8 >> (tagged_vlans % 4)
|
||||||
vlan_bit[j] = hex(bit_int[j])[2]
|
vlan_bit[j] = hex(bit_int[j])[2]
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ from ansible.utils.display import Display
|
||||||
|
|
||||||
display = Display()
|
display = Display()
|
||||||
|
|
||||||
CLI_SUPPORTED_MODULES = ['ce_config', 'ce_command']
|
CLI_SUPPORTED_MODULES = ['ce_config', 'ce_command', 'ce_facts']
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(ActionNetworkModule):
|
class ActionModule(ActionNetworkModule):
|
||||||
|
@ -89,7 +89,7 @@ class ActionModule(ActionNetworkModule):
|
||||||
out = conn.get_prompt()
|
out = conn.get_prompt()
|
||||||
while to_text(out, errors='surrogate_then_replace').strip().endswith(']'):
|
while to_text(out, errors='surrogate_then_replace').strip().endswith(']'):
|
||||||
display.vvvv('wrong context, sending exit to device', self._play_context.remote_addr)
|
display.vvvv('wrong context, sending exit to device', self._play_context.remote_addr)
|
||||||
conn.send_command('exit')
|
conn.exec_command('return')
|
||||||
out = conn.get_prompt()
|
out = conn.get_prompt()
|
||||||
|
|
||||||
result = super(ActionModule, self).run(task_vars=task_vars)
|
result = super(ActionModule, self).run(task_vars=task_vars)
|
||||||
|
|
Loading…
Reference in a new issue