Exemple #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 {}
        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)
Exemple #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 {}
        # 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 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)

        ipv4 = []
        ipv4_all = re.findall(r"ip address (\S+.*)", conf)
        for each in ipv4_all:
            each_ipv4 = dict()
            if 'secondary' not in each and 'dhcp' not in each:
                each_ipv4['address'] = each
            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])
                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)
 def set_config(self, existing_l3_interfaces_facts):
     """ Collect the configuration from the args passed to the module,
         collect the current configuration (as a dict from facts)
     :rtype: A list
     :returns: the commands necessary to migrate the current configuration
               to the desired configuration
     """
     config = self._module.params.get("config")
     want = []
     if config:
         for each in config:
             each.update({"name": normalize_interface(each["name"])})
             want.append(each)
     have = existing_l3_interfaces_facts
     resp = self.set_state(want, have)
     return to_list(resp)
Exemple #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 {}

        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_mode = utils.parse_conf_arg(conf, 'switchport mode')
            if has_mode:
                config['mode'] = has_mode
            has_access = utils.parse_conf_arg(conf, 'switchport access vlan')
            if has_access:
                config["access"] = {"vlan": int(has_access)}

            has_voice = utils.parse_conf_arg(conf, 'switchport voice vlan')
            if has_voice:
                config["voice"] = {"vlan": int(has_voice)}

            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)
        match = re.search(r'^(\S+)', conf)
        intf = match.group(1)

        if get_interface_type(intf) == 'unknown':
            return {}
        member_config = {}
        channel_group = utils.parse_conf_arg(conf, 'channel-group')
        if intf.startswith('Gi'):
            config['name'] = intf
            config['members'] = []
            if channel_group:
                channel_group = channel_group.split(' ')
                id = channel_group[0]
                config['name'] = 'Port-channel{0}'.format(str(id))
                if 'mode' in channel_group:
                    mode = channel_group[2]
                    member_config.update({'mode': mode})
                if 'link' in channel_group:
                    link = channel_group[2]
                    member_config.update({'link': link})
            if member_config.get('mode') or member_config.get('link'):
                member_config['member'] = normalize_interface(intf)
                config['members'].append(member_config)

        return utils.remove_empties(config)
Exemple #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)
        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)
            trunk = dict()

            # Scans configuration of port for "switchport mode" and if access, puts in access bits, if trunk puts in trunk bits, if neither looks for other lines and potentially adds both.
            swport_mode = utils.parse_conf_arg(conf, 'switchport mode')
            if swport_mode == 'access':
                has_access = utils.parse_conf_arg(conf,
                                                  'switchport access vlan')
                if has_access:
                    config["access"] = {
                        "vlan": int(has_access),
                    }
                if not has_access:
                    config["access"] = {
                        "vlan": 1,
                    }
            elif swport_mode == 'trunk':
                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(',')
                if not allowed_vlan:
                    trunk["allowed_vlans"] = 'all'
                pruning_vlan = utils.parse_conf_arg(conf, 'pruning vlan')
                if pruning_vlan:
                    trunk['pruning_vlans'] = pruning_vlan.split(',')
            else:
                has_access = utils.parse_conf_arg(conf,
                                                  'switchport access vlan')
                if has_access:
                    config["access"] = {
                        "vlan": int(has_access),
                    }
                trunk["encapsulation"] = utils.parse_conf_arg(
                    conf, 'encapsulation')
                if not has_access:
                    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(',')
                    if not allowed_vlan:
                        trunk["allowed_vlans"] = 'all'
                    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)