コード例 #1
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'^(\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)

        # Capture the default 'enabled' state, which may be interface-specific
        config['enabled_def'] = default_intf_enabled(name=intf, sysdefs=self.sysdefs, mode=config['mode'])

        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
コード例 #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'^(\S+)(:)', conf)
        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)
コード例 #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"^(\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)
コード例 #4
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"^(\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)
コード例 #5
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)
        config['name'] = utils.parse_conf_arg(conf, 'resource')
        config['some_string'] = utils.parse_conf_arg(conf, 'a_string')

        match = re.match(r'.*key is property01 (\S+)',
                         conf, re.MULTILINE | re.DOTALL)
        if match:
            config['some_dict']['property_01'] = match.groups()[0]

        a_bool = utils.parse_conf_arg(conf, 'a_bool')
        if a_bool == 'true':
            config['some_bool'] = True
        elif a_bool == 'false':
            config['some_bool'] = False
        else:
            config['some_bool'] = None

        try:
            config['some_int'] = int(utils.parse_conf_arg(conf, 'an_int'))
        except TypeError:
            config['some_int'] = None
        return utils.remove_empties(config)
コード例 #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'^(\S+)', conf)
        intf = match.group(1)
        if get_interface_type(intf) == 'unknown':
            return {}

        config['name'] = intf
        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)
コード例 #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"(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)
コード例 #8
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)
        if len(conf) == 1:
            return utils.remove_empties({'vlan_id': conf})

        match = re.search(r'^(\S+)?', conf, re.M)
        if match:
            if len(match.group(1)) == 1:
                config['vlan_id'] = match.group(1)
                config['name'] = parse_conf_arg(conf, 'name')
                config['mode'] = parse_conf_arg(conf, 'mode')
                config['mapped_vni'] = parse_conf_arg(conf, 'vn-segment')
                config['state'] = parse_conf_arg(conf, 'state')
                admin_state = parse_conf_cmd_arg(conf, 'shutdown', 'down',
                                                 'up')
                if admin_state == 'up':
                    config['enabled'] = True
                elif admin_state == 'down':
                    config['enabled'] = False

        vlans_cfg = utils.remove_empties(config)
        return vlans_cfg
コード例 #9
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"^(\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)
コード例 #10
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'^(\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)
コード例 #11
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"^(\S+)", conf)
        intf = match.group(1)
        if get_interface_type(intf) == "unknown":
            return {}

        config["name"] = intf
        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)
コード例 #12
0
ファイル: acl_interfaces.py プロジェクト: zealot00/ansible
    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)
コード例 #13
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"^(\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)
コード例 #14
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)

        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)
コード例 #15
0
ファイル: lldp_global.py プロジェクト: zorgzerg/ansible
    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
コード例 #16
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)
        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)
コード例 #17
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)

        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
コード例 #18
0
ファイル: lacp_interfaces.py プロジェクト: zgx950813/ansible
    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)
コード例 #19
0
    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)
コード例 #20
0
    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
コード例 #21
0
 def parse_attribs(self, attribs, conf):
     config = {}
     for item in attribs:
         value = utils.parse_conf_arg(conf, item)
         if value:
             config[item] = value.strip("'")
         else:
             config[item] = None
     return utils.remove_empties(config)
コード例 #22
0
ファイル: lacp.py プロジェクト: sivakrishnaa/ansible-1
    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
コード例 #23
0
ファイル: l3_interfaces.py プロジェクト: zealot00/ansible
    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)
コード例 #24
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)

        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
コード例 #25
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)
        config['holdtime'] = utils.parse_conf_arg(conf, 'holdtime')
        config['reinit'] = utils.parse_conf_arg(conf, 'reinit')
        config['timer'] = utils.parse_conf_arg(conf, 'timer')

        for match in re.findall(r'^(no)? lldp tlv-select (\S+)', conf,
                                re.MULTILINE):
            tlv_option = match[1].replace("-", "_")
            config['tlv_select'][tlv_option] = bool(match[0] != "no")

        return utils.remove_empties(config)
コード例 #26
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'^(\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)
コード例 #27
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"^(\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_arg(
            conf, "fabric forwarding mode anycast-gateway")
        config["ip_forward"] = utils.parse_conf_arg(conf, "ip forward")

        interfaces_cfg = utils.remove_empties(config)
        return interfaces_cfg
コード例 #28
0
ファイル: vlans.py プロジェクト: achaussier/ansible-ndclt
    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 = []

        vlan_list = vlan_to_list(utils.parse_conf_arg(conf, 'vlan'))
        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')

            vlans.append(utils.remove_empties(config))

        return vlans
コード例 #29
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"^(\S+)", conf)
        intf = match.group(1)
        if get_interface_type(intf) == "unknown":
            return {}
        config["name"] = intf
        config["port_priority"] = utils.parse_conf_arg(conf,
                                                       "lacp port-priority")
        config["rate"] = utils.parse_conf_arg(conf, "lacp rate")
        config["mode"] = utils.parse_conf_arg(conf, "mode")
        suspend_individual = re.search(r"no lacp suspend-individual", conf)
        if suspend_individual:
            config["suspend_individual"] = False
        max_links = utils.parse_conf_arg(conf, "lacp max-bundle")
        if max_links:
            config["links"]["max"] = max_links
        min_links = utils.parse_conf_arg(conf, "lacp min-links")
        if min_links:
            config["links"]["min"] = min_links
        graceful = re.search(r"no lacp graceful-convergence", conf)
        if graceful:
            config["convergence"]["gracefule"] = False
        vpc = re.search(r"lacp vpc-convergence", conf)
        if vpc:
            config["convergence"]["vpc"] = True

        return utils.remove_empties(config)
コード例 #30
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'^(\S+)', conf)
        intf = match.group(1)
        if get_interface_type(intf) == 'unknown':
            return {}
        config['name'] = intf
        config['port_priority'] = utils.parse_conf_arg(conf,
                                                       'lacp port-priority')
        config['rate'] = utils.parse_conf_arg(conf, 'lacp rate')
        config['mode'] = utils.parse_conf_arg(conf, 'mode')
        suspend_individual = re.search(r'no lacp suspend-individual', conf)
        if suspend_individual:
            config['suspend_individual'] = False
        max_links = utils.parse_conf_arg(conf, 'lacp max-bundle')
        if max_links:
            config['links']['max'] = max_links
        min_links = utils.parse_conf_arg(conf, 'lacp min-links')
        if min_links:
            config['links']['min'] = min_links
        graceful = re.search(r'no lacp graceful-convergence', conf)
        if graceful:
            config['convergence']['gracefule'] = False
        vpc = re.search(r'lacp vpc-convergence', conf)
        if vpc:
            config['convergence']['vpc'] = True

        return utils.remove_empties(config)