def if_media_type_set(pas_media_obj): try: media_id = pas_media_obj.get_attr_data('port') media_type = pas_media_obj.get_attr_data('type') except: nas_if.log_err( "media Id or media type is not present in the media event") return # fetch FP info from media ID l = nas_if.nas_os_fp_list(d={'media-id': media_id}) if len(l) == 0: nas_if.log_err("No such port found... for media " + str(media_id)) return # fetch PHY port list for the FP port port_list = nas_if.physical_ports_for_front_panel_port( cps_object.CPSObject(obj=l[0])) if len(port_list) == 0: nas_if.log_err("There are no physical ports for front panel port ") nas_if.log_err(l[0]) return # create interface set RPC obj for each phy port in the list and send it for p in port_list: npu = p.get_attr_data('npu-id') port = p.get_attr_data('port-id') fanout = p.get_attr_data('fanout-mode') hwport = p.get_attr_data('hardware-port-id') nas_if.log_info("send if rpc for media id set for phy port " + str(port)) ifobj = cps_object.CPSObject( module='dell-base-if-cmn/set-interface', data={ 'dell-base-if-cmn/set-interface/input/operation': 3, 'base-if-phy/if/interfaces/interface/npu-id': npu, 'base-if-phy/if/interfaces/interface/port-id': port, 'base-if-phy/if/interfaces/interface/phy-media': media_type, 'if/interfaces/interface/type': "ianaift:ethernetCsmacd" }) ch = {'operation': 'rpc', 'change': ifobj.get()} cps.transaction([ch]) if_name = ba.ba_to_str( ch['change']['data']['if/interfaces/interface/name'], len(_if_name)) if_details = nas_if.nas_os_if_list( d={'if/interfaces/interface/name': if_name}) enable = ba.from_ba( if_details[0]['data']['if/interfaces/interface/enabled'], "uint64_t") fp_details = fp.find_port_by_hwport(npu, hwport) if fanout == 2: # then it is in 4x10G fanout mode BASE_PORT_BREAKOUT_MODE_BREAKOUT_4X1 _lane = fp_details.lane else: # non-fanout mode 1x40g mode _lane = None # enable/disable all channels. Do not pass Lane # media_transceiver_set(1, fp_details.media_id, _lane, enable) nas_if.log_info("setting media id: " + str(media_id) + " media type: " + str(media_type))
def extract_cps_attr(qos_obj, cps_data, attr_name, yang_name=None): """ Get value for attr from the CPS data returned by Create or Get @cps_data - CPS data returned by Create or Get """ if yang_name is None: yang_name = qos_obj.yang_name type_map = qos_obj.get_type_map() cps_obj = extract_cps_obj(cps_data) path = name_to_path(yang_name, attr_name) if 'cps/key_data' in cps_obj and \ path in cps_obj['cps/key_data']: return extract_cps_attr(qos_obj, cps_obj['cps/key_data'], attr_name) if path not in cps_obj: return None val = cps_obj[path] prfx = enum_prefix(type_map, attr_name) atype = attr_type(type_map, attr_name) if prfx is not None: der_val = ba_utils.from_ba(val, 'uint32_t') der_val = enum_reverse_get(der_val, enum_prefix(type_map, attr_name)) elif atype is not None: if isinstance(val, list): der_val = [] for ba_val in val: attr_val = ba_utils.from_ba(ba_val, atype) der_val.append(attr_val) else: if atype != 'string': der_val = ba_utils.from_ba(val, atype) else: der_val = ba_utils.ba_to_str(val, len(val)) else: return val return der_val