コード例 #1
0
    def render_config(self, spec, conf, interface):
        """
        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)
        if interface:
            intf = interface
            if intf.startswith("port"):
                config["name"] = intf
                config["members"] = []
                member_config = {}
                channel_group = re.search(r"static-channel-group (\d+)", conf)
                if channel_group:
                    channel_group_id = channel_group.group(1)
                    config["name"] = str(channel_group_id)
                    member_filters = re.search(
                        r"static-channel-group (\d+) (member-filters)", conf)
                    if member_filters and member_filters.group(2):
                        member_filters = True
                        member_config.update(
                            {"member_filters": member_filters})
                    member_config["member"] = normalize_interface(intf)
                    config["members"].append(member_config)

        return utils.remove_empties(config)
コード例 #2
0
    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)
コード例 #3
0
    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"(\d+\.\d+\.\d+).+", conf, re.M)
        intf = ""
        if match:
            intf = match.group(1)

        if get_interface_type(intf) == "unknown":
            return {}

        if intf.lower()[0].isdigit():
            config["name"] = normalize_interface(intf)

            if "Rx" in conf:
                config["receive"] = True
            else:
                config["receive"] = False

            if "Tx" in conf:
                config["transmit"] = True
            else:
                config["transmit"] = False

        return utils.remove_empties(config)
コード例 #4
0
 def render_config(self, spec, conf, intf):
     config = deepcopy(spec)
     config["name"] = normalize_interface(intf)
     config["description"] = utils.parse_conf_arg(conf, "description")
     if utils.parse_conf_arg(conf, "speed"):
         config["speed"] = int(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)
コード例 #5
0
 def parse_neighbors(self, neighbors):
     facts = dict()
     for entry in neighbors.split(
         "------------------------------------------------"
     ):
         if entry == "":
             continue
         intf = self.parse_lldp_intf(entry)
         if intf is None:
             return facts
         intf = normalize_interface(intf)
         if intf not in facts:
             facts[intf] = list()
         fact = dict()
         fact["host"] = self.parse_lldp_host(entry)
         fact["port"] = self.parse_lldp_port(entry)
         facts[intf].append(fact)
     return facts
コード例 #6
0
    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 (\S+)", conf)
        intf = match.group(1)

        if get_interface_type(intf) == "unknown":
            return {}

        if intf.upper()[:2] in ("PO"):
            # populate the facts from the configuration
            config["name"] = normalize_interface(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)}
                else:
                    config["access"] = {"vlan": 1}

            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")
            if allowed_vlan:
                trunk["allowed_vlans"] = allowed_vlan.split(",")
                first_vlan = trunk["allowed_vlans"][0]
                if "add" in first_vlan:
                    first_vlan = first_vlan.replace("add ", "")
                    trunk["allowed_vlans"][0] = first_vlan
            config["trunk"] = trunk

        return utils.remove_empties(config)
コード例 #7
0
    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 (\S+)", conf)
        if match:
            intf = match.group(1)

            if get_interface_type(intf) == "unknown":
                return {}
            # populate the facts from the configuration
            config["name"] = normalize_interface(intf)

            ipv4 = []
            ipv4_all = re.findall(r"ip address (\S+.*)", conf)
            for each in ipv4_all:
                each = each.strip()
                each_ipv4 = dict()
                if "secondary" not in each and "dhcp" not in each:
                    each_ipv4["address"] = each
                    each_ipv4["secondary"] = False
                    each_ipv4["dhcp_client"] = None
                    each_ipv4["dhcp_hostname"] = None
                elif "secondary" in each:
                    each_ipv4["address"] = each.split(" secondary")[0]
                    each_ipv4["secondary"] = True
                elif "dhcp" in each:
                    each_ipv4["address"] = "dhcp"
                    if "client-id" in each:
                        each_ipv4["dhcp_client"] = int(
                            each.split(" hostname ")[0].split("/")[-1][-1])
                    if "hostname" in each:
                        each_ipv4["dhcp_hostname"] = each.split(
                            " hostname ")[-1]
                    if "client-id" in each and each_ipv4["dhcp_client"] is None:
                        each_ipv4["dhcp_client"] = int(each.split("/")[-1])
                    if "hostname" in each and not each_ipv4["dhcp_hostname"]:
                        each_ipv4["dhcp_hostname"] = each.split(
                            " hostname ")[-1]
                ipv4.append(each_ipv4)
            config["ipv4"] = ipv4

            # Get the configured IPV6 details
            ipv6 = []
            ipv6_all = re.findall(r"ipv6 address (\S+)", conf)
            for each in ipv6_all:
                each_ipv6 = dict()
                if "autoconfig" in each:
                    each_ipv6["autoconfig"] = True
                if "dhcp" in each:
                    each_ipv6["dhcp"] = True
                each_ipv6["address"] = each.lower()
                ipv6.append(each_ipv6)
            config["ipv6"] = ipv6

        return utils.remove_empties(config)