Exemple #1
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
    def __init__(self,
                 ifindex=None,
                 ifname=None,
                 cps_data=None,
                 switch_id=0,
                 list_of_attr_value_pairs=[]):

        if cps_data is not None:
            self.cps_data = cps_data
            return

        self.cps_data = None
        self.cps_obj_wr = utl.CPSObjWrp(self.yang_name, self.get_type_map())

        if ifindex is not None:
            self.cps_obj_wr.add_leaf_attr('port-id', ifindex)
        elif ifname is not None:
            ifindex = ifindex_utils.if_nametoindex(ifname)
            if ifindex is None:
                raise RuntimeError("Port " + ifname + " not available")
            self.cps_obj_wr.add_leaf_attr('port-id', ifindex)

        self.cps_obj_wr.add_leaf_attr('switch-id', switch_id)

        for pair in list_of_attr_value_pairs:
            self.set_attr(pair[0], pair[1])
Exemple #3
0
def get_parent_sched_group_id(ifname, child_id):
    """
    Get the parent scheduler group id
    @ifname interface nae
    @child_id queue_id or scheduler_group_id
    @return parent scheduler_group_id or None
    Sample: get_parent_sched_group_id('e101-032-0', 281474976711181)

    """
    # find the parent with a matching child qid
    sg_info = {}
    return_data_list = []

    port_id = ifindex_utils.if_nametoindex(ifname)
    attr_list = {
        'port-id': port_id,
        'level': None,
        'id': None,
    }
    sg_obj = SchedGroupCPSObj(map_of_attr=attr_list)
    ret = cps.get([sg_obj.data()], return_data_list)
    if ret:
        for cps_ret_data in return_data_list:
            m = SchedGroupCPSObj(cps_data=cps_ret_data)
            sg_id = m.extract_attr('id')
            child_list = m.extract_attr('child-list')
            if (child_list and
                    child_id in child_list):
                return sg_id
    else:
        print 'Error in get'

    return None
Exemple #4
0
def get_port_queue_id(ifname, queue_number, queue_type):
    """
    Get Queue id
    Sample: get_port_queue_id('e101-032-0', 1, 'UCAST')
    """
    return_data_list = []
    port_id = ifindex_utils.if_nametoindex(ifname)

    attr_list = {
        'type': queue_type,
        'queue-number': queue_number,
        'port-id': port_id,
    }
    queue_obj = QueueCPSObj(map_of_attr=attr_list)
    ret = cps.get([queue_obj.data()], return_data_list)

    if ret:
        for cps_ret_data in return_data_list:
            m = QueueCPSObj(cps_data=cps_ret_data)
            if (m.extract_attr('type') == queue_type and
                    m.extract_attr('queue-number') == queue_number):
                return m.extract_id()
    else:
        print 'Error in get'

    return None
    def __init__(self,
                 port_name=None,
                 level=None,
                 switch_id=0,
                 sg_id=None,
                 sched_id=None,
                 chld_id_list=[],
                 cps_data=None):
        if cps_data is not None:
            self.cps_data = cps_data
            return

        self.cps_obj_wr = utl.CPSObjWrp(self.yang_name, self.get_type_map())
        self.cps_data = self.cps_obj_wr.get()
        self.set_attr('switch-id', switch_id)
        if port_name is not None:
            port_id = ifindex_utils.if_nametoindex(port_name)
            self.set_attr('port-id', port_id)
        if sg_id is not None:
            self.set_attr('id', sg_id)
        if level is not None:
            self.set_attr('level', level)
        if sched_id is not None:
            self.set_attr('scheduler-profile-id', sched_id)
        if chld_id_list is not None and isinstance(
                chld_id_list, list) and len(chld_id_list) > 0:
            self.set_attr('child_count', len(chld_id_list))
            self.set_attr('child-list', chld_id_list)
Exemple #6
0
def __create_vtep_if(vtep_name, vni, src_ip, addr_family):
    """Method to create vtep interface in Linux"""
    if __if_present(vtep_name) is False and \
       dn_base_ip_tool.create_vxlan_if(str(vtep_name), str(vni),
                                       str(src_ip), addr_family) is True:
        nas_if.log_info("Successfully created VTEP Interface " +
                        str(vtep_name))
        if_index = ifindex_utils.if_nametoindex(vtep_name)
        return True, if_index
    nas_if.log_err("Failed to create VTEP Interface " + str(vtep_name))
    return False, None
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
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
        port_name = cps_obj.get_attr_data('if/interfaces/interface/name')
        name_list.append(port_name)
    name_list.sort()
    return name_list[0]

if __name__ == '__main__':
    if len(sys.argv) >= 2:
        port_name = sys.argv[1]
    else:
        port_name = get_first_phy_port()
    if port_name is None:
        print 'Could not find front port'
        sys.exit(0)
    print 'Using port %s' % port_name

    port_id = ifindex_utils.if_nametoindex(port_name)

    # Create scheduler profile
    sched_id_l0 = scheduler_profile_create_example(
        'WRR', 50, 100, 100, 500, 100)
    if sched_id_l0 is None:
        sys.exit(0)
    sched_id_l1 = scheduler_profile_create_example(
        'WRR', 30, 50, 100, 200, 100)
    if sched_id_l1 is None:
        sys.exit(0)
    sched_id_l2 = scheduler_profile_create_example(
        'WDRR', 30, 50, 100, 200, 100)
    if sched_id_l2 is None:
        sys.exit(0)