def list_ports(self, client, ports, internal_port=False, all=False): field_fmt = self._get_field_format(internal_port) port_status_map = client.getPortStatus(ports) qsfp_info_map = utils.get_qsfp_info_map( self._qsfp_client, None, continue_on_error=True) port_info_map = client.getAllPortInfo() missing_port_status = [] for port_info in sorted(port_info_map.values(), key=utils.port_sort_fn): port_id = port_info.portId if ports and (port_id not in ports): continue status = port_status_map.get(port_id) if not status: missing_port_status.append(port_id) continue qsfp_present = False # For non QSFP ports (think Fabric port) qsfp_client # will not return any information. if status.transceiverIdx and self._qsfp_client: qsfp_info = qsfp_info_map.get( status.transceiverIdx.transceiverId) qsfp_present = qsfp_info.present if qsfp_info else False attrs = utils.get_status_strs(status, qsfp_present) if internal_port: speed = attrs['speed'] if not speed: speed = '-' print(field_fmt.format( port_id, port_info.name, attrs['admin_status'], attrs['color_align'], attrs['link_status'], attrs['present'], speed)) elif all: name = port_info.name if port_info.name else port_id print(field_fmt.format( name, attrs['admin_status'], attrs['color_align'], attrs['link_status'], attrs['present'], attrs['speed'])) elif status.enabled: name = port_info.name if port_info.name else port_id print(field_fmt.format( name, attrs['admin_status'], attrs['color_align'], attrs['link_status'], attrs['present'], attrs['speed'])) if missing_port_status: print(utils.make_error_string( "Could not get status of ports {}".format(missing_port_status)))
def list_ports(self, ports, internal_port=False): field_fmt = self._get_field_format(internal_port) port_status_map = self._client.getPortStatus(ports) qsfp_info_map = utils.get_qsfp_info_map( self._qsfp_client, None, continue_on_error=True) port_info_map = self._client.getAllPortInfo() missing_port_status = [] for port_info in sorted(port_info_map.values(), key=utils.port_sort_fn): port_id = port_info.portId if ports and (port_id not in ports): continue status = port_status_map.get(port_id) if not status: missing_port_status.append(port_id) continue # The transceiver id can be derived from port name # e.g. port name eth1/4/1 -> transceiver_id is 4-1 = 3 # (-1 because we start counting transceivers at 0) transceiver_id = utils.port_sort_fn(port_info)[2] - 1 qsfp_info = qsfp_info_map.get(transceiver_id) qsfp_present = None if self._qsfp_client: # For non QSFP ports (think Fabric port) qsfp_client # will not return any information. qsfp_present = qsfp_info.present if qsfp_info else False attrs = utils.get_status_strs(status, qsfp_present) if internal_port: speed = attrs['speed'] if not speed: speed = '-' print(field_fmt.format( port_id, port_info.name, attrs['admin_status'], attrs['color_align'], attrs['link_status'], attrs['present'], speed)) elif status.enabled: name = port_info.name if port_info.name else port_id print(field_fmt.format( name, attrs['admin_status'], attrs['color_align'], attrs['link_status'], attrs['present'], attrs['speed'])) if missing_port_status: print(utils.make_error_string( "Could not get status of ports {}".format(missing_port_status)))