Example #1
0
def get_acl_interface(device, acl):
    """Checks to see if an ACL is applied to an interface

    Args:
        device (Device): This is the device object of an NX-API enabled device
            using the Device class
        acl (str): Name of the ACL

    Returns:
        Dictionary- keys: applied, direction
    """
    command = 'show ip access-list summary'
    data = device.show(command, text=True)
    data_dict = xmltodict.parse(data[1])

    raw_text = data_dict['ins_api']['outputs']['output']['body']

    existing = legacy.get_structured_data('acl_interface.tmpl', raw_text)

    existing_no_null = []
    temp = {}
    for each in existing:
        if each.get('name') == acl:
            temp['interface'] = each.get('interface').lower()
            each.update(temp)
            existing_no_null.append(each)

    return existing_no_null
Example #2
0
def get_acl_interface(device, acl):
    """Checks to see if an ACL is applied to an interface

    Args:
        device (Device): This is the device object of an NX-API enabled device
            using the Device class
        acl (str): Name of the ACL

    Returns:
        Dictionary- keys: applied, direction
    """
    command = "show ip access-list summary"
    data = device.show(command, text=True)
    data_dict = xmltodict.parse(data[1])

    raw_text = data_dict["ins_api"]["outputs"]["output"]["body"]

    existing = legacy.get_structured_data("acl_interface.tmpl", raw_text)

    existing_no_null = []
    temp = {}
    for each in existing:
        if each.get("name") == acl:
            temp["interface"] = each.get("interface").lower()
            each.update(temp)
            existing_no_null.append(each)

    return existing_no_null
Example #3
0
def get_igmp_global(device):
    """Retrieves igmp global configurations

    Args:
        device (Device): This is the device object of an NX-API enabled device
            using the Device class from pycsco

    Returns:
        Dictionary
    """
    command = 'show run igmp'
    data = device.show(command, text=True)
    data_dict = xmltodict.parse(data[1])

    raw_text = data_dict['ins_api']['outputs']['output']['body']

    existing = legacy.get_structured_data('igmp_global.tmpl', raw_text)

    flush = False
    enforce = False
    for each in existing:
        value = each.get('igmp')
        if 'flush' in value:
            flush = True
        elif 'enforce' in value:
            enforce = True

    existing = dict(flush_routes=flush, enforce_rtr_alert=enforce)

    return existing
Example #4
0
def get_igmp_global(device):
    """Retrieves igmp global configurations

    Args:
        device (Device): This is the device object of an NX-API enabled device
            using the Device class from pycsco

    Returns:
        Dictionary
    """
    command = 'show run igmp'
    data = device.show(command, text=True)
    data_dict = xmltodict.parse(data[1])

    raw_text = data_dict['ins_api']['outputs']['output']['body']

    existing = legacy.get_structured_data('igmp_global.tmpl', raw_text)

    flush = False
    enforce = False
    for each in existing:
        value = each.get('igmp')
        if 'flush' in value:
            flush = True
        elif 'enforce' in value:
            enforce = True

    existing = dict(flush_routes=flush, enforce_rtr_alert=enforce)

    return existing
Example #5
0
def get_igmp_snooping(device):
    """Retrieves igmp snooping configurations

    Args:
        device (Device): This is the device object of an NX-API enabled device
            using the Device class from pycsco

    Returns:
        Dictionary
    """

    command = "show ip igmp snooping"
    data = device.show(command, text=True)
    data_dict = xmltodict.parse(data[1])
    raw_text = data_dict["ins_api"]["outputs"]["output"]["body"]

    # existing returns a list of dictionaries
    existing = legacy.get_structured_data("igmp_snooping.tmpl", raw_text)[0]
    if not existing.get("proxy"):
        existing["proxy"] = "5"
    # TODO need to add PROXY BACK INT CONFIG MODULES and ANSIBLE MOD

    command = "show run all | inc snooping"
    data = device.show(command, text=True)
    data_dict = xmltodict.parse(data[1])
    raw_text = data_dict["ins_api"]["outputs"]["output"]["body"]

    command = "show ip igmp snooping"
    data = device.show(command)
    data_dict = xmltodict.parse(data[1])

    try:
        my_data = data_dict["ins_api"]["outputs"]["output"]["body"]

        enabled = my_data.get("enabled")
        link_local_grp_supp = my_data.get("glinklocalgrpsup")
        v3_report_supp = my_data.get("gv3repsup")
        # E Raised this: Enable v3-report-suppression on vlan to take effect...
        # with this command: ip igmp snooping v3-report-suppression
        report_supp = my_data.get("grepsup")
        existing2 = dict(
            snooping=enabled,
            link_local_grp_supp=link_local_grp_supp,
            report_supp=report_supp,
            v3_report_supp=v3_report_supp,
        )
    except (KeyError, AttributeError):
        existing2 = {}
        # need to fix this

    existing2.update(existing)

    for k, v in existing2.items():
        if v in ["true", "enabled"]:
            existing2[k] = True
        elif v in ["false", "disabled"]:
            existing2[k] = False

    return existing2
Example #6
0
def get_igmp_snooping(device):
    """Retrieves igmp snooping configurations

    Args:
        device (Device): This is the device object of an NX-API enabled device
            using the Device class from pycsco

    Returns:
        Dictionary
    """

    command = 'show ip igmp snooping'
    data = device.show(command, text=True)
    data_dict = xmltodict.parse(data[1])
    raw_text = data_dict['ins_api']['outputs']['output']['body']

    # existing returns a list of dictionaries
    existing = legacy.get_structured_data('igmp_snooping.tmpl', raw_text)[0]
    if not existing.get('proxy'):
        existing['proxy'] = '5'
    # TODO need to add PROXY BACK INT CONFIG MODULES and ANSIBLE MOD

    command = 'show run all | inc snooping'
    data = device.show(command, text=True)
    data_dict = xmltodict.parse(data[1])
    raw_text = data_dict['ins_api']['outputs']['output']['body']

    command = 'show ip igmp snooping'
    data = device.show(command)
    data_dict = xmltodict.parse(data[1])

    try:
        my_data = data_dict['ins_api']['outputs']['output']['body']

        enabled = my_data.get('enabled')
        link_local_grp_supp = my_data.get('glinklocalgrpsup')
        v3_report_supp = my_data.get('gv3repsup')
        # E Raised this: Enable v3-report-suppression on vlan to take effect...
        # with this command: ip igmp snooping v3-report-suppression
        report_supp = my_data.get('grepsup')
        existing2 = dict(snooping=enabled,
                         link_local_grp_supp=link_local_grp_supp,
                         report_supp=report_supp,
                         v3_report_supp=v3_report_supp)
    except (KeyError, AttributeError):
        existing2 = {}
        # need to fix this

    existing2.update(existing)

    for k, v in existing2.iteritems():
        if v in ['true', 'enabled']:
            existing2[k] = True
        elif v in ['false', 'disabled']:
            existing2[k] = False

    return existing2
Example #7
0
def get_igmp_snooping(device):
    """Retrieves igmp snooping configurations

    Args:
        device (Device): This is the device object of an NX-API enabled device
            using the Device class from pycsco

    Returns:
        Dictionary
    """

    command = 'show ip igmp snooping'
    data = device.show(command, text=True)
    data_dict = xmltodict.parse(data[1])
    raw_text = data_dict['ins_api']['outputs']['output']['body']

    # existing returns a list of dictionaries
    existing = legacy.get_structured_data('igmp_snooping.tmpl', raw_text)[0]
    if not existing.get('proxy'):
        existing['proxy'] = '5'
    # TODO need to add PROXY BACK INT CONFIG MODULES and ANSIBLE MOD

    command = 'show run all | inc snooping'
    data = device.show(command, text=True)
    data_dict = xmltodict.parse(data[1])
    raw_text = data_dict['ins_api']['outputs']['output']['body']

    command = 'show ip igmp snooping'
    data = device.show(command)
    data_dict = xmltodict.parse(data[1])

    try:
        my_data = data_dict['ins_api']['outputs']['output']['body']

        enabled = my_data.get('enabled')
        link_local_grp_supp = my_data.get('glinklocalgrpsup')
        v3_report_supp = my_data.get('gv3repsup')
        # E Raised this: Enable v3-report-suppression on vlan to take effect...
        # with this command: ip igmp snooping v3-report-suppression
        report_supp = my_data.get('grepsup')
        existing2 = dict(snooping=enabled,
                         link_local_grp_supp=link_local_grp_supp,
                         report_supp=report_supp,
                         v3_report_supp=v3_report_supp)
    except (KeyError, AttributeError):
        existing2 = {}
        # need to fix this

    existing2.update(existing)

    for k, v in existing2.iteritems():
        if v in ['true', 'enabled']:
            existing2[k] = True
        elif v in ['false', 'disabled']:
            existing2[k] = False

    return existing2
Example #8
0
def get_ntp_auth_key(device, key_id):
    ntp_auth_cfg_response = device.show(
        'show run | inc "ntp authentication-key {0}"'.format(key_id),
        text=True)
    ntp_auth_run_cfg = xmltodict.parse(
        ntp_auth_cfg_response[1])["ins_api"]["outputs"]["output"]["body"]
    ntp_auth_data = legacy.get_structured_data("ntp_auth.tmpl",
                                               ntp_auth_run_cfg)
    if len(ntp_auth_data) > 0:
        return ntp_auth_data[0]

    return {}
Example #9
0
def get_ntp_auth_key(device, key_id):
    ntp_auth_cfg_response = device.show(
        'show run | inc "ntp authentication-key {0}"'.format(key_id),
        text=True)
    ntp_auth_run_cfg = xmltodict.parse(
        ntp_auth_cfg_response[1])['ins_api']['outputs']['output']['body']
    ntp_auth_data = legacy.get_structured_data(
        'ntp_auth.tmpl', ntp_auth_run_cfg)
    if len(ntp_auth_data) > 0:
        return ntp_auth_data[0]

    return {}
Example #10
0
def get_ntp_serv_peer(device):
    response = device.show('show run | inc "ntp (server|peer)"', text=True)
    response_dict = xmltodict.parse(response[1])
    serv_peer_str = response_dict["ins_api"]["outputs"]["output"]["body"]
    serv_peer_list = legacy.get_structured_data("ntp_server_peer.tmpl",
                                                serv_peer_str)
    for serv_peer in serv_peer_list:
        if serv_peer["prefer"]:
            serv_peer["prefer"] = "enabled"
        else:
            serv_peer["prefer"] = "disabled"

    return serv_peer_list
Example #11
0
def get_ntp_serv_peer(device):
    response = device.show(
        'show run | inc "ntp (server|peer)"', text=True)
    response_dict = xmltodict.parse(response[1])
    serv_peer_str = response_dict['ins_api']['outputs']['output']['body']
    serv_peer_list = legacy.get_structured_data(
        'ntp_server_peer.tmpl', serv_peer_str)
    for serv_peer in serv_peer_list:
        if serv_peer['prefer']:
            serv_peer['prefer'] = 'enabled'
        else:
            serv_peer['prefer'] = 'disabled'

    return serv_peer_list
Example #12
0
def get_snmp_location(device):
    """Retrieves snmp location from a device

    Args:
        device (Device): This is the device object of an NX-API enabled device
            using the Device class

    Returns:
        dictionary
    """
    command = 'show run snmp'
    data = device.show(command, text=True)
    data_dict = xmltodict.parse(data[1])

    raw_text = data_dict['ins_api']['outputs']['output']['body']

    existing = legacy.get_structured_data('snmp_location.tmpl', raw_text)

    if len(existing) == 1:
        return existing[0]

    return existing
Example #13
0
def get_snmp_location(device):
    """Retrieves snmp location from a device

    Args:
        device (Device): This is the device object of an NX-API enabled device
            using the Device class

    Returns:
        dictionary
    """
    command = "show run snmp"
    data = device.show(command, text=True)
    data_dict = xmltodict.parse(data[1])

    raw_text = data_dict["ins_api"]["outputs"]["output"]["body"]

    existing = legacy.get_structured_data("snmp_location.tmpl", raw_text)

    if len(existing) == 1:
        return existing[0]

    return existing
Example #14
0
def get_igmp_interface(device, interface):
    """Retrieves IGMP interface config params for a given interface

    Args:
        device (Device): This is the device object of an NX-API enabled device
            using the Device class within device.py
        interface (str): full name of the interface

    Returns:
        Dictionary

    """
    command = 'show ip igmp interface ' + interface

    try:
        data = device.show(command)
        data_dict = xmltodict.parse(data[1])
        igmp = {}
    except CLIError:
        return {}

    try:
        resource = data_dict['ins_api']['outputs']['output']['body'].get(
            'TABLE_vrf')['ROW_vrf']['TABLE_if']['ROW_if']
        igmp['version'] = str(resource['IGMPVersion'])
        igmp['startup_query_interval'] = str(
            resource['ConfiguredStartupQueryInterval'])
        igmp['startup_query_count'] = str(resource['StartupQueryCount'])
        igmp['robustness'] = str(resource['RobustnessVariable'])
        igmp['querier_timeout'] = str(resource['QuerierTimeout'])
        igmp['query_mrt'] = str(resource['ConfiguredMaxResponseTime'])
        igmp['query_interval'] = str(resource['ConfiguredQueryInterval'])
        igmp['last_member_qrt'] = str(resource['LastMemberMTR'])
        igmp['last_member_query_count'] = str(resource['LastMemberQueryCount'])
        igmp['group_timeout'] = str(resource['ConfiguredGroupTimeout'])
        report_llg = str(resource['ReportingForLinkLocal'])
        if report_llg == 'true':
            igmp['report_llg'] = True
        elif report_llg == 'false':
            igmp['report_llg'] = False
        igmp['group_timeout'] = str(resource['ConfiguredGroupTimeout'])
        immediate_leave = str(resource['ImmediateLeave'])  # returns en or dis
        if immediate_leave == 'en':
            igmp['immediate_leave'] = True
        elif immediate_leave == 'dis':
            igmp['immediate_leave'] = False

    except (KeyError, AttributeError):
        pass

    # the  next block of code is used to retrieve anything with:
    # ip igmp static-oif *** i.e.. could be route-map ROUTEMAP
    # or PREFIX source <ip>, etc.
    command = 'show run interface {0} | inc oif'.format(interface)
    data = device.show(command, text=True)

    data_dict = xmltodict.parse(data[1])

    raw_text = data_dict['ins_api']['outputs']['output']['body']

    # existing returns a list of dictionaries
    staticoif = legacy.get_structured_data('igmp_static_oif.tmpl', raw_text)
    # staticoif returns a list of dicts

    new_staticoif = []
    temp = {}
    for counter, data in enumerate(staticoif):
        for k, v in data.iteritems():
            if v:
                temp[k] = v
        if temp:
            new_staticoif.append(temp)
        temp = {}

    igmp['oif_routemap'] = None
    igmp['oif_prefix_source'] = []
    if new_staticoif:
        if len(new_staticoif) == 1 and new_staticoif[0].get('routemap'):
            igmp['oif_routemap'] = new_staticoif[0]['routemap']
        else:
            igmp['oif_prefix_source'] = new_staticoif

    return igmp
Example #15
0
def get_igmp_interface(device, interface):
    """Retrieves IGMP interface config params for a given interface

    Args:
        device (Device): This is the device object of an NX-API enabled device
            using the Device class within device.py
        interface (str): full name of the interface

    Returns:
        Dictionary

    """
    command = "show ip igmp interface " + interface

    try:
        data = device.show(command)
        data_dict = xmltodict.parse(data[1])
        igmp = {}
    except CLIError:
        return {}

    try:
        resource = data_dict["ins_api"]["outputs"]["output"]["body"].get(
            "TABLE_vrf"
        )["ROW_vrf"]["TABLE_if"]["ROW_if"]
        igmp["version"] = str(resource["IGMPVersion"])
        igmp["startup_query_interval"] = str(
            resource["ConfiguredStartupQueryInterval"]
        )
        igmp["startup_query_count"] = str(resource["StartupQueryCount"])
        igmp["robustness"] = str(resource["RobustnessVariable"])
        igmp["querier_timeout"] = str(resource["QuerierTimeout"])
        igmp["query_mrt"] = str(resource["ConfiguredMaxResponseTime"])
        igmp["query_interval"] = str(resource["ConfiguredQueryInterval"])
        igmp["last_member_qrt"] = str(resource["LastMemberMTR"])
        igmp["last_member_query_count"] = str(resource["LastMemberQueryCount"])
        igmp["group_timeout"] = str(resource["ConfiguredGroupTimeout"])
        report_llg = str(resource["ReportingForLinkLocal"])
        if report_llg == "true":
            igmp["report_llg"] = True
        elif report_llg == "false":
            igmp["report_llg"] = False
        igmp["group_timeout"] = str(resource["ConfiguredGroupTimeout"])
        immediate_leave = str(resource["ImmediateLeave"])  # returns en or dis
        if immediate_leave == "en":
            igmp["immediate_leave"] = True
        elif immediate_leave == "dis":
            igmp["immediate_leave"] = False

    except (KeyError, AttributeError):
        pass

    # the  next block of code is used to retrieve anything with:
    # ip igmp static-oif *** i.e.. could be route-map ROUTEMAP
    # or PREFIX source <ip>, etc.
    command = "show run interface {0} | inc oif".format(interface)
    data = device.show(command, text=True)

    data_dict = xmltodict.parse(data[1])

    raw_text = data_dict["ins_api"]["outputs"]["output"]["body"]

    # existing returns a list of dictionaries
    staticoif = legacy.get_structured_data("igmp_static_oif.tmpl", raw_text)
    # staticoif returns a list of dicts

    new_staticoif = []
    temp = {}
    for counter, data in enumerate(staticoif):
        for k, v in data.items():
            if v:
                temp[k] = v
        if temp:
            new_staticoif.append(temp)
        temp = {}

    igmp["oif_routemap"] = None
    igmp["oif_prefix_source"] = []
    if new_staticoif:
        if len(new_staticoif) == 1 and new_staticoif[0].get("routemap"):
            igmp["oif_routemap"] = new_staticoif[0]["routemap"]
        else:
            igmp["oif_prefix_source"] = new_staticoif

    return igmp
Example #16
0
def get_igmp_interface(device, interface):
    """Retrieves IGMP interface config params for a given interface

    Args:
        device (Device): This is the device object of an NX-API enabled device
            using the Device class within device.py
        interface (str): full name of the interface

    Returns:
        Dictionary

    """
    command = 'show ip igmp interface ' + interface

    try:
        data = device.show(command)
        data_dict = xmltodict.parse(data[1])
        igmp = {}
    except CLIError:
        return {}

    try:
        resource = data_dict['ins_api']['outputs']['output']['body'].get(
            'TABLE_vrf')['ROW_vrf']['TABLE_if']['ROW_if']
        igmp['version'] = str(resource['IGMPVersion'])
        igmp['startup_query_interval'] = str(
            resource['ConfiguredStartupQueryInterval']
            )
        igmp['startup_query_count'] = str(resource['StartupQueryCount'])
        igmp['robustness'] = str(resource['RobustnessVariable'])
        igmp['querier_timeout'] = str(resource['QuerierTimeout'])
        igmp['query_mrt'] = str(resource['ConfiguredMaxResponseTime'])
        igmp['query_interval'] = str(resource['ConfiguredQueryInterval'])
        igmp['last_member_qrt'] = str(resource['LastMemberMTR'])
        igmp['last_member_query_count'] = str(resource['LastMemberQueryCount'])
        igmp['group_timeout'] = str(resource['ConfiguredGroupTimeout'])
        report_llg = str(resource['ReportingForLinkLocal'])
        if report_llg == 'true':
            igmp['report_llg'] = True
        elif report_llg == 'false':
            igmp['report_llg'] = False
        igmp['group_timeout'] = str(resource['ConfiguredGroupTimeout'])
        immediate_leave = str(resource['ImmediateLeave'])  # returns en or dis
        if immediate_leave == 'en':
            igmp['immediate_leave'] = True
        elif immediate_leave == 'dis':
            igmp['immediate_leave'] = False

    except (KeyError, AttributeError):
        pass

    # the  next block of code is used to retrieve anything with:
    # ip igmp static-oif *** i.e.. could be route-map ROUTEMAP
    # or PREFIX source <ip>, etc.
    command = 'show run interface {0} | inc oif'.format(interface)
    data = device.show(command, text=True)

    data_dict = xmltodict.parse(data[1])

    raw_text = data_dict['ins_api']['outputs']['output']['body']

    # existing returns a list of dictionaries
    staticoif = legacy.get_structured_data('igmp_static_oif.tmpl', raw_text)
    # staticoif returns a list of dicts

    new_staticoif = []
    temp = {}
    for counter, data in enumerate(staticoif):
        for k, v in data.iteritems():
            if v:
                temp[k] = v
        if temp:
            new_staticoif.append(temp)
        temp = {}

    igmp['oif_routemap'] = None
    igmp['oif_prefix_source'] = []
    if new_staticoif:
        if len(new_staticoif) == 1 and new_staticoif[0].get('routemap'):
            igmp['oif_routemap'] = new_staticoif[0]['routemap']
        else:
            igmp['oif_prefix_source'] = new_staticoif

    return igmp