diff --git a/plugins/module_utils/network/vyos/config/vrrp/vrrp.py b/plugins/module_utils/network/vyos/config/vrrp/vrrp.py index 16a9d1cc..5a0a3c8d 100644 --- a/plugins/module_utils/network/vyos/config/vrrp/vrrp.py +++ b/plugins/module_utils/network/vyos/config/vrrp/vrrp.py @@ -1,372 +1,482 @@ # # -*- coding: utf-8 -*- # Copyright 2021 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # from __future__ import absolute_import, division, print_function __metaclass__ = type """ The vyos_vrrp config file. It is in this file where the current configuration (as dict) is compared to the provided configuration (as dict) and the command set necessary to bring the current configuration to its desired end-state is created. """ from copy import deepcopy from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.vrrp import ( VrrpTemplate, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import combine from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import ( LooseVersion, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version -# from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( # dict_merge, -# get_from_dict, -# ) - - class Vrrp(ResourceModule): """ The vyos_vrrp config class """ def __init__(self, module): super(Vrrp, self).__init__( empty_fact_val={}, facts_module=Facts(module), module=module, resource="vrrp", tmplt=VrrpTemplate(), ) self.parsers = [ "disable", ] def _validate_template(self): version = get_os_version(self._module) if LooseVersion(version) >= LooseVersion("1.4"): self._tmplt = VrrpTemplate() else: self._module.fail_json(msg="VRRP is not supported in this version of VyOS") def parse(self): """override parse to check template""" self._validate_template() return super().parse() def get_parser(self, name): """get_parsers""" self._validate_template() return super().get_parser(name) def execute_module(self): """Execute the module :rtype: A dictionary :returns: The result from module execution """ if self.state not in ["parsed", "gathered"]: self.generate_commands() self.run_commands() return self.result def generate_commands(self): """Generate configuration commands to send based on want, have and desired state. """ wantd = {} haved = {} wantd = deepcopy(self.want) haved = deepcopy(self.have) for entry in wantd, haved: # self._module.fail_json(msg="Before normalize_vrrp_groups - entry: " + str(entry)) self._vrrp_groups_list_to_dict(entry) self._virtual_servers_list_to_dict(entry) self._vrrp_sync_groups_list_to_dict(entry) # self._module.fail_json(msg="Normalise - want: " + str(wantd) + " (((()))) have: " + str(haved)) # if state is merged, merge want onto have and then compare if self.state in ["merged"]: wantd = combine(haved, wantd, recursive=True) # self._module.fail_json(msg="Want: " + str(wantd) + "**** H: " + str(haved)) # if state is deleted, delete and empty out wantd # if self.state == "deleted": # w = deepcopy(wantd) # if w == {} and haved != {}: # self.commands = ["delete vrrp"] # return # for k, want in w.items(): # if not (k in haved and haved[k]): # del wantd[k] # else: # if isinstance(want, list): # for entry in want: # wname = entry.get("name") # haved["instances"] = [ # i for i in haved.get("instances", []) if i.get("name") != wname # ] # self.commands.append("delete vrrp name {}".format(wname)) # else: # self.commands.append("delete vrrp {}".format(k.replace("_", "-"))) # del wantd[k] # # if self.state == "overridden": # w = deepcopy(wantd) # h = deepcopy(haved) # for k, want in w.items(): # if k in haved anzd haved[k] != want: # if isinstance(want, list): # for entry in want: # wname = entry.get("name") # hdict = next( # (inst for inst in haved["instances"] if inst["name"] == wname), # None, # ) # if entry != hdict: # # self._module.fail_json(msg="Want: " + str(entry) + "**** H: " + str(hdict)) # haved["instances"] = [ # i for i in haved.get("instances", []) if i.get("name") != wname # ] # self.commands.append("delete vrrp name {}".format(wname)) # self.commands.append("commit") # for k, want in wantd.items(): if k == "vrrp": self._compare_vrrp(want, haved.get(k, {})) if k == "virtual_servers": # self._module.fail_json(msg="VSERVERS: " + str(want) + " ---- " + str(haved.get(k, {}))) self._compare_vsrvs(want, haved.get(k, {})) # self._module.fail_json(msg=str(want) + " +++ " + str(haved.pop(k, {}))) self.compare( parsers=self.parsers, want={k: want}, have={k: haved.pop(k, {})}, ) self._module.fail_json(msg=self.commands) def _compare_vsrvs(self, want, have): """Compare virtual servers of VRRP.py""" vs_parsers = [ "virtual_servers", "virtual_servers.real_server", ] for pair in self._extract_named_leafs(want): self.compare( parsers=vs_parsers, want={"virtual_servers": pair}, have={"virtual_servers": {}}, ) def _compare_vrrp(self, want, have): """Compare the instances of VRRP""" vrrp_parsers = [ "vrrp.snmp", "vrrp.global_parameters", "vrrp.global_parameters.garp", "vrrp.groups", "vrrp.groups.excluded_address", "vrrp.groups.garp", "vrrp.groups.authentication", "vrrp.groups.transition_script", "vrrp.groups.health_check", "vrrp.groups.track", "vrrp.sync_groups.member", "vrrp.sync_groups.transition_script", "vrrp.sync_groups.health_check", ] + pairs = [] # self._module.fail_json(msg="Want: " + str(want) + "&&&&&&&&&&&&&&&&&&&& have: " + str(have)) + # for wdict in self._extract_leaf_items(want): + # self._module.fail_json( + # msg=self._lookup_element(wdict, self._extract_leaf_items(have)), + # ) + + # for wdict in self._extract_leaf_items(want): + # self.compare(parsers=vrrp_parsers, want={"vrrp": wdict}, have={"vrrp": {}}) + + hlist = self._extract_leaf_items(have) + # wdict = { + # "groups": { + # "name": "g2", + # "preempt": False + # } + # } + # self._module.fail_json(msg=self._extract_path_tuple(wdict)) + # self._module.fail_json(msg=self._lookup_element(wdict, hlist)) + # self._module.fail_json(msg=self._find_matching_by_path(wdict, hlist)) + + # self._module.fail_json(msg=self._extract_leaf_items(want)) + + # wdict = { + # "groups": { + # "name": "g1", + # "track": { + # "interface": [ + # "eth0", + # ] + # } + # } + # } + # hdict = { + # "groups": { + # "name": "g1", + # "track": { + # "interface": [ + # "eth2", + # ] + # } + # } + # } + + # self.compare(parsers=vrrp_parsers, want={"vrrp": wdict}, have={"vrrp": hdict}) for wdict in self._extract_leaf_items(want): - self._module.fail_json( - msg=self.find_matching_element_by_path(wdict, self._extract_leaf_items(have)), - ) - - for wdict in self._extract_leaf_items(want): - self.compare(parsers=vrrp_parsers, want={"vrrp": wdict}, have={"vrrp": {}}) + # hdict = {} + hdict = self._find_matching_by_path(wdict, hlist) + pairs.append((wdict, hdict)) + self.compare(parsers=vrrp_parsers, want={"vrrp": wdict}, have={"vrrp": hdict}) + # self._module.fail_json(msg=pairs) def _vrrp_groups_list_to_dict(self, data): vrrp = data.get("vrrp", {}) groups = vrrp.get("groups") if not groups: return data if isinstance(groups, dict): return data if isinstance(groups, list): new_groups = {} for item in groups: name = item.get("name") if not name: continue new_groups[name] = item data["vrrp"]["groups"] = new_groups return data return data def _vrrp_sync_groups_list_to_dict(self, data): vrrp = data.get("vrrp", {}) groups = vrrp.get("sync_groups") if not groups: return data if isinstance(groups, dict): return data if isinstance(groups, list): new_groups = {} for item in groups: name = item.get("name") if not name: continue new_groups[name] = item data["vrrp"]["sync_groups"] = new_groups return data return data def _virtual_servers_list_to_dict(self, data): vss = data.get("virtual_servers") if not vss: return data if isinstance(vss, dict): for vs in vss.items(): rs = vs.get("real_server") if isinstance(rs, list): vs["real_server"] = { item["address"]: item for item in rs if isinstance(item, dict) and item.get("address") } return data if isinstance(vss, list): new_vss = {} for vs in vss: if not isinstance(vs, dict): continue name = vs.get("name") if not name: continue rs = vs.get("real_server") if isinstance(rs, list): vs["real_server"] = { item["address"]: item for item in rs if isinstance(item, dict) and item.get("address") } new_vss[name] = vs data["virtual_servers"] = new_vss return data return data def _extract_leaf_items(self, data, path=None, parent_name=None): path = path or [] results = [] if isinstance(data, dict): current_name = data.get("name", parent_name) for k, v in data.items(): if k == "name": continue results.extend(self._extract_leaf_items(v, path + [k], current_name)) return results leaf_key = path[-1] top_key = path[0] if top_key in ["groups", "sync_groups"]: subkeys = path[2:] else: subkeys = path[1:] nested = {leaf_key: data} for p in reversed(subkeys[:-1]): nested = {p: nested} if parent_name: out = {top_key: {"name": parent_name}} out[top_key].update(nested) else: out = {top_key: nested} results.append(out) return results def _extract_named_leafs(self, data, parent_name=None, prefix_key=None): results = [] if prefix_key == "real_server" and isinstance(data, dict): for server_name, server_data in data.items(): if isinstance(server_data, dict): results.append( { "name": parent_name, "real_server": server_data, }, ) return results if isinstance(data, dict): current_name = data.get("name", parent_name) for k, v in data.items(): if k == "name": continue leaves = self._extract_named_leafs(v, current_name, k) results.extend(leaves) return results return [ { "name": parent_name, prefix_key: data, }, ] - def extract_path_tuple(self, d): + # def _extract_path_tuple(self, d): + + # path = [] + # cur = d + # while isinstance(cur, dict) and cur: + # k = next(iter(cur)) + # path.append(k) + # cur = cur[k] + # return tuple(path) + + # def _lookup_element(self, element, target_list): + + # key = self._extract_path_tuple(element) + # for obj in target_list: + # if self._extract_path_tuple(obj) == key: + # return obj + # return {} + + def _lookup_by_path(self, want_item, have_list): + """ + Find matching object in have_list by structural path + name (if present). + Ignore values. Return {} if not found. + """ + + def extract_signature(d): + sig = [] + + while isinstance(d, dict) and d: + k = next(iter(d)) + sig.append(k) + d = d[k] + + # capture identity if present + if isinstance(d, dict) and "name" in d: + sig.append(("name", d["name"])) + self._module.fail_json(msg="SIG: " + str(sig)) + return tuple(sig) + + want_sig = extract_signature(want_item) - path = [] - cur = d - while isinstance(cur, dict) and cur: - k = next(iter(cur)) - path.append(k) - cur = cur[k] - return tuple(path) + for obj in have_list: + if extract_signature(obj) == want_sig: + return obj + + return {} - def find_matching_element_by_path(self, element, second_list): + def _find_matching_by_path(self, want_item, have_list): """ - Find the element in second_list that has the same path as `element`. + Return the object from have_list that matches the structural path of want_item. + Matching ignores values; 'name' inside objects is treated as identity and included. Returns {} if no match. """ - key = self.extract_path_tuple(element) - for obj in second_list: - if self.extract_path_tuple(obj) == key: + + def build_sig_node(node): + """Return a tuple fragment describing node (no top-level key).""" + if not isinstance(node, dict): + return () + # single-key dict: descend + if len(node) == 1: + k = next(iter(node)) + return (k,) + build_sig_node(node[k]) + # multi-key dict: capture name (if present), then remaining keys deterministically + parts = [] + if "name" in node: + parts.append(("name", node["name"])) + # process other keys in sorted order for determinism + for k in sorted(k for k in node.keys() if k != "name"): + v = node[k] + if isinstance(v, dict): + # include the key and recurse into it + parts.append(k) + parts += list(build_sig_node(v)) + else: + parts.append(k) + return tuple(parts) + + # build signature for want_item + if not (isinstance(want_item, dict) and want_item): + return {} + top = next(iter(want_item)) # e.g. "groups" or "global_parameters" + sig_want = (top,) + build_sig_node(want_item[top]) + + # search + for obj in have_list: + if not (isinstance(obj, dict) and obj): + continue + top2 = next(iter(obj)) + sig_have = (top2,) + build_sig_node(obj[top2]) + if sig_have == sig_want: return obj + return {} diff --git a/plugins/module_utils/network/vyos/facts/vrrp/vrrp.py b/plugins/module_utils/network/vyos/facts/vrrp/vrrp.py index a7f7fe53..5e9abf42 100644 --- a/plugins/module_utils/network/vyos/facts/vrrp/vrrp.py +++ b/plugins/module_utils/network/vyos/facts/vrrp/vrrp.py @@ -1,160 +1,160 @@ # -*- coding: utf-8 -*- # Copyright 2021 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type """ The vyos vrrp fact class It is in this file the configuration is collected from the device for a given resource, parsed, and the facts tree is populated based on the configuration. """ import re from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.vrrp.vrrp import ( VrrpArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.vrrp import ( VrrpTemplate, ) class VrrpFacts(object): """The vyos vrrp facts class""" def __init__(self, module, subspec="config", options="options"): self._module = module self.argument_spec = VrrpArgs.argument_spec def get_device_data(self, connection): return connection.get('show configuration commands | match "set high-availability"') def get_config_set(self, data, connection): """To classify the configurations beased on vrrp""" config_dict = {} for config_line in data.splitlines(): vrrp_grp = re.search(r"set high-availability vrrp group (\S+).*", config_line) vrrp_gp = re.search( r"set high-availability vrrp global-parameters (\S+).*", config_line, ) vrrp_sg = re.search(r"set high-availability vrrp sync-group (\S+).*", config_line) vrrp_vsrv = re.search(r"set high-availability virtual-server (\S+).*", config_line) vrrp_disable = re.search(r"set high-availability disable", config_line) vrrp_snmp = re.search(r"set high-availability vrrp snmp", config_line) if vrrp_disable: - config_dict["disable"] = config_dict.get("disable", "") + config_line + "\n" + config_dict["disable"] = [config_dict.get("disable", "") + config_line] if vrrp_snmp: config_dict.setdefault("vrrp", []).append(config_line) if vrrp_gp: config_dict.setdefault("global_parameters", []).append(config_line) if vrrp_vsrv: config_dict.setdefault(vrrp_vsrv.group(1), []).append(config_line) if vrrp_sg: config_dict.setdefault(vrrp_sg.group(1), []).append(config_line) if vrrp_grp: config_dict.setdefault(vrrp_grp.group(1), []).append(config_line) return list(config_dict.values()) def deep_merge(self, dest, src): for key, value in src.items(): if key in dest and isinstance(dest[key], dict) and isinstance(value, dict): self.deep_merge(dest[key], value) else: dest[key] = value return dest def populate_facts(self, connection, ansible_facts, data=None): """Populate the facts for vrrp network resource :param connection: the device connection :param ansible_facts: Facts dictionary :param data: previously collected conf :rtype: dictionary :returns: facts """ facts = {} objs = {} config_lines = [] if not data: data = self.get_device_data(connection) # self._module.fail_json(msg="Data: " + str(data)) resources = self.get_config_set(data, connection) # self._module.fail_json(msg="Resources: " + str(resources)) vrrp_facts = {"disable": False, "virtual_servers": {}, "vrrp": {}} for resource in resources: vrrp_parser = VrrpTemplate( lines=resource, module=self._module, ) objs = vrrp_parser.parse() # self._module.fail_json(msg="VRRP Objs: " + str(objs)) if "disable" in objs: vrrp_facts["disable"] = objs["disable"] for section in ("virtual_servers", "vrrp"): if section in objs: # self._module.fail_json(msg="Section: " + str(section) + " Objs[section]: " + str(objs[section])) for name, data in objs[section].items(): if not isinstance(data, dict): vrrp_facts[section][name] = data continue existing = vrrp_facts[section].get(name, {}) vrrp_facts[section][name] = self.deep_merge(existing, data) ansible_facts["ansible_network_resources"].pop("vrrp", None) # vrrp_facts = self.normalize_config(vrrp_facts) # # self._module.fail_json(msg="VRRP_Facts: " + str(vrrp_facts)) validate_parser = VrrpTemplate(lines=[], module=self._module) params = utils.remove_empties( validate_parser.validate_config( self.argument_spec, {"config": vrrp_facts}, redact=True, ), ) # self._module.fail_json(msg="Params: " + str(params)) facts["vrrp"] = params.get("config", []) ansible_facts["ansible_network_resources"].update(facts) # self._module.fail_json(msg='Facts - ' + str(ansible_facts)) return ansible_facts def normalize_config(self, config): if not config: return config # Normalize virtual_servers if isinstance(config.get("virtual_servers"), dict): config["virtual_servers"] = list(config["virtual_servers"].values()) # Normalize vrrp vrrp = config.get("vrrp", {}) # self._module.fail_json(msg=config.get("vrrp", {})) if isinstance(vrrp.get("groups"), dict): vrrp["groups"] = list(vrrp["groups"].values()) # self._module.fail_json(msg="Groups: " + str(vrrp["groups"])) if isinstance(vrrp.get("sync_groups"), dict): vrrp["sync_groups"] = list(vrrp["sync_groups"].values()) # self._module.fail_json(msg="SGroups: " + str(vrrp["sync_groups"])) # Normalize real_server inside each virtual_server for vs in config.get("virtual_servers", []): if isinstance(vs.get("real_server"), dict): vs["real_server"] = list(vs["real_server"].values()) return config diff --git a/plugins/module_utils/network/vyos/rm_templates/vrrp.py b/plugins/module_utils/network/vyos/rm_templates/vrrp.py index daec527f..0f5eebca 100644 --- a/plugins/module_utils/network/vyos/rm_templates/vrrp.py +++ b/plugins/module_utils/network/vyos/rm_templates/vrrp.py @@ -1,675 +1,674 @@ # -*- coding: utf-8 -*- # Copyright 2021 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type """ The Vrrp parser templates file. This contains a list of parser definitions and associated functions that facilitates both facts gathering and native command generation for the given network resource. """ import re from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) def _tmplt_vsrvs(config_data): config_data = config_data["virtual_servers"] command = [] cmd = "high-availability virtual-server {name}".format(**config_data) for key, value in config_data.items(): if key == "name" or isinstance(value, dict) or value is None: continue else: command.append(f"{cmd} {key.replace('_', '-')} {value}") return command def _tmplt_vsrvs_rsrv(config_data): config_data = config_data["virtual_servers"] command = [] cmd = "high-availability virtual-server {name}".format(**config_data) config_data = config_data["real_server"] address = config_data["address"] for key, value in config_data.items(): if key == "address" or value is None: continue if value is not None: command.append(cmd + " real-server " + f"{address} {key.replace('_', '-')} {value}") return command def _tmplt_vrrp_sgroup_hc(config_data): config_data = config_data["vrrp"]["sync_groups"] command = [] cmd = "high-availability vrrp sync-group {name}".format(**config_data) config_data = config_data["health_check"] for key, value in config_data.items(): if value is not None: command.append(cmd + " health-check " + f"{key.replace('_', '-')} {value}") return command def _tmplt_vrrp_sgroup_ts(config_data): config_data = config_data["vrrp"]["sync_groups"] command = [] cmd = "high-availability vrrp sync-group {name}".format(**config_data) config_data = config_data["transition_script"] for key, value in config_data.items(): if value is not None: command.append(cmd + " transition-script " + f"{key.replace('_', '-')} {value}") return command def _tmplt_vrrp_gp(config_data): config_data = config_data["vrrp"]["global_parameters"] command = [] cmd = "high-availability vrrp global-parameters".format(**config_data) for key, value in config_data.items(): if isinstance(value, dict) or value is None: continue else: command.append(f"{cmd} {key.replace('_', '-')} {value}") return command def _tmplt_vrrp_gp_garp(config_data): config_data = config_data["vrrp"]["global_parameters"]["garp"] command = [] cmd = "high-availability vrrp global-parameters garp" for key, value in config_data.items(): if value is None: continue command.append(f"{cmd} {key.replace('_', '-')} {value}") return command def _tmplt_vrrp_group(config_data): config_data = config_data["vrrp"]["groups"] command = [] cmd = "high-availability vrrp group {name}".format(**config_data) for key, value in config_data.items(): if key == "name" or isinstance(value, dict) or isinstance(value, list) or value is None: continue elif isinstance(value, bool) and value is not None: command.append(f"{cmd} {key.replace('_', '-')}") else: command.append(f"{cmd} {key.replace('_', '-')} {value}") return command def _tmplt_vrrp_group_garp(config_data): config_data = config_data["vrrp"]["groups"] command = [] cmd = "high-availability vrrp group {name}".format(**config_data) config_data = config_data["garp"] for key, value in config_data.items(): if value is not None: command.append(cmd + " garp " + f"{key.replace('_', '-')} {value}") return command def _tmplt_vrrp_group_auth(config_data): config_data = config_data["vrrp"]["groups"] command = [] cmd = "high-availability vrrp group {name}".format(**config_data) config_data = config_data["authentication"] for key, value in config_data.items(): if value is not None: command.append(cmd + " authentication " + f"{key.replace('_', '-')} {value}") return command def _tmplt_vrrp_group_ts(config_data): config_data = config_data["vrrp"]["groups"] command = [] cmd = "high-availability vrrp group {name}".format(**config_data) config_data = config_data["transition_script"] for key, value in config_data.items(): if value is not None: command.append(cmd + " transition-script " + f"{key.replace('_', '-')} {value}") return command def _tmplt_vrrp_sgroup_member(config_data): sgroup = config_data["vrrp"]["sync_groups"] command = [] cmd = "high-availability vrrp sync-group {name}".format(**sgroup) members = sgroup.get("member", []) for member in members: if member is None: continue command.append(f"{cmd} member {member}") return command def _tmplt_vrrp_group_exaddress(config_data): group = config_data["vrrp"]["groups"] command = [] cmd = "high-availability vrrp group {name}".format(**group) exaddresses = group.get("excluded_address", []) for exaddress in exaddresses: if exaddress is None: continue command.append(f"{cmd} excluded-address {exaddress}") return command def _tmplt_vrrp_group_hc(config_data): config_data = config_data["vrrp"]["groups"] command = [] cmd = "high-availability vrrp group {name}".format(**config_data) config_data = config_data["health_check"] for key, value in config_data.items(): if value is not None: command.append(cmd + " health-check " + f"{key.replace('_', '-')} {value}") return command def _tmplt_vrrp_group_track(config_data): config_data = config_data["vrrp"]["groups"] command = [] cmd = "high-availability vrrp group {name}".format(**config_data) config_data = config_data["track"] for key, value in config_data.items(): if isinstance(value, bool) and value is not None: command.append(cmd + " track " + f"{key.replace('_', '-')}") elif isinstance(value, list): for item in value: command.append(cmd + " track " + f"{key.replace('_', '-')} {item}") return command class VrrpTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): prefix = {"set": "set", "remove": "delete"} super(VrrpTemplate, self).__init__( lines=lines, tmplt=self, prefix=prefix, module=module, ) # fmt: off PARSERS = [ { "name": "disable", "getval": re.compile( r""" ^set \shigh-availability \s(?Pdisable) $""", re.VERBOSE, ), "setval": "high-availability disable", "result": { - "disable": "{{ True if disable is defined }}", + "disable": "{{ True if disable is defined else False }}", }, }, { "name": "virtual_servers", "getval": re.compile( r""" ^set\shigh-availability\svirtual-server \s+(?P\S+) (?:\s+address\s+(?P
\S+))? (?:\s+algorithm\s+(?P\S+))? (?:\s+delay-loop\s+(?P\S+))? (?:\s+forward-method\s+(?P\S+))? (?:\s+fwmark\s+(?P\S+))? (?:\s+persistence-timeout\s+(?P\S+))? (?:\s+port\s+(?P\S+))? (?:\s+protocol\s+(?P\S+))? $ """, re.VERBOSE, ), "setval": _tmplt_vsrvs, "result": { "virtual_servers": { "{{ name }}": { "name": "{{ name }}", "address": "{{ address if address is defined else None }}", "algorithm": "{{ algorithm if algorithm is defined else None }}", "delay_loop": "{{ delay_loop if delay_loop is defined else None }}", "forward_method": "{{ forward_method if forward_method is defined else None }}", "fwmark": "{{ fwmark if fwmark is defined else None }}", "persistence_timeout": "{{ persistence_timeout if persistence_timeout is defined else None }}", "port": "{{ port if port is defined else None }}", "protocol": "{{ protocol if protocol is defined else None }}", }, }, }, }, { "name": "virtual_servers.real_server", "getval": re.compile( r""" ^set\shigh-availability\svirtual-server \s+(?P\S+) \sreal-server \s+(?P
\S+) (?:\s+port\s+(?P\S+))? (?:\s+health-check\sscript\s+(?P\S+))? (?:\s+connection-timeout\s+(?P\S+))? $ """, re.VERBOSE, ), "setval": _tmplt_vsrvs_rsrv, "result": { "virtual_servers": { "{{ name }}": { "name": "{{ name }}", "real_server": { "{{ address }}": { "address": "{{ address }}", "port": "{{ port if port is defined else None }}", "health_check": "{{ hcscript if hcscript is defined else None }}", "connection_timeout": "{{ cont if cont is defined else None }}", }, }, }, }, }, }, { "name": "vrrp.sync_groups.member", "getval": re.compile( r""" ^set\shigh-availability\svrrp\ssync-group \s+(?P\S+) \smember \s+(?P\S+) $ """, re.VERBOSE, ), "setval": _tmplt_vrrp_sgroup_member, "result": { "vrrp": { "sync_groups": { "{{ sgname }}": { "name": "{{ sgname }}", "member": [ "{{ member }}", ], }, }, }, }, }, { "name": "vrrp.sync_groups.health_check", "getval": re.compile( r""" ^set\shigh-availability\svrrp\ssync-group \s+(?P\S+) \shealth-check (?:\s+failure-count\s+(?P\S+)) ?(?:\s+interval\s+(?P\S+)) ?(?:\s+ping\s+(?P\S+)) ?(?:\s+script\s+(?P