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):
|
||||
return re.sub(r'<data.+?(/>|>)', r'<data\1', data)
|
||||
return re.sub(r'<data\s+.+?(/>|>)', r'<data\1', data)
|
||||
|
||||
|
||||
def check_args(module, warnings):
|
||||
|
@ -164,12 +164,11 @@ class Cli:
|
|||
responses = list()
|
||||
|
||||
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:
|
||||
self._module.fail_json(msg=cli_err_msg(cmd.strip(), err))
|
||||
self._module.fail_json(msg=cli_err_msg(item['command'].strip(), err))
|
||||
|
||||
try:
|
||||
out = self._module.from_json(out)
|
||||
|
@ -234,7 +233,7 @@ def to_command(module, commands):
|
|||
command=dict(key=True),
|
||||
output=dict(default=default_output),
|
||||
prompt=dict(),
|
||||
response=dict()
|
||||
answer=dict()
|
||||
), module)
|
||||
|
||||
commands = transform(to_list(commands))
|
||||
|
|
|
@ -46,6 +46,7 @@ options:
|
|||
- Preferred authentication mode.
|
||||
type: str
|
||||
choices: ['invalid', 'local', 'hwtacacs', 'radius', 'none']
|
||||
default: local
|
||||
author_scheme_name:
|
||||
description:
|
||||
- Name of an authorization scheme.
|
||||
|
@ -56,6 +57,7 @@ options:
|
|||
- Preferred authorization mode.
|
||||
type: str
|
||||
choices: ['invalid', 'local', 'hwtacacs', 'if-authenticated', 'none']
|
||||
default: local
|
||||
acct_scheme_name:
|
||||
description:
|
||||
- Accounting scheme name.
|
||||
|
@ -66,6 +68,7 @@ options:
|
|||
- Accounting Mode.
|
||||
type: str
|
||||
choices: ['invalid', 'hwtacacs', 'radius', 'none']
|
||||
default: none
|
||||
domain_name:
|
||||
description:
|
||||
- Name of a domain.
|
||||
|
@ -762,16 +765,15 @@ class AaaServer(object):
|
|||
conf_str = CE_GET_AUTHENTICATION_SCHEME
|
||||
|
||||
xml_str = self.netconf_get_config(module=module, conf_str=conf_str)
|
||||
|
||||
result = list()
|
||||
|
||||
if "<data/>" in xml_str:
|
||||
return result
|
||||
else:
|
||||
re_find = re.findall(
|
||||
r'.*<firstAuthenMode>(.*)</firstAuthenMode>.*\s*'
|
||||
r'<secondAuthenMode>(.*)</secondAuthenMode>.*\s*'
|
||||
r'<authenSchemeName>(.*)</authenSchemeName>.*', xml_str)
|
||||
r'.*<authenSchemeName>(.*)</authenSchemeName>.*\s*'
|
||||
r'<firstAuthenMode>(.*)</firstAuthenMode>.*\s*'
|
||||
r'<secondAuthenMode>(.*)</secondAuthenMode>.*\s*', xml_str)
|
||||
|
||||
if re_find:
|
||||
return re_find
|
||||
|
@ -947,16 +949,15 @@ class AaaServer(object):
|
|||
conf_str = CE_GET_AUTHORIZATION_SCHEME
|
||||
|
||||
xml_str = self.netconf_get_config(module=module, conf_str=conf_str)
|
||||
|
||||
result = list()
|
||||
|
||||
if "<data/>" in xml_str:
|
||||
return result
|
||||
else:
|
||||
re_find = re.findall(
|
||||
r'.*<firstAuthorMode>(.*)</firstAuthorMode>.*\s*'
|
||||
r'<secondAuthorMode>(.*)</secondAuthorMode>.*\s*'
|
||||
r'<authorSchemeName>(.*)</authorSchemeName>.*', xml_str)
|
||||
r'.*<authorSchemeName>(.*)</authorSchemeName>.*\s*'
|
||||
r'<firstAuthorMode>(.*)</firstAuthorMode>.*\s*'
|
||||
r'<secondAuthorMode>(.*)</secondAuthorMode>.*\s*', xml_str)
|
||||
|
||||
if re_find:
|
||||
return re_find
|
||||
|
@ -1132,16 +1133,12 @@ class AaaServer(object):
|
|||
conf_str = CE_GET_ACCOUNTING_SCHEME
|
||||
|
||||
xml_str = self.netconf_get_config(module=module, conf_str=conf_str)
|
||||
|
||||
result = list()
|
||||
|
||||
if "<data/>" in xml_str:
|
||||
return result
|
||||
else:
|
||||
re_find = re.findall(
|
||||
r'.*<accountingMode>(.*)</accountingMode>.*\s*'
|
||||
r'<acctSchemeName>(.*)</acctSchemeName>.*', xml_str)
|
||||
|
||||
re_find = re.findall(r'.*<acctSchemeName>(.*)</acctSchemeName>\s*<accountingMode>(.*)</accountingMode>', xml_str)
|
||||
if re_find:
|
||||
return re_find
|
||||
else:
|
||||
|
@ -1676,25 +1673,20 @@ def check_module_argument(**kwargs):
|
|||
module.fail_json(
|
||||
msg='Error: local_user_group %s '
|
||||
'is large than 32.' % local_user_group)
|
||||
check_name(module=module, name=local_user_group,
|
||||
invalid_char=INVALID_GROUP_CHAR)
|
||||
check_name(module=module, name=local_user_group, invalid_char=INVALID_GROUP_CHAR)
|
||||
|
||||
|
||||
def main():
|
||||
""" Module main """
|
||||
|
||||
argument_spec = dict(
|
||||
state=dict(choices=['present', 'absent'],
|
||||
default='present'),
|
||||
state=dict(choices=['present', 'absent'], default='present'),
|
||||
authen_scheme_name=dict(type='str'),
|
||||
first_authen_mode=dict(choices=['invalid', 'local',
|
||||
'hwtacacs', 'radius', 'none']),
|
||||
first_authen_mode=dict(default='local', choices=['invalid', 'local', 'hwtacacs', 'radius', 'none']),
|
||||
author_scheme_name=dict(type='str'),
|
||||
first_author_mode=dict(choices=['invalid', 'local',
|
||||
'hwtacacs', 'if-authenticated', 'none']),
|
||||
first_author_mode=dict(default='local', choices=['invalid', 'local', 'hwtacacs', 'if-authenticated', 'none']),
|
||||
acct_scheme_name=dict(type='str'),
|
||||
accounting_mode=dict(choices=['invalid', 'hwtacacs',
|
||||
'radius', 'none']),
|
||||
accounting_mode=dict(default='none', choices=['invalid', 'hwtacacs', 'radius', 'none']),
|
||||
domain_name=dict(type='str'),
|
||||
radius_server_group=dict(type='str'),
|
||||
hwtacas_template=dict(type='str'),
|
||||
|
@ -1758,8 +1750,7 @@ def main():
|
|||
if authen_scheme_name:
|
||||
|
||||
scheme_exist = ce_aaa_server.get_authentication_scheme(module=module)
|
||||
scheme_new = (first_authen_mode.lower(), "invalid",
|
||||
authen_scheme_name.lower())
|
||||
scheme_new = (authen_scheme_name.lower(), first_authen_mode.lower(), "invalid")
|
||||
|
||||
existing["authentication scheme"] = scheme_exist
|
||||
|
||||
|
@ -1843,8 +1834,7 @@ def main():
|
|||
if author_scheme_name:
|
||||
|
||||
scheme_exist = ce_aaa_server.get_authorization_scheme(module=module)
|
||||
scheme_new = (first_author_mode.lower(), "invalid",
|
||||
author_scheme_name.lower())
|
||||
scheme_new = (author_scheme_name.lower(), first_author_mode.lower(), "invalid")
|
||||
|
||||
existing["authorization scheme"] = scheme_exist
|
||||
|
||||
|
@ -1925,7 +1915,7 @@ def main():
|
|||
if acct_scheme_name:
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -788,7 +788,7 @@ class AaaServerHost(object):
|
|||
replace('xmlns="http://www.huawei.com/netconf/vrp"', "")
|
||||
|
||||
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:
|
||||
for tmp in local_user_info:
|
||||
tmp_dict = dict()
|
||||
|
@ -1042,7 +1042,7 @@ class AaaServerHost(object):
|
|||
|
||||
root = ElementTree.fromstring(xml_str)
|
||||
radius_server_ip_v4 = root.findall(
|
||||
"data/radius/rdsTemplates/rdsTemplate/rdsServerIPV4s/rdsServerIPV4")
|
||||
"radius/rdsTemplates/rdsTemplate/rdsServerIPV4s/rdsServerIPV4")
|
||||
if radius_server_ip_v4:
|
||||
for tmp in radius_server_ip_v4:
|
||||
tmp_dict = dict()
|
||||
|
@ -1053,43 +1053,42 @@ class AaaServerHost(object):
|
|||
result["radius_server_ip_v4"].append(tmp_dict)
|
||||
|
||||
if result["radius_server_ip_v4"]:
|
||||
for tmp in result["radius_server_ip_v4"]:
|
||||
if "serverType" in tmp.keys():
|
||||
if state == "present":
|
||||
if tmp["serverType"] != radius_server_type:
|
||||
need_cfg = True
|
||||
else:
|
||||
if tmp["serverType"] == radius_server_type:
|
||||
need_cfg = True
|
||||
if "serverIPAddress" in tmp.keys():
|
||||
if state == "present":
|
||||
if tmp["serverIPAddress"] != radius_server_ip:
|
||||
need_cfg = True
|
||||
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
|
||||
cfg = dict()
|
||||
config_list = list()
|
||||
if radius_server_type:
|
||||
cfg["serverType"] = radius_server_type.lower()
|
||||
if radius_server_ip:
|
||||
cfg["serverIPAddress"] = radius_server_ip.lower()
|
||||
if radius_server_port:
|
||||
cfg["serverPort"] = radius_server_port.lower()
|
||||
if radius_server_mode:
|
||||
cfg["serverMode"] = radius_server_mode.lower()
|
||||
if radius_vpn_name:
|
||||
cfg["vpnName"] = radius_vpn_name.lower()
|
||||
|
||||
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
|
||||
return result
|
||||
|
||||
|
@ -1221,7 +1220,7 @@ class AaaServerHost(object):
|
|||
|
||||
root = ElementTree.fromstring(xml_str)
|
||||
radius_server_ip_v6 = root.findall(
|
||||
"data/radius/rdsTemplates/rdsTemplate/rdsServerIPV6s/rdsServerIPV6")
|
||||
"radius/rdsTemplates/rdsTemplate/rdsServerIPV6s/rdsServerIPV6")
|
||||
if radius_server_ip_v6:
|
||||
for tmp in radius_server_ip_v6:
|
||||
tmp_dict = dict()
|
||||
|
@ -1232,35 +1231,38 @@ class AaaServerHost(object):
|
|||
result["radius_server_ip_v6"].append(tmp_dict)
|
||||
|
||||
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"]:
|
||||
if "serverType" in tmp.keys():
|
||||
if state == "present":
|
||||
if tmp["serverType"] != radius_server_type:
|
||||
need_cfg = True
|
||||
else:
|
||||
if tmp["serverType"] == radius_server_type:
|
||||
need_cfg = True
|
||||
if "serverIPAddress" in tmp.keys():
|
||||
if state == "present":
|
||||
if tmp["serverIPAddress"] != radius_server_ipv6:
|
||||
need_cfg = True
|
||||
else:
|
||||
if tmp["serverIPAddress"] == radius_server_ipv6:
|
||||
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
|
||||
exist_cfg = dict()
|
||||
if radius_server_type:
|
||||
exist_cfg["serverType"] = tmp.get("serverType").lower()
|
||||
if radius_server_ipv6:
|
||||
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()
|
||||
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
|
||||
return result
|
||||
|
@ -1380,7 +1382,7 @@ class AaaServerHost(object):
|
|||
|
||||
root = ElementTree.fromstring(xml_str)
|
||||
radius_server_name_cfg = root.findall(
|
||||
"data/radius/rdsTemplates/rdsTemplate/rdsServerNames/rdsServerName")
|
||||
"radius/rdsTemplates/rdsTemplate/rdsServerNames/rdsServerName")
|
||||
if radius_server_name_cfg:
|
||||
for tmp in radius_server_name_cfg:
|
||||
tmp_dict = dict()
|
||||
|
@ -1391,43 +1393,42 @@ class AaaServerHost(object):
|
|||
result["radius_server_name_cfg"].append(tmp_dict)
|
||||
|
||||
if result["radius_server_name_cfg"]:
|
||||
for tmp in result["radius_server_name_cfg"]:
|
||||
if "serverType" in tmp.keys():
|
||||
if state == "present":
|
||||
if tmp["serverType"] != radius_server_type:
|
||||
need_cfg = True
|
||||
else:
|
||||
if tmp["serverType"] == radius_server_type:
|
||||
need_cfg = True
|
||||
if "serverName" in tmp.keys():
|
||||
if state == "present":
|
||||
if tmp["serverName"] != radius_server_name:
|
||||
need_cfg = True
|
||||
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
|
||||
cfg = dict()
|
||||
config_list = list()
|
||||
if radius_server_type:
|
||||
cfg["serverType"] = radius_server_type.lower()
|
||||
if radius_server_name:
|
||||
cfg["serverName"] = radius_server_name.lower()
|
||||
if radius_server_port:
|
||||
cfg["serverPort"] = radius_server_port.lower()
|
||||
if radius_server_mode:
|
||||
cfg["serverMode"] = radius_server_mode.lower()
|
||||
if radius_vpn_name:
|
||||
cfg["vpnName"] = radius_vpn_name.lower()
|
||||
|
||||
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
|
||||
return result
|
||||
|
||||
|
@ -1559,7 +1560,7 @@ class AaaServerHost(object):
|
|||
|
||||
root = ElementTree.fromstring(xml_str)
|
||||
hwtacacs_server_cfg_ipv4 = root.findall(
|
||||
"data/hwtacacs/hwTacTempCfgs/hwTacTempCfg/hwTacSrvCfgs/hwTacSrvCfg")
|
||||
"hwtacacs/hwTacTempCfgs/hwTacTempCfg/hwTacSrvCfgs/hwTacSrvCfg")
|
||||
if hwtacacs_server_cfg_ipv4:
|
||||
for tmp in hwtacacs_server_cfg_ipv4:
|
||||
tmp_dict = dict()
|
||||
|
@ -1570,43 +1571,43 @@ class AaaServerHost(object):
|
|||
result["hwtacacs_server_cfg_ipv4"].append(tmp_dict)
|
||||
|
||||
if result["hwtacacs_server_cfg_ipv4"]:
|
||||
for tmp in result["hwtacacs_server_cfg_ipv4"]:
|
||||
if "serverIpAddress" in tmp.keys():
|
||||
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
|
||||
cfg = dict()
|
||||
config_list = list()
|
||||
|
||||
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
|
||||
return result
|
||||
|
||||
|
@ -1775,7 +1776,7 @@ class AaaServerHost(object):
|
|||
|
||||
root = ElementTree.fromstring(xml_str)
|
||||
hwtacacs_server_cfg_ipv6 = root.findall(
|
||||
"data/hwtacacs/hwTacTempCfgs/hwTacTempCfg/hwTacIpv6SrvCfgs/hwTacIpv6SrvCfg")
|
||||
"hwtacacs/hwTacTempCfgs/hwTacTempCfg/hwTacIpv6SrvCfgs/hwTacIpv6SrvCfg")
|
||||
if hwtacacs_server_cfg_ipv6:
|
||||
for tmp in hwtacacs_server_cfg_ipv6:
|
||||
tmp_dict = dict()
|
||||
|
@ -1786,36 +1787,39 @@ class AaaServerHost(object):
|
|||
result["hwtacacs_server_cfg_ipv6"].append(tmp_dict)
|
||||
|
||||
if result["hwtacacs_server_cfg_ipv6"]:
|
||||
for tmp in result["hwtacacs_server_cfg_ipv6"]:
|
||||
if "serverIpAddress" in tmp.keys():
|
||||
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
|
||||
cfg = dict()
|
||||
config_list = list()
|
||||
|
||||
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
|
||||
return result
|
||||
|
||||
|
@ -1967,7 +1971,7 @@ class AaaServerHost(object):
|
|||
|
||||
root = ElementTree.fromstring(xml_str)
|
||||
hwtacacs_server_name_cfg = root.findall(
|
||||
"data/hwtacacs/hwTacTempCfgs/hwTacTempCfg/hwTacHostSrvCfgs/hwTacHostSrvCfg")
|
||||
"hwtacacs/hwTacTempCfgs/hwTacTempCfg/hwTacHostSrvCfgs/hwTacHostSrvCfg")
|
||||
if hwtacacs_server_name_cfg:
|
||||
for tmp in hwtacacs_server_name_cfg:
|
||||
tmp_dict = dict()
|
||||
|
@ -1978,43 +1982,43 @@ class AaaServerHost(object):
|
|||
result["hwtacacs_server_name_cfg"].append(tmp_dict)
|
||||
|
||||
if result["hwtacacs_server_name_cfg"]:
|
||||
for tmp in result["hwtacacs_server_name_cfg"]:
|
||||
if "serverHostName" in tmp.keys():
|
||||
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
|
||||
cfg = dict()
|
||||
config_list = list()
|
||||
|
||||
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
|
||||
return result
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ DOCUMENTATION = """
|
|||
|
||||
module: ce_command
|
||||
version_added: "2.3"
|
||||
author: "JackyGao2016 (@JackyGao2016)"
|
||||
author: "JackyGao2016 (@CloudEngine-Ansible)"
|
||||
short_description: Run arbitrary command on HUAWEI CloudEngine devices.
|
||||
description:
|
||||
- Sends an arbitrary command to an HUAWEI CloudEngine node and returns
|
||||
|
@ -168,7 +168,7 @@ def parse_commands(module, warnings):
|
|||
command=dict(key=True),
|
||||
output=dict(),
|
||||
prompt=dict(),
|
||||
response=dict()
|
||||
answer=dict()
|
||||
), module)
|
||||
|
||||
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 ce_argument_spec
|
||||
from ansible.module_utils.network.cloudengine.ce import check_args as ce_check_args
|
||||
import re
|
||||
|
||||
|
||||
def check_args(module, warnings):
|
||||
|
@ -240,10 +241,45 @@ def get_running_config(module):
|
|||
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):
|
||||
candidate = NetworkConfig(indent=1)
|
||||
if module.params['src']:
|
||||
candidate.load(module.params['src'])
|
||||
config = conversion_src(module)
|
||||
candidate.load(config)
|
||||
elif module.params['lines']:
|
||||
parents = module.params['parents'] or list()
|
||||
candidate.add(module.params['lines'], parents=parents)
|
||||
|
@ -253,7 +289,6 @@ def get_candidate(module):
|
|||
def run(module, result):
|
||||
match = module.params['match']
|
||||
replace = module.params['replace']
|
||||
|
||||
candidate = get_candidate(module)
|
||||
|
||||
if match != 'none':
|
||||
|
@ -265,21 +300,27 @@ def run(module, result):
|
|||
|
||||
if configobjs:
|
||||
commands = dumps(configobjs, 'commands').split('\n')
|
||||
|
||||
if module.params['lines']:
|
||||
|
||||
commands = conversion_lines(commands)
|
||||
|
||||
if module.params['before']:
|
||||
commands[:0] = module.params['before']
|
||||
|
||||
if module.params['after']:
|
||||
commands.extend(module.params['after'])
|
||||
|
||||
result['commands'] = commands
|
||||
result['updates'] = commands
|
||||
command_display = []
|
||||
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:
|
||||
load_config(module, commands)
|
||||
|
||||
result['changed'] = True
|
||||
if result['commands']:
|
||||
result['changed'] = True
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
@ -205,11 +205,14 @@ class Default(FactsBase):
|
|||
data = self.responses[0]
|
||||
if data:
|
||||
version = data.split("\n")
|
||||
tmp_version = version[11:]
|
||||
for item in tmp_version:
|
||||
tmp_item = item.split()
|
||||
tmp_key = tmp_item[1] + " " + tmp_item[2]
|
||||
self.facts[tmp_key] = tmp_item[4]
|
||||
for item in version:
|
||||
if re.findall(r"^\d+\S\s+", item.strip()):
|
||||
tmp_item = item.split()
|
||||
tmp_key = tmp_item[1] + " " + tmp_item[2]
|
||||
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]
|
||||
if data:
|
||||
|
@ -293,12 +296,17 @@ class Interfaces(FactsBase):
|
|||
super(Interfaces, self).populate()
|
||||
|
||||
data = self.responses[0]
|
||||
begin = False
|
||||
if data:
|
||||
interface_info = data.split("\n")
|
||||
tmp_interface = interface_info[12:]
|
||||
for item in tmp_interface:
|
||||
tmp_item = item.split()
|
||||
interface_dict[tmp_item[0]] = tmp_item[1]
|
||||
for item in interface_info:
|
||||
if begin:
|
||||
tmp_item = item.split()
|
||||
interface_dict[tmp_item[0]] = tmp_item[1]
|
||||
|
||||
if re.findall(r"^Interface", item.strip()):
|
||||
begin = True
|
||||
|
||||
self.facts['interfaces'] = interface_dict
|
||||
|
||||
data = self.responses[1]
|
||||
|
|
|
@ -180,7 +180,7 @@ def main():
|
|||
if "<data/>" in response:
|
||||
end_state["result"] = "<data/>"
|
||||
else:
|
||||
tmp1 = response.xml.split(r"<data>")
|
||||
tmp1 = response.split(r"<data>")
|
||||
tmp2 = tmp1[1].split(r"</data>")
|
||||
result = tmp2[0].split("\n")
|
||||
|
||||
|
|
|
@ -384,13 +384,17 @@ class Vlan(object):
|
|||
if "<data/>" in xml_str:
|
||||
return attr
|
||||
else:
|
||||
re_find = re.findall(r'.*<vlanId>(.*)</vlanId>.*\s*'
|
||||
r'<vlanName>(.*)</vlanName>.*\s*'
|
||||
r'<vlanDesc>(.*)</vlanDesc>.*', xml_str)
|
||||
if re_find:
|
||||
attr = dict(vlan_id=re_find[0][0], name=re_find[0][1],
|
||||
description=re_find[0][2])
|
||||
re_find_id = re.findall(r'.*<vlanId>(.*)</vlanId>.*\s*', xml_str)
|
||||
re_find_name = re.findall(r'.*<vlanName>(.*)</vlanName>.*\s*', xml_str)
|
||||
re_find_desc = re.findall(r'.*<vlanDesc>(.*)</vlanDesc>.*\s*', xml_str)
|
||||
|
||||
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
|
||||
|
||||
def get_vlans_name(self):
|
||||
|
@ -477,7 +481,7 @@ class Vlan(object):
|
|||
if tagged_vlans <= 0 or tagged_vlans > 4094:
|
||||
self.module.fail_json(
|
||||
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)
|
||||
vlan_bit[j] = hex(bit_int[j])[2]
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ from ansible.utils.display import Display
|
|||
|
||||
display = Display()
|
||||
|
||||
CLI_SUPPORTED_MODULES = ['ce_config', 'ce_command']
|
||||
CLI_SUPPORTED_MODULES = ['ce_config', 'ce_command', 'ce_facts']
|
||||
|
||||
|
||||
class ActionModule(ActionNetworkModule):
|
||||
|
@ -89,7 +89,7 @@ class ActionModule(ActionNetworkModule):
|
|||
out = conn.get_prompt()
|
||||
while to_text(out, errors='surrogate_then_replace').strip().endswith(']'):
|
||||
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()
|
||||
|
||||
result = super(ActionModule, self).run(task_vars=task_vars)
|
||||
|
|
Loading…
Reference in a new issue