def _print_transceiver_ports(self, ch_to_port, info): # Print port info if the transceiver doesn't have any for port in ch_to_port.values(): attrs = utils.get_status_strs(self._status_resp[port]) print("Port: {:>2} Status: {:<8} Link: {:<4} Transceiver: {}" .format(port, attrs['admin_status'], attrs['link_status'], attrs['present']))
def _print_port_detail(self): """print port details""" if not self._qsfp_client: self._print_transceiver_ports(self._status_resp.keys(), None) return # If a port does not have a mapping to a transceiver, we should # still print it, lest we skip ports in the detail display. transceiver_printed = [] for port, status in sorted(self._status_resp.items()): if status.transceiverIdx: tid = status.transceiverIdx.transceiverId if tid not in transceiver_printed: self._print_transceiver_details(tid) transceiver_printed.append(tid) else: attrs = utils.get_status_strs(self._status_resp[port], is_present=False) print( "Port: {:>2} Status: {:<8} Link: {:<4} Transceiver: {}". format( port, attrs["admin_status"], attrs["link_status"], attrs["present"], ))
def _print_transceiver_ports(self, ch_to_port, info): # Print port info if the transceiver doesn't have any for port in ch_to_port.values(): attrs = utils.get_status_strs(self._status_resp[port]) print("Port: {:>2} Status: {:<8} Link: {:<4} Transceiver: {}". format(port, attrs['admin_status'], attrs['link_status'], attrs['present']))
def list_ports(self, ports): try: field_fmt = '{:>10} {:>12} {}{:>10} {:>12} {:>6}' print( field_fmt.format('Port', 'Admin State', '', 'Link State', 'Transceiver', 'Speed')) print('-' * 59) resp = self._client.getPortStatus(ports) port_info = self._client.getAllPortInfo() for port_data in sorted(port_info.values(), key=utils.port_sort_fn): port = port_data.portId if port not in resp: continue status = resp[port] attrs = utils.get_status_strs(status) if status.enabled: name = port_data.name if port_data.name else port print( field_fmt.format(name, attrs['admin_status'], attrs['color_align'], attrs['link_status'], attrs['present'], attrs['speed'])) except KeyError as e: print("Invalid port", e)
def _print_transceiver_details(self, tid): # noqa """ Print details about transceiver """ info = self._info_resp[tid] ch_to_port = self._t_to_p[tid] if info.present is False: self._print_transceiver_ports(ch_to_port.values(), info) return print("Transceiver: {:>2}".format(info.port)) if info.vendor: self._print_vendor_details(info) if info.cable: self._print_cable_details(info) if info.settings: self._print_settings_details(info) if info.sensor or (info.thresholds and self._verbose) or info.channels: print("Monitoring Information:") if info.sensor: print(" {:<15} {:0.4} {:<4} {:0.4}".format( "Temperature", info.sensor.temp.value, "Vcc", info.sensor.vcc.value)) if self._verbose and info.thresholds: self._print_thresholds(info.thresholds) if self._verbose and info.sensor: if info.sensor.temp.flags and info.sensor.vcc.flags: self._print_sensor_flags(info.sensor) for channel in info.channels: port = ch_to_port.get(channel.channel, None) if port: attrs = utils.get_status_strs(self._status_resp[port], None) print(" Channel: {} Port: {:>2} Status: {:<8} Link: {:<4}". format( channel.channel, port, attrs["admin_status"], attrs["link_status"], )) else: # This is a channel for a port we weren't asked to display. # # (It would probably be nicer to clean up the CLI syntax so it # is a bit less ambiguous about what we should do here when we # were only asked to display info for some ports in a given # transceiver.) print(" Channel: {}".format(channel.channel)) self._print_port_channel(channel) # If we didn't print any channel info, print something useful if not info.channels: self._print_transceiver_ports(ch_to_port.values(), info)
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 _print_transceiver_ports(self, ports, info): ''' Print port info if the transceiver doesn't have any''' present = info.present if info else None for port in ports: attrs = utils.get_status_strs(self._status_resp[port], present) print("Port: {:>2} Status: {:<8} Link: {:<4} Transceiver: {}". format(port, attrs['admin_status'], attrs['link_status'], attrs['present']))
def _print_transceiver_details(self, tid): # noqa ''' Print details about transceiver ''' info = self._info_resp[tid] ch_to_port = self._t_to_p[tid] if info.present is False: self._print_transceiver_ports(ch_to_port.values(), info) return print("Transceiver: {:>2}".format(info.port)) if info.vendor: self._print_vendor_details(info) if info.cable: self._print_cable_details(info) if info.settings: self._print_settings_details(info) if info.sensor or (info.thresholds and self._verbose) or info.channels: print("Monitoring Information:") if info.sensor: print(" {:<15} {:0.4} {:<4} {:0.4}".format("Temperature", info.sensor.temp.value, "Vcc", info.sensor.vcc.value)) if self._verbose and info.thresholds: self._print_thresholds(info.thresholds) if self._verbose and info.sensor: if info.sensor.temp.flags and info.sensor.vcc.flags: self._print_sensor_flags(info.sensor) for channel in info.channels: port = ch_to_port.get(channel.channel, None) if port: attrs = utils.get_status_strs(self._status_resp[port], None) print(" Channel: {} Port: {:>2} Status: {:<8} Link: {:<4}" .format(channel.channel, port, attrs['admin_status'], attrs['link_status'])) else: # This is a channel for a port we weren't asked to display. # # (It would probably be nicer to clean up the CLI syntax so it # is a bit less ambiguous about what we should do here when we # were only asked to display info for some ports in a given # transceiver.) print(" Channel: {}".format(channel.channel)) self._print_port_channel(channel) # If we didn't print any channel info, print something useful if not info.channels: self._print_transceiver_ports(ch_to_port.values(), info)
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)))
def _print_port_detail(self): ''' print port details ''' # If a port does not have a mapping to a transceiver, we should # still print it, lest we skip ports in the detail display. transceiver_printed = [] for port, status in sorted(self._status_resp.items()): if status.transceiverIdx: tid = status.transceiverIdx.transceiverId if tid not in transceiver_printed: self._print_transceiver_details(tid) transceiver_printed.append(tid) else: attrs = utils.get_status_strs(self._status_resp[port]) print("Port: {:>2} Status: {:<8} Link: {:<4} Transceiver: {}" .format(port, attrs['admin_status'], attrs['link_status'], attrs['present']))
def _print_port_detail(self): ''' print port details ''' # If a port does not have a mapping to a transceiver, we should # still print it, lest we skip ports in the detail display. transceiver_printed = [] for port, status in sorted(self._status_resp.items()): if status.transceiverIdx: tid = status.transceiverIdx.transceiverId if tid not in transceiver_printed: self._print_transceiver_details(tid) transceiver_printed.append(tid) else: attrs = utils.get_status_strs(self._status_resp[port]) print( "Port: {:>2} Status: {:<8} Link: {:<4} Transceiver: {}". format(port, attrs['admin_status'], attrs['link_status'], attrs['present']))
def list_ports(self, ports): try: field_fmt = '{:>10} {:>12} {}{:>10} {:>12} {:>6}' print(field_fmt.format('Port', 'Admin State', '', 'Link State', 'Transceiver', 'Speed')) print('-' * 59) resp = self._client.getPortStatus(ports) port_info = self._client.getAllPortInfo() for port_data in sorted(port_info.values(), key=utils.port_sort_fn): port = port_data.portId if port not in resp: continue status = resp[port] attrs = utils.get_status_strs(status) if status.enabled: name = port_data.name if port_data.name else port print(field_fmt.format( name, attrs['admin_status'], attrs['color_align'], attrs['link_status'], attrs['present'], attrs['speed'])) except KeyError as e: print("Invalid port", e)
def _print_port_details_sfpdom(self, port, dom): status = self._status_resp[port] print("Port %d: %s" % (port, dom.name)) attrs = utils.get_status_strs(status) admin_status = attrs['admin_status'] link_status = attrs['link_status'] print(" Admin Status: %s" % admin_status) print(" Oper Status: %s" % link_status) print(" Module Present: %s" % dom.sfpPresent) if dom.sfpPresent and dom.vendor is not None: print(" Vendor Name: %s" % dom.vendor.name) print(" Part Number: %s" % dom.vendor.partNumber) print(" Revision: %s" % dom.vendor.rev) print(" Serial Number: %s" % dom.vendor.serialNumber) print(" Date Code: %s" % dom.vendor.dateCode) print(" Monitoring Information:") if not dom.domSupported: print(" DOM Not Supported") return print(" Values:") print(" {:<15} {:0.4}".format("Temperature", dom.value.temp)) print(" {:<15} {:0.4}".format("Vcc", dom.value.vcc)) print(" {:<15} {:0.4}".format("Tx Bias", dom.value.txBias)) print(" {:<15} {:0.4}".format("Tx Power(dBm)", self._mw_to_dbm(dom.value.txPwr))) print(" {:<15} {:0.4}".format("Rx Power(dBm)", self._mw_to_dbm(dom.value.rxPwr))) print(" {:<14} {:>15} {:>15} {:>15} {:>15}".format( 'Flags:', 'Alarm Low', 'Warning Low', 'Warning High', 'Alarm High')) print(" {:<14} {:>15} {:>15} {:>15} {:>15}".format( 'Temperature:', dom.flags.tempAlarmLow, dom.flags.tempWarnLow, dom.flags.tempWarnHigh, dom.flags.tempAlarmHigh)) print(" {:<14} {:>15} {:>15} {:>15} {:>15}".format( 'Vcc:', dom.flags.vccAlarmLow, dom.flags.vccWarnLow, dom.flags.vccWarnHigh, dom.flags.vccAlarmHigh)) print(" {:<14} {:>15} {:>15} {:>15} {:>15}".format( 'Tx Bias:', dom.flags.txBiasAlarmLow, dom.flags.txBiasWarnLow, dom.flags.txBiasWarnHigh, dom.flags.txBiasAlarmHigh)) print(" {:<14} {:>15} {:>15} {:>15} {:>15}".format( 'Tx Power(dBm):', self._mw_to_dbm(dom.flags.txPwrAlarmLow), self._mw_to_dbm(dom.flags.txPwrWarnLow), self._mw_to_dbm(dom.flags.txPwrWarnHigh), self._mw_to_dbm(dom.flags.txPwrAlarmHigh))) print(" {:<14} {:>15} {:>15} {:>15} {:>15}".format( 'Rx Power(dBm):', self._mw_to_dbm(dom.flags.rxPwrAlarmLow), self._mw_to_dbm(dom.flags.rxPwrWarnLow), self._mw_to_dbm(dom.flags.rxPwrWarnHigh), self._mw_to_dbm(dom.flags.rxPwrAlarmHigh))) thresh = dom.threshValue print(" {:<16} {:>15} {:>15} {:>15} {:>15}".format( 'Thresholds:', 'Alarm Low', 'Warning Low', 'Warning High', 'Alarm High')) print(" {:<14} {:>15.4} {:>15.4} {:>15.4} {:>15.4}".format( 'Temperature:', thresh.tempAlarmLow, thresh.tempWarnLow, thresh.tempWarnHigh, thresh.tempAlarmHigh)) print(" {:<14} {:>15.4} {:>15.4} {:>15.4} {:>15.4}".format( 'Vcc:', thresh.vccAlarmLow, thresh.vccWarnLow, thresh.vccWarnHigh, thresh.vccAlarmHigh)) print(" {:<14} {:>15.4} {:>15.4} {:>15.4} {:>15.4}".format( 'Tx Bias:', thresh.txBiasAlarmLow, thresh.txBiasWarnLow, thresh.txBiasWarnHigh, thresh.txBiasAlarmHigh)) print(" {:<14} {:>15.4} {:>15.4} {:>15.4} {:>15.4}".format( 'Tx Power(dBm):', self._mw_to_dbm(thresh.txPwrAlarmLow), self._mw_to_dbm(thresh.txPwrWarnLow), self._mw_to_dbm(thresh.txPwrWarnHigh), self._mw_to_dbm(thresh.txPwrAlarmHigh))) print(" {:<14} {:>15.4} {:>15.4} {:>15.4} {:>15.4}".format( 'Rx Power(dBm):', self._mw_to_dbm(thresh.rxPwrAlarmLow), self._mw_to_dbm(thresh.rxPwrWarnLow), self._mw_to_dbm(thresh.rxPwrWarnHigh), self._mw_to_dbm(thresh.rxPwrAlarmHigh)))