def map_config_to_obj(module):
    objs = []
    output = run_commands(module, {'command': 'show vrf'})
    if output is not None:
        vrfText = output[0].strip()
        vrfList = vrfText.split('VRF')
        for vrfItem in vrfList:
            if 'FIB ID' in vrfItem:
                obj = dict()
                list_of_words = vrfItem.split()
                vrfName = list_of_words[0]
                obj['name'] = vrfName[:-1]
                obj['rd'] = list_of_words[list_of_words.index('RD') + 1]
                start = False
                obj['interfaces'] = []
                for intName in list_of_words:
                    if 'Interfaces' in intName:
                        start = True
                    if start is True:
                        if '!' not in intName and 'Interfaces' not in intName:
                            obj['interfaces'].append(intName.strip().lower())
                objs.append(obj)
    else:
        module.fail_json(msg='Could not fetch VRF details from device')
    return objs
def get_switchport(name, module):
    config = run_commands(module,
                          ['show interface {0} switchport'.format(name)])[0]
    mode = re.search(r'Switchport mode         : (?:.* )?(\w+)$', config, re.M)
    access = re.search(r'Configured Vlans        : (\d+)', config)
    native = re.search(r'Default/Native Vlan     : (\d+)', config)
    trunk = re.search(r'Enabled Vlans           : (.+)$', config, re.M)
    if mode:
        mode = mode.group(1)
    if access:
        access = access.group(1)
    if native:
        native = native.group(1)
    if trunk:
        trunk = trunk.group(1)
    if trunk == 'ALL':
        trunk = '1-4094'

    switchport_config = {
        "interface": name,
        "mode": mode,
        "access_vlan": access,
        "native_vlan": native,
        "trunk_vlans": trunk,
    }

    return switchport_config
def interface_is_portchannel(name, module):
    if get_interface_type(name) == 'ethernet':
        config = run_commands(module,
                              ['show run interface {0}'.format(name)])[0]
        if any(c in config for c in ['channel group', 'channel-group']):
            return True
    return False
def is_switchport(name, module):
    intf_type = get_interface_type(name)

    if intf_type in ('ethernet', 'portchannel'):
        config = run_commands(
            module, ['show interface {0} switchport'.format(name)])[0]
        match = re.search(r'Switchport              : enabled', config)
        return bool(match)
    return False
Ejemplo n.º 5
0
def get_ethernet_range(module):
    output = run_commands(module, ['show interface brief'])[0].split('\n')
    maxport = None
    last_interface = None
    for line in output:
        if line.startswith('Ethernet1/'):
            last_interface = line.split(' ')[0]
    if last_interface is not None:
        eths = last_interface.split('/')
        maxport = eths[1]
    return maxport
def get_list_of_vlans(module):
    config = run_commands(module, ['show vlan'])[0]
    vlans = set()

    lines = config.strip().splitlines()
    for line in lines:
        line_parts = line.split()
        if line_parts:
            try:
                int(line_parts[0])
            except ValueError:
                continue
            vlans.add(line_parts[0])

    return list(vlans)
def map_config_to_obj(module):
    out = run_commands(module, ['show user-account'])
    data = out[0]
    objects = list()
    datum = data.split('User')

    for item in datum:
        objects.append({
            'name': parse_username(item),
            'configured_password': parse_password(item),
            'sshkey': parse_sshkey(item),
            'roles': parse_roles(item),
            'state': 'present'
        })
    return objects
def map_config_to_obj(module):
    return parse_vlan_brief(run_commands(module, ['show vlan brief'])[0])
 def run(self, cmd):
     return run_commands(self.module, cmd, check_rc=False)
 def populate(self):
     self.responses = run_commands(self.module, self.COMMANDS,
                                   check_rc=False)