示例#1
0
def _get_ip_addr_obj(filt, resp):
    af = _get_af_from_obj(filt)
    name = _get_key_from_obj(filt)

    lst = dn_base_ip_tool.get_if_details(name)

    for _if in lst:

        for ip in _if.ip:
            if not _ip_line_type_valid(af, ip):
                continue

            o = create_obj_from_line(
                'base-ip/' + af + '/address',
                _if.ifix,
                _if.ifname)
            if not filt.key_compare(
                {'base-ip/' + af + '/name': o.get_attr_data('base-ip/' + af + '/name'),
                                   'base-ip/' + af + '/ifindex': o.get_attr_data('base-ip/' + af + '/ifindex')}):
                continue

            process_ip_line(af, o.get()['data'], ip)
            resp.append(o.get())

    return True
示例#2
0
def _get_ip_addr_obj(filt, resp):
    af = _get_af_from_obj(filt)
    name = _get_key_from_obj(filt)

    lst = dn_base_ip_tool.get_if_details(name)

    for _if in lst:

        for ip in _if.ip:
            if not _ip_line_type_valid(af, ip):
                continue

            o = create_obj_from_line(
                'base-ip/' + af + '/address',
                _if.ifix,
                _if.ifname)
            if not filt.key_compare(
                {'base-ip/' + af + '/name': o.get_attr_data('base-ip/' + af + '/name'),
                                   'base-ip/' + af + '/ifindex': o.get_attr_data('base-ip/' + af + '/ifindex')}):
                continue

            process_ip_line(af, o.get()['data'], ip)
            resp.append(o.get())

    return True
示例#3
0
def _get_ip_objs(filt, resp):
    af = _get_af_from_obj(filt)
    name = _get_key_from_obj(filt)

    lst = dn_base_ip_tool.get_if_details(name)

    for _if in lst:
        o = create_obj_from_line('base-ip/' + af, _if.ifix, _if.ifname)

        if not filt.key_compare(
            {'base-ip/' + af + '/name': o.get_attr_data('base-ip/' + af + '/name'),
                               'base-ip/' + af + '/ifindex': o.get_attr_data('base-ip/' + af + '/ifindex')}):
            continue

        fwd = _get_proc_variable(
            _get_proc_fwd_entry(o.get_attr_data('base-ip/' + af + '/name'), af))
        if fwd == -1:
            fwd = 0
        o.add_attr('base-ip/' + af + '/enabled', 1)
        o.add_attr('base-ip/' + af + '/forwarding', fwd)

        for _ip in _if.ip:
            add_ip_info(af, o, _ip)
        resp.append(o.get())

    return True
def create_macvlan_interface(obj):
    data = obj.get()['data']
    nas_if.log_info("data = " + str(data))
    vrf = 'default'

    #Check if attributes are present in the object or not
    if if_name not in data or parent_interface not in data or physical_addr not in data:
        nas_if.log_err("Missing Macvlan interface, or parent interface or mac address attribute")
        return False

    if vrf_name in data:
        vrf = obj.get_attr_data(vrf_name)

    #Get the attribute data
    name = obj.get_attr_data(if_name)
    parent_if = obj.get_attr_data(parent_interface)
    mac_addr = obj.get_attr_data(physical_addr)

    #Check if the attributes are empty strings or not
    if name is None or parent_if is None or mac_addr is None:
        nas_if.log_err("Empty Maclvan interface, or parent interface, or mac address")
        return False

    # Check if interface already exists
    lst = dn_base_ip_tool.get_if_details(vrf, name)
    if (len(lst)) > 0:
        nas_if.log_err("Interface " + str(name) + " already exists")
        return False

    rc = dn_base_ip_tool.create_macvlan_if(name, parent_if, mac_addr, vrf)
    if rc:
        nas_if.log_info("Macvlan interface " + str(name) + " is created")
        rc = set_macvlan_interface(obj)

    return rc
示例#5
0
def _get_ip_objs(filt, resp):
    af = _get_af_from_obj(filt)
    name = _get_key_from_obj(filt)

    lst = dn_base_ip_tool.get_if_details(name)

    for _if in lst:
        o = create_obj_from_line('base-ip/' + af, _if.ifix, _if.ifname)

        if not filt.key_compare(
            {'base-ip/' + af + '/name': o.get_attr_data('base-ip/' + af + '/name'),
                               'base-ip/' + af + '/ifindex': o.get_attr_data('base-ip/' + af + '/ifindex')}):
            continue

        fwd = _get_proc_variable(
            _get_proc_fwd_entry(o.get_attr_data('base-ip/' + af + '/name'), af))
        if fwd == -1:
            fwd = 0
        o.add_attr('base-ip/' + af + '/enabled', 1)
        o.add_attr('base-ip/' + af + '/forwarding', fwd)

        for _ip in _if.ip:
            add_ip_info(af, o, _ip)
        resp.append(o.get())

    return True
示例#6
0
def get_cb(methods, params):
    obj = cps_object.CPSObject(obj=params['filter'])
    resp = params['list']
    try:
        name = _get_name_from_obj(obj)

        lst = dn_base_ip_tool.get_if_details(name)

        for _if in lst:
            o = cps_object.CPSObject(
                'base-interface/entry',
                data={'name': _if.ifname,
                      'ifindex': _if.ifix})

            if not obj.key_compare({_name_field: _if.ifname,
                                    _ifindex_field: _if.ifix}):
                continue

            o.add_attr('mtu', _if.mtu)
            o.add_attr('admin-status', _if.state)
            o.add_attr('oper-status', _if.oper_state)
            if _if.mac is not None:
                o.add_attr('mac-address', _if.mac)
            resp.append(o.get())

        return True
    except Exception as ex:
        print ex
        print ex.print_exc()
    return False
示例#7
0
def create_loopback_interface(obj, params):
    name = None
    mac_str = None
    mac = None
    try:
        name = obj.get_attr_data('if/interfaces/interface/name')
        mac_str = obj.get_attr_data(
            'dell-if/if/interfaces/interface/phys-address')
    except:
        pass
    if name is None:
        nas_if.log_err("Failed to create interface without name")
        return False
    nas_if.log_info("interface name is" + str(name))
    lst = dn_base_ip_tool.get_if_details(name)
    if (len(lst)) > 0:
        nas_if.log_err("Interface already exists" + str(name))
        return False
    if mac_str is None:
        mac_str = ma.get_offset_mac_addr(ma.get_base_mac_addr(), 0)
    rc = dn_base_ip_tool.create_loopback_if(name, mac=mac_str)
    if rc:
        nas_if.log_info("loopback interface is created" + str(name))
        rc = set_loopback_interface(obj)
        if_index = ifindex_utils.if_nametoindex(name)
        obj.add_attr(nas_comm.yang.get_value('if_index', 'attr_name'),
                     if_index)
        params['change'] = obj.get()
    return rc
示例#8
0
def __if_present(name):
    """Method to check if the interface is present in linux"""
    if len(dn_base_ip_tool.get_if_details(name)) > 0:
        nas_if.log_info("Interface exists " + str(name))
        return True
    nas_if.log_info("Interface doesn't exist " + str(name))
    return False
示例#9
0
def _get_ip_addr_obj(filt, resp):
    af = _get_af_from_obj(filt)
    name = _get_key_from_obj(filt)

    vrf_name = None
    try:
        vrf_name = filt.get_attr_data('base-ip/' + af + '/vrf-name')
    except:
        # VRF-name is optional attribute.
        pass

    lst = dn_base_ip_tool.get_if_details(vrf_name, name)

    for _if in lst:

        for ip in _if.ip:
            if not _ip_line_type_valid(af, ip):
                continue

            o = create_obj_from_line('base-ip/' + af + '/address', _if.ifix,
                                     _if.ifname, _if.vrf_name)
            if not filt.key_compare({
                    'base-ip/' + af + '/name':
                    o.get_attr_data('base-ip/' + af + '/name'),
                    'base-ip/' + af + '/ifindex':
                    o.get_attr_data('base-ip/' + af + '/ifindex')
            }):
                continue

            process_ip_line(af, o.get()['data'], ip)
            resp.append(o.get())

    return True
示例#10
0
def get_cb(methods, params):
    obj = cps_object.CPSObject(obj=params['filter'])
    resp = params['list']
    try:
        name = _get_name_from_obj(obj)

        lst = dn_base_ip_tool.get_if_details(name)

        for _if in lst:
            o = cps_object.CPSObject('base-interface/entry',
                                     data={
                                         'name': _if.ifname,
                                         'ifindex': _if.ifix
                                     })

            if not obj.key_compare({
                    _name_field: _if.ifname,
                    _ifindex_field: _if.ifix
            }):
                continue

            o.add_attr('mtu', _if.mtu)
            o.add_attr('admin-status', _if.state)
            o.add_attr('oper-status', _if.oper_state)
            if _if.mac is not None:
                o.add_attr('mac-address', _if.mac)
            resp.append(o.get())

        return True
    except Exception as ex:
        print ex
        print ex.print_exc()
    return False
示例#11
0
def _get_ip_objs(filt, resp):
    af = _get_af_from_obj(filt)
    name = _get_key_from_obj(filt)

    vrf_name = None
    try:
        vrf_name = filt.get_attr_data('base-ip/' + af + '/vrf-name')
    except:
        # VRF-name is optional attribute.
        pass
    if (vrf_name is None) and (name is not None):
        vrf_name = 'default'

    lst = dn_base_ip_tool.get_if_details(vrf_name, name)

    for _if in lst:
        o = create_obj_from_line('base-ip/' + af, _if.ifix, _if.ifname, _if.vrf_name)

        name = o.get_attr_data('base-ip/' + af + '/name')
        if not filt.key_compare(
            {'base-ip/' + af + '/name': name,
                               'base-ip/' + af + '/ifindex': o.get_attr_data('base-ip/' + af + '/ifindex')}):
            continue

        fwd = _get_proc_variable(
            _get_proc_fwd_entry(o.get_attr_data('base-ip/' + af + '/name'), af))
        if fwd == -1:
            fwd = 0
        o.add_attr('base-ip/' + af + '/forwarding', fwd)

        if af == 'ipv6':
            enabled = _ipv6_enable_status.get(name, None)
            log_msg = 'IPv6 intf-name:' + name + ' enabled status in DB:' + str(enabled)
            log_info(log_msg)
            if enabled is None:
                enabled = 1
                disable_ipv6 = _get_proc_variable(_get_proc_disable_ipv6_entry(name))
                if disable_ipv6 == -1 or disable_ipv6 == 1:
                    enabled = 0
            o.add_attr('base-ip/' + af + '/enabled', enabled)
            autoconf = _get_proc_variable(_get_proc_ipv6_autoconf_entry(name))
            if autoconf == -1 or autoconf == 0:
                autoconf = 0
            o.add_attr('base-ip/' + af + '/autoconf', autoconf)
            accept_dad = _get_proc_variable(_get_proc_ipv6_accept_dad_entry(name))
            if accept_dad != 1 and accept_dad != -1:
                o.add_attr('base-ip/' + af + '/accept-dad', accept_dad + 1)

            log_msg = 'IPv6 intf-name:' + name + ' fwd status:' + str(fwd) + ' ipv6 status:' \
                       + str(enabled) + 'auto conf:' + str(autoconf) + 'accept_dad:' + str(accept_dad)
            log_info(log_msg)
        else:
            log_msg = 'IPv4 intf-name:' + name + ' fwd status:' + str(fwd)
            log_info(log_msg)

        for _ip in _if.ip:
            add_ip_info(af, o, _ip)
        resp.append(o.get())

    return True
示例#12
0
def get_intf_ip_addr(ip_type, if_name):
    info_list = ip_tool.get_if_details(if_name)
    if len(info_list) == 0:
        log_err('Failed to get information of interface %s' % if_name)
        return None
    for af, addr, mask in info_list[0].ip:
        if ((af == 'inet' and ip_type == 'ipv4')
                or (af == 'inet6' and ip_type == 'ipv6')):
            return addr
    return ''
示例#13
0
def handle_create_op(obj, params):

    # if no mac specified use the system MAC
    mac = None
    try:
        mac = obj.get_attr_data('base-interface/entry/mac-address')
    except:
        pass

    if mac is None:
        chassis_obj = cps_object.CPSObject('base-pas/chassis')
        l = []
        if cps.get([chassis_obj.get()], l) and len(l) > 0:
            chassis_obj = cps_object.CPSObject(obj=l[0])
            try:
                mac = chassis_obj.get_attr_data(
                    'base-pas/chassis/base_mac_addresses')
            except:
                pass
    else:
        # since we will set it via the set method.. don't bother setting it at
        # init time
        mac = None

    name = None
    try:
        name = obj.get_attr_data('base-interface/entry/name')
    except:
        pass

    if name is None:
        print("Failed to create interface without name")
        return False

    lst = dn_base_ip_tool.get_if_details(name)

    if len(lst) > 0:
        print("Failed to create an existing interface ", name)
        return False

    rc = dn_base_ip_tool.create_loopback_if(name, mac=mac)

    if rc:
        rc = handle_set_obj(obj)
        if_index = ifindex_utils.if_nametoindex(name)
        obj.add_attr('base-interface/entry/ifindex', if_index)
        params['change'] = obj.get()

    return rc
示例#14
0
def handle_create_op(obj, params):

    # if no mac specified use the system MAC
    mac = None
    try:
        mac = obj.get_attr_data('base-interface/entry/mac-address')
    except:
        pass

    if mac is None:
        chassis_obj = cps_object.CPSObject('base-pas/chassis')
        l = []
        if cps.get([chassis_obj.get()], l) and len(l) > 0:
            chassis_obj = cps_object.CPSObject(obj=l[0])
            try:
                mac = chassis_obj.get_attr_data(
                    'base-pas/chassis/base_mac_addresses')
            except:
                pass
    else:
        # since we will set it via the set method.. don't bother setting it at
        # init time
        mac = None

    name = None
    try:
        name = obj.get_attr_data('base-interface/entry/name')
    except:
        pass

    if name is None:
        print("Failed to create interface without name")
        return False

    lst = dn_base_ip_tool.get_if_details(name)

    if len(lst) > 0:
        print("Failed to create an existing interface ", name)
        return False

    rc = dn_base_ip_tool.create_loopback_if(name, mac=mac)

    if rc:
        rc = handle_set_obj(obj)
        if_index = ifindex_utils.if_nametoindex(name)
        obj.add_attr('base-interface/entry/ifindex', if_index)
        params['change'] = obj.get()

    return rc