def _clear_config(self, want, have):
        # Delete the interface config based on the want and have config
        commands = []

        if want.get('name'):
            interface_type = get_interface_type(want['name'])
            interface = 'interface ' + want['name']
        else:
            interface_type = get_interface_type(have['name'])
            interface = 'interface ' + have['name']

        if have.get('description'
                    ) and want.get('description') != have.get('description'):
            remove_command_from_config_list(interface, 'description', commands)
        if not have.get(
                'enabled') and want.get('enabled') != have.get('enabled'):
            # if enable is False set enable as True which is the default behavior
            remove_command_from_config_list(interface, 'shutdown', commands)

        if interface_type.lower() == 'gigabitethernet':
            if have.get('speed') and have.get('speed') != 'auto' and want.get(
                    'speed') != have.get('speed'):
                remove_command_from_config_list(interface, 'speed', commands)
            if have.get(
                    'duplex') and have.get('duplex') != 'auto' and want.get(
                        'duplex') != have.get('duplex'):
                remove_command_from_config_list(interface, 'duplex', commands)
            if have.get('mtu') and want.get('mtu') != have.get('mtu'):
                remove_command_from_config_list(interface, 'mtu', commands)

        return commands
Beispiel #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 = ''
        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)
Beispiel #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)
    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)
Beispiel #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)
        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 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)}

            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)
Beispiel #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'^(\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)