def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) match = re.search(r'^(\S+)', conf) intf = match.group(1) if get_interface_type(intf) == 'unknown': return {} config['name'] = intf config['mode'] = utils.parse_conf_arg(conf, 'switchport mode') config['ip_forward'] = utils.parse_conf_arg(conf, 'ip forward') config['access']['vlan'] = utils.parse_conf_arg( conf, 'switchport access vlan') config['trunk']['allowed_vlans'] = utils.parse_conf_arg( conf, 'switchport trunk allowed vlan') config['trunk']['native_vlan'] = utils.parse_conf_arg( conf, 'switchport trunk native vlan') return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) match = re.search( r'(GigabitEthernet|Bundle-Ether|TenGigE|FortyGigE|HundredGigE)(\S+)', conf, re.M) if match: config['name'] = match.group(1) + match.group(2) temp = { 'churn_logging': 'lacp churn logging', 'switchover_suppress_flaps': 'lacp switchover suppress-flaps', 'collector_max_delay': 'lacp collector-max-delay', 'period': 'lacp period' } for key, value in iteritems(temp): config[key] = utils.parse_conf_arg(conf, value) for key in config['system'].keys(): config['system'][key] = utils.parse_conf_arg( conf, 'lacp system {0}'.format(key)) return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) match = re.search(r'^(\S+)(:)', conf) intf = '' if match: intf = match.group(1) if get_interface_type(intf) == 'unknown': return {} if intf.lower().startswith('gi'): config['name'] = normalize_interface(intf) receive = utils.parse_conf_arg(conf, 'Rx:') transmit = utils.parse_conf_arg(conf, 'Tx:') if receive == 'enabled': config['receive'] = True elif receive == 'disabled': config['receive'] = False if transmit == 'enabled': config['transmit'] = True elif transmit == 'disabled': config['transmit'] = False return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) match = re.search(r"^(\S+)", conf) intf = match.group(1) if get_interface_type(intf) == "unknown": return {} config["name"] = intf config["mode"] = utils.parse_conf_arg(conf, "switchport mode") config["ip_forward"] = utils.parse_conf_arg(conf, "ip forward") config["access"]["vlan"] = utils.parse_conf_arg( conf, "switchport access vlan" ) config["trunk"]["allowed_vlans"] = utils.parse_conf_arg( conf, "switchport trunk allowed vlan" ) config["trunk"]["native_vlan"] = utils.parse_conf_arg( conf, "switchport trunk native vlan" ) return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) match = re.search(r"^(\S+)", conf) intf = match.group(1) if get_interface_type(intf) == "unknown": return {} config["name"] = intf config["description"] = utils.parse_conf_arg(conf, "description") config["speed"] = utils.parse_conf_arg(conf, "speed") config["mtu"] = utils.parse_conf_arg(conf, "mtu") config["duplex"] = utils.parse_conf_arg(conf, "duplex") config["mode"] = utils.parse_conf_cmd_arg(conf, "switchport", "layer2", "layer3") config["enabled"] = utils.parse_conf_cmd_arg(conf, "shutdown", False, True) config["fabric_forwarding_anycast_gateway"] = utils.parse_conf_cmd_arg( conf, "fabric forwarding mode anycast-gateway", True) config["ip_forward"] = utils.parse_conf_cmd_arg( conf, "ip forward", True) interfaces_cfg = utils.remove_empties(config) return interfaces_cfg
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) # populate the facts from the configuration config["name"] = re.match(r"(\S+)", conf).group(1) description = utils.parse_conf_arg(conf, "description") if description is not None: config["description"] = description.replace('"', "") shutdown = utils.parse_conf_cmd_arg(conf, "shutdown", False) config["enabled"] = shutdown if shutdown is False else True config["mtu"] = utils.parse_conf_arg(conf, "mtu") config["mode"] = utils.parse_conf_cmd_arg( conf, "switchport", "layer2", "layer3" ) state = utils.parse_conf_arg(conf, "speed") if state: if state == "auto": config["duplex"] = state else: # remaining options are all e.g., 10half or 40gfull config["speed"] = state[:-4] config["duplex"] = state[-4:] return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) log = utils.parse_conf_arg(conf, 'log') config['dest'] = log.split()[0] if log else None if not config['dest']: return if config['dest'] == 'host': host = utils.parse_conf_arg(conf, 'host') config['name'] = host.split()[0] if host else None size = utils.parse_conf_arg(conf, 'size') config['size'] = size.split()[0] if size else None facility = utils.parse_conf_arg(conf, 'facility') config['facility'] = facility.split()[0] if facility else None level = utils.parse_conf_arg(conf, 'level') config['level'] = level.split()[0] if level else None return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) match = re.search(r"^(\S+)(:)", conf) intf = "" if match: intf = match.group(1) if get_interface_type(intf) == "unknown": return {} if intf.lower().startswith("gi"): config["name"] = normalize_interface(intf) receive = utils.parse_conf_arg(conf, "Rx:") transmit = utils.parse_conf_arg(conf, "Tx:") if receive == "enabled": config["receive"] = True elif receive == "disabled": config["receive"] = False if transmit == "enabled": config["transmit"] = True elif transmit == "disabled": config["transmit"] = False return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) match = re.search(r"^(\S+)", conf) intf = match.group(1) if get_interface_type(intf) == "unknown": return {} # populate the facts from the configuration config["name"] = normalize_interface(intf) config["description"] = utils.parse_conf_arg(conf, "description") config["speed"] = utils.parse_conf_arg(conf, "speed") if utils.parse_conf_arg(conf, "mtu"): config["mtu"] = int(utils.parse_conf_arg(conf, "mtu")) config["duplex"] = utils.parse_conf_arg(conf, "duplex") enabled = utils.parse_conf_cmd_arg(conf, "shutdown", False) config["enabled"] = enabled if enabled is not None else True return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) match = re.search(r"^(\S+)", conf) intf = match.group(1) if get_interface_type(intf) == "unknown": return {} config["name"] = normalize_interface(intf) port_priority = utils.parse_conf_arg(conf, "lacp port-priority") max_bundle = utils.parse_conf_arg(conf, "lacp max-bundle") if port_priority: config["port_priority"] = int(port_priority) if "lacp fast-switchover" in conf: config["fast_switchover"] = True if max_bundle: config["max_bundle"] = int(max_bundle) return utils.remove_empties(config)
def parse_config(self, conf, intf): """ Translate a given config into dictionary and delete keys from spec for null values :param conf: The configuration :param intf: name of the interface :rtype: dict :returns: The generated config """ config = deepcopy(self.generated_spec) config["name"] = intf mode = utils.parse_conf_arg(conf, "switchport mode") if mode == "access": has_access = utils.parse_conf_arg(conf, "switchport access vlan") if has_access: config["access"] = {"vlan": int(has_access)} trunk = dict() native_vlan = utils.parse_conf_arg(conf, "native vlan") if native_vlan and native_vlan != "none": trunk["native_vlan"] = int(native_vlan) allowed_vlan = utils.parse_conf_arg(conf, "allowed vlan add") if allowed_vlan: trunk["allowed_vlans"] = allowed_vlan.split(",") config["trunk"] = trunk return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) vlans = [] parse_result = utils.parse_conf_arg(conf, "vlan") if not parse_result.split(" ")[0].isalpha(): vlan_list = vlan_to_list(parse_result) for vlan in vlan_list: config["vlan_id"] = vlan config["name"] = utils.parse_conf_arg(conf, "name") config["state"] = utils.parse_conf_arg(conf, "state") if config["state"] is None: config["state"] = "active" vlans.append(utils.remove_empties(config)) return vlans
def render_config(self, spec, conf, data): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) match = re.search(r"(Bundle-Ether)(\d+)", conf, re.M) if match: config["name"] = match.group(1) + match.group(2) config["load_balancing_hash"] = utils.parse_conf_arg( conf, "bundle load-balancing hash" ) config["mode"] = utils.parse_conf_arg(conf, "lacp mode") config["links"]["max_active"] = utils.parse_conf_arg( conf, "bundle maximum-active links" ) config["links"]["min_active"] = utils.parse_conf_arg( conf, "bundle minimum-active links" ) config["members"] = self.parse_members(match.group(2), data) return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) match = re.search(r'^(\S+)', conf) intf = match.group(1) if get_interface_type(intf) == 'unknown': return {} # populate the facts from the configuration config['name'] = normalize_interface(intf) config['description'] = utils.parse_conf_arg(conf, 'description') config['speed'] = utils.parse_conf_arg(conf, 'speed') if utils.parse_conf_arg(conf, 'mtu'): config['mtu'] = int(utils.parse_conf_arg(conf, 'mtu')) config['duplex'] = utils.parse_conf_arg(conf, 'duplex') enabled = utils.parse_conf_cmd_arg(conf, 'shutdown', False) config['enabled'] = enabled if enabled is not None else True return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) match = re.search(r"interface (port\S+)", conf) if match: intf = match.group(1) if get_interface_type(intf) == "unknown": return {} config["name"] = normalize_interface(intf) port_priority = utils.parse_conf_arg(conf, "lacp port-priority") if port_priority: config["port_priority"] = int(port_priority) timeout = utils.parse_conf_arg(conf, "lacp timeout") if timeout: config["timeout"] = timeout else: config["timeout"] = "long" return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) match = re.search(r"^(\S+)", conf) intf = match.group(1) if get_interface_type(intf) == "unknown": return {} config["name"] = intf config["dot1q"] = utils.parse_conf_arg(conf, "encapsulation dot1[qQ]") config["redirects"] = utils.parse_conf_cmd_arg(conf, "no ip redirects", False, True) config["unreachables"] = utils.parse_conf_cmd_arg(conf, "ip unreachables", True, False) config["evpn_multisite_tracking"] = utils.parse_conf_arg(conf, "evpn multisite") ipv4_match = re.compile(r"\n ip address (.*)") matches = ipv4_match.findall(conf) if matches: if matches[0]: config["ipv4"] = [] for m in matches: ipv4_conf = m.split() addr = ipv4_conf[0] if addr: config_dict = {"address": addr} if len(ipv4_conf) > 1: d = ipv4_conf[1] if d == "secondary": config_dict.update({"secondary": True}) if len(ipv4_conf) == 4: if ipv4_conf[2] == "tag": config_dict.update({"tag": int(ipv4_conf[-1])}) elif d == "tag": config_dict.update({"tag": int(ipv4_conf[-1])}) config["ipv4"].append(config_dict) ipv6_match = re.compile(r"\n ipv6 address (.*)") matches = ipv6_match.findall(conf) if matches: if matches[0]: config["ipv6"] = [] for m in matches: ipv6_conf = m.split() addr = ipv6_conf[0] if addr: config_dict = {"address": addr} if len(ipv6_conf) > 1: d = ipv6_conf[1] if d == "tag": config_dict.update({"tag": int(ipv6_conf[-1])}) config["ipv6"].append(config_dict) return utils.remove_empties(config)
def parse_bgp(config, conf): config['bgp_as'] = utils.parse_conf_arg(conf, 'router bgp') config['router_id'] = utils.parse_conf_arg(conf, 'bgp router-id') if 'bgp log-neighbor-changes' in conf: config['log_neighbor_changes'] = True lines = conf.split('\n') config['neighbors'] = get_neighbors(lines) config['networks'] = get_networks(conf)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) access_group_list = [] access_group_v6_list = [] acls_list = [] group_list = [] group_dict = {} config["name"] = utils.parse_conf_arg(conf, "^interface") conf_lines = conf.split("\n") for line in conf_lines: if config["name"] in line: continue access_group = utils.parse_conf_arg(line, "^ip access-group") # This module was verified on an ios device since vEOS doesnot support # acl_interfaces cnfiguration. In ios, ipv6 acl is configured as # traffic-filter and in eos it is access-group # access_group_v6 = utils.parse_conf_arg(line, 'ipv6 traffic-filter') access_group_v6 = utils.parse_conf_arg(line, "^ipv6 access-group") if access_group: access_group_list.append(access_group) if access_group_v6: access_group_v6_list.append(access_group_v6) if access_group_list: for acl in access_group_list: a_name = acl.split()[0] a_dir = acl.split()[1] acls_dict = {"name": a_name, "direction": a_dir} acls_list.append(acls_dict) group_dict = {"afi": "ipv4", "acls": acls_list} group_list.append(group_dict) acls_list = [] if group_list: config["access_groups"] = group_list if access_group_v6_list: for acl in access_group_v6_list: a_name = acl.split()[0] a_dir = acl.split()[1] acls_dict = {"name": a_name, "direction": a_dir} acls_list.append(acls_dict) group_dict = {"acls": acls_list, "afi": "ipv6"} group_list.append(group_dict) acls_list = [] if group_list: config["access_groups"] = group_list return utils.remove_empties(config)
def populate_destination(self, config): same_dest = {} ip_str = "" for i in sorted(config): if i and "ospf" not in i: if "::" in i and "vrf" in i: ip_str = "ipv6 route vrf" elif "::" in i and "vrf" not in i: ip_str = "ipv6 route" elif "." in i and "vrf" in i: ip_str = "ip route vrf" elif "." in i and "vrf" not in i: ip_str = "ip route" if "vrf" in i: filter_vrf = utils.parse_conf_arg(i, ip_str) if "::" not in filter_vrf: filter_vrf, dest_vrf = self.update_netmask_to_cidr( filter_vrf, 1, 2, ) dest_vrf = dest_vrf + "_vrf" else: dest_vrf = filter_vrf.split(" ")[1] if dest_vrf not in same_dest.keys(): same_dest[dest_vrf] = [] same_dest[dest_vrf].append("vrf " + filter_vrf) elif "vrf" not in same_dest[dest_vrf][0]: same_dest[dest_vrf] = [] same_dest[dest_vrf].append("vrf " + filter_vrf) else: same_dest[dest_vrf].append(("vrf " + filter_vrf)) else: filter_non_vrf = utils.parse_conf_arg(i, ip_str) if "::" not in filter_non_vrf: # "/" not in filter_non_vrf and filter_non_vrf, dest = self.update_netmask_to_cidr( filter_non_vrf, 0, 1, ) else: dest = filter_non_vrf.split(" ")[0] if dest not in same_dest.keys(): same_dest[dest] = [] same_dest[dest].append(filter_non_vrf) elif "vrf" in same_dest[dest][0]: same_dest[dest] = [] same_dest[dest].append(filter_non_vrf) else: same_dest[dest].append(filter_non_vrf) return same_dest
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) match = re.search(r"^(\S+)", conf) intf = match.group(1) if get_interface_type(intf) == "unknown": return {} if intf.upper()[:2] in ( "HU", "FO", "TW", "TE", "GI", "FA", "ET", "PO", ): # populate the facts from the configuration config["name"] = normalize_interface(intf) has_access = utils.parse_conf_arg(conf, "switchport access vlan") if has_access: config["access"] = {"vlan": int(has_access)} trunk = dict() trunk["encapsulation"] = utils.parse_conf_arg( conf, "encapsulation") native_vlan = utils.parse_conf_arg(conf, "native vlan") if native_vlan: trunk["native_vlan"] = int(native_vlan) allowed_vlan = utils.parse_conf_arg(conf, "allowed vlan") if allowed_vlan: trunk["allowed_vlans"] = allowed_vlan.split(",") pruning_vlan = utils.parse_conf_arg(conf, "pruning vlan") if pruning_vlan: trunk["pruning_vlans"] = pruning_vlan.split(",") config["trunk"] = trunk return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) ntp = utils.parse_conf_arg(conf, 'ntp') if ntp: ntp = ntp.split() else: return if ntp[0] == 'server': config['server'] = ntp[1] elif ntp[0] == 'authentication-key': config['key_id'] = ntp[1] config['key_type'] = ntp[2] config['auth_key'] = ntp[3] elif ntp[0] == 'source': config['source_int'] = ntp[1] return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) config["name"] = utils.parse_conf_arg(conf, "interface") config["port_priority"] = utils.parse_conf_arg(conf, "port-priority") config["rate"] = utils.parse_conf_arg(conf, "rate") return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) for key in spec.keys(): if key == 'subinterfaces': config[key] = True if 'subinterfaces enable' in conf else None elif key == 'tlv_select': for item in [ 'system_name', 'port_description', 'management_address', 'system_description', 'system_capabilities' ]: config[key][item] = False if ('{0} disable'.format( item.replace('_', '-'))) in conf else None else: value = utils.parse_conf_arg(conf, key) config[key] = int(value) if value else value return config
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) for key in spec.keys(): if key == "subinterfaces": config[key] = True if "subinterfaces enable" in conf else None elif key == "tlv_select": for item in [ "system_name", "port_description", "management_address", "system_description", "system_capabilities", ]: config[key][item] = (False if ("{0} disable".format( item.replace("_", "-"))) in conf else None) else: value = utils.parse_conf_arg(conf, key) config[key] = int(value) if value else value return config
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) config['name'] = utils.parse_conf_arg(conf, 'interface') matches = re.findall(r'.*ip address (.+)$', conf, re.MULTILINE) if matches: config["ipv4"] = [] for match in matches: address, dummy, remainder = match.partition(" ") ipv4 = {"address": address} if remainder == "secondary": ipv4["secondary"] = True config['ipv4'].append(ipv4) matches = re.findall(r'.*ipv6 address (.+)$', conf, re.MULTILINE) if matches: config["ipv6"] = [] for match in matches: address, dummy, remainder = match.partition(" ") ipv6 = {"address": address} config['ipv6'].append(ipv6) return utils.remove_empties(config)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) interface_name = utils.parse_conf_arg(conf, "interface") if interface_name.startswith("Port-Channel"): config["name"] = interface_name return utils.remove_empties(config) interface = {"member": interface_name} match = re.match( r".*channel-group (\d+) mode (\S+)", conf, re.MULTILINE | re.DOTALL ) if match: config["name"], interface["mode"] = match.groups() config["name"] = "Port-Channel" + config["name"] config["members"] = [interface] return utils.remove_empties(config)
def render_config(self, spec, vlan): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param vlan: structured data vlan settings (dict) and raw cfg from device :rtype: dictionary :returns: The generated config Sample inputs: test/units/modules/network/nxos/fixtures/nxos_vlans/show_vlan """ obj = deepcopy(spec) obj["vlan_id"] = vlan["vlan_id"] # name: 'VLAN000x' (default name) or custom name name = vlan["vlanshowbr-vlanname"] if name and re.match("VLAN%04d" % int(vlan["vlan_id"]), name): name = None obj["name"] = name # mode: 'ce-vlan' or 'fabricpath-vlan' obj["mode"] = vlan["vlanshowinfo-vlanmode"].replace("-vlan", "") # enabled: shutdown, noshutdown obj["enabled"] = ( True if "noshutdown" in vlan["vlanshowbr-shutstate"] else False ) # state: active, suspend obj["state"] = vlan["vlanshowbr-vlanstate"] # non-structured data obj["mapped_vni"] = parse_conf_arg(vlan["run_cfg"], "vn-segment") return utils.remove_empties(obj)
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) match = re.search(r'^(\S+)', conf) intf = match.group(1) if get_interface_type(intf) == 'unknown': return {} config['name'] = intf config['dot1q'] = utils.parse_conf_arg(conf, 'encapsulation dot1[qQ]') config['redirects'] = utils.parse_conf_cmd_arg(conf, 'no ip redirects', False, True) config['unreachables'] = utils.parse_conf_cmd_arg( conf, 'ip unreachables', True, False) ipv4_match = re.compile(r'\n ip address (.*)') matches = ipv4_match.findall(conf) if matches: if matches[0]: config['ipv4'] = [] for m in matches: ipv4_conf = m.split() addr = ipv4_conf[0] if addr: config_dict = {'address': addr} if len(ipv4_conf) > 1: d = ipv4_conf[1] if d == 'secondary': config_dict.update({'secondary': True}) if len(ipv4_conf) == 4: if ipv4_conf[2] == 'tag': config_dict.update( {'tag': int(ipv4_conf[-1])}) elif d == 'tag': config_dict.update({'tag': int(ipv4_conf[-1])}) config['ipv4'].append(config_dict) ipv6_match = re.compile(r'\n ipv6 address (.*)') matches = ipv6_match.findall(conf) if matches: if matches[0]: config['ipv6'] = [] for m in matches: ipv6_conf = m.split() addr = ipv6_conf[0] if addr: config_dict = {'address': addr} if len(ipv6_conf) > 1: d = ipv6_conf[1] if d == 'tag': config_dict.update({'tag': int(ipv6_conf[-1])}) config['ipv6'].append(config_dict) return utils.remove_empties(config)
def populate_destination(self, config): same_dest = {} ip_str = '' for i in sorted(config): if i: if '::' in i and 'vrf' in i: ip_str = 'ipv6 route vrf' elif '::' in i and 'vrf' not in i: ip_str = 'ipv6 route' elif '.' in i and 'vrf' in i: ip_str = 'ip route vrf' elif '.' in i and 'vrf' not in i: ip_str = 'ip route' if 'vrf' in i: filter_vrf = utils.parse_conf_arg(i, ip_str) if '/' not in filter_vrf and '::' not in filter_vrf: filter_vrf, dest_vrf = self.update_netmask_to_cidr( filter_vrf, 1, 2) dest_vrf = dest_vrf + '_vrf' else: dest_vrf = filter_vrf.split(' ')[1] if dest_vrf not in same_dest.keys(): same_dest[dest_vrf] = [] same_dest[dest_vrf].append('vrf ' + filter_vrf) elif 'vrf' not in same_dest[dest_vrf][0]: same_dest[dest_vrf] = [] same_dest[dest_vrf].append('vrf ' + filter_vrf) else: same_dest[dest_vrf].append(('vrf ' + filter_vrf)) else: filter = utils.parse_conf_arg(i, ip_str) if '/' not in filter and '::' not in filter: filter, dest = self.update_netmask_to_cidr( filter, 0, 1) else: dest = filter.split(' ')[0] if dest not in same_dest.keys(): same_dest[dest] = [] same_dest[dest].append(filter) elif 'vrf' in same_dest[dest][0]: same_dest[dest] = [] same_dest[dest].append(filter) else: same_dest[dest].append(filter) return same_dest
def render_config(self, spec, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ config = deepcopy(spec) system_priority = utils.parse_conf_arg(conf, 'priority') config['system']['priority'] = int(system_priority) if system_priority else system_priority config['system']['mac']['address'] = utils.parse_conf_arg(conf, 'mac') return config