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)
Пример #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)
Пример #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 = ''
        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)
Пример #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'(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)
Пример #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 {}

        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)
Пример #6
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)
Пример #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)

        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)
        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
Пример #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)

        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
 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)
Пример #12
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['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 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)
Пример #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)
        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
Пример #15
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
Пример #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)
        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)

        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)
Пример #18
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 match.group(1).lower() == "preconfigure":
            match = re.search(r'^(\S+) (.*)', conf)
            if match:
                intf = match.group(2)

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

        if intf.lower().startswith('gi'):
            config['name'] = intf

            # populate the facts from the configuration
            native_vlan = re.search(r"dot1q native vlan (\d+)", conf)
            if native_vlan:
                config["native_vlan"] = int(native_vlan.group(1))

            dot1q = utils.parse_conf_arg(conf, 'encapsulation dot1q')
            config['q_vlan'] = []
            if dot1q:
                config['q_vlan'].append(int(dot1q.split(' ')[0]))
                if len(dot1q.split(' ')) > 1:
                    config['q_vlan'].append(int(dot1q.split(' ')[2]))

            if utils.parse_conf_cmd_arg(conf, 'l2transport', True):
                config['l2transport'] = True
            if utils.parse_conf_arg(conf, 'propagate'):
                config['propagate'] = True
            config['l2protocol'] = []

            cdp = utils.parse_conf_arg(conf, 'l2protocol cdp')
            pvst = utils.parse_conf_arg(conf, 'l2protocol pvst')
            stp = utils.parse_conf_arg(conf, 'l2protocol stp')
            vtp = utils.parse_conf_arg(conf, 'l2protocol vtp')
            if cdp:
                config['l2protocol'].append({'cdp': cdp})
            if pvst:
                config['l2protocol'].append({'pvst': pvst})
            if stp:
                config['l2protocol'].append({'stp': stp})
            if vtp:
                config['l2protocol'].append({'vtp': vtp})

            return utils.remove_empties(config)
Пример #19
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)

        # 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')

        speed_pair = utils.parse_conf_arg(conf, 'speed')
        if speed_pair:
            state = speed_pair.split()
            if state[0] == 'forced':
                state = state[1]
            else:
                state = state[0]

            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)

        holdtime = utils.parse_conf_arg(conf, 'lldp holdtime')
        timer = utils.parse_conf_arg(conf, 'lldp timer')
        reinit = utils.parse_conf_arg(conf, 'lldp reinit')
        if holdtime:
            config['holdtime'] = int(holdtime)
        if 'lldp run' in conf:
            config['enabled'] = True
        if timer:
            config['timer'] = int(timer)
        if reinit:
            config['reinit'] = int(reinit)

        return utils.remove_empties(config)
    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)
Пример #22
0
    def parse_attribs(self, attribs, conf):
        config = {}
        for item in attribs:
            value = utils.parse_conf_arg(conf, item)
            if value and item == 'mtu':
                config[item] = int(value.strip("'"))
            elif value:
                config[item] = value.strip("'")
            else:
                config[item] = None
        if 'disable' in conf:
            config['enabled'] = False
        else:
            config['enabled'] = True

        return utils.remove_empties(config)
Пример #23
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'(no )?lldp (\S+)', conf)
        for match in matches:
            config[match[1]] = not bool(match[0])

        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)
        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)
    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)