def do_alarm_list(cc, args={}): '''List all active alarms.''' includeUUID = args.uuid include_suppress = False if args.include_suppress: include_suppress = True include_mgmt_affecting = False if args.mgmt_affecting: include_mgmt_affecting = True faults = cc.ialarm.list(q=options.cli_to_array(args.query), include_suppress=include_suppress) for f in faults: cgts_utils.normalize_field_data(f, ['entity_type_id', 'entity_instance_id', 'reason_text', 'proposed_repair_action']) # omit action initially to keep output width sane # (can switch over to vertical formatting when available from CLIFF) def hightlightAlarmId(alarm): suppressed = hasattr(alarm,"suppression_status") and alarm.suppression_status=="suppressed" if suppressed: value = "S({})".format(alarm.alarm_id) else: value = alarm.alarm_id return value field_labels = ['Alarm ID', 'Reason Text', 'Entity ID', 'Severity', 'Time Stamp'] fields = ['alarm_id', 'reason_text', 'entity_instance_id', 'severity', 'timestamp'] # for best results, ensure width ratios add up to 1 (=100%) formatterSpec = { "alarm_id" : {"formatter" : hightlightAlarmId, "wrapperFormatter": .08}, "reason_text" : .54, "entity_instance_id" : .15, "severity" : .10, "timestamp" : .10, } if includeUUID: field_labels.insert(0, 'UUID') fields.insert(0, 'uuid') # for best results, ensure width ratios add up to 1 (=100%) formatterSpec['uuid'] = wrapping_formatters.UUID_MIN_LENGTH formatterSpec['reason_text'] -= .05 formatterSpec['entity_instance_id'] -= .02 if include_mgmt_affecting: field_labels.insert(4, 'Management Affecting') fields.insert(4, 'mgmt_affecting') # for best results, ensure width ratios add up to 1 (=100%) formatterSpec['mgmt_affecting'] = .08 formatterSpec['reason_text'] -= .05 formatterSpec['severity'] -= .03 formatters = wrapping_formatters.build_wrapping_formatters(faults, fields, field_labels, formatterSpec) cgts_utils.print_list(faults, fields, field_labels, formatters=formatters, sortby=fields.index('timestamp'), reversesort=True)
def do_host_port_list(cc, args): """List host ports.""" from cgtsclient.common import wrapping_formatters terminal_width = utils.get_terminal_size()[0] ihost = ihost_utils._find_ihost(cc, args.hostnameorid) ports = cc.port.list(ihost.uuid) field_labels = ['uuid', 'name', 'type', 'pci address', 'device', 'processor', 'accelerated', 'device type'] fields = ['uuid', 'name', 'type', 'pciaddr', 'dev_id', 'numa_node', 'dpdksupport', 'pdevice'] format_spec = wrapping_formatters.build_best_guess_formatters_using_average_widths(ports, fields, field_labels, no_wrap_fields=['pciaddr']) # best-guess formatter does not make a good guess for # proper width of pdevice until terminal is > 155 # We override that width here. pdevice_width = None if terminal_width <= 130: pdevice_width = .1 elif 131 >= terminal_width <= 150: pdevice_width = .13 elif 151 >= terminal_width <= 155: pdevice_width = .14 if pdevice_width and format_spec["pdevice"] > pdevice_width: format_spec["pdevice"] = pdevice_width formatters = wrapping_formatters.build_wrapping_formatters(ports, fields, field_labels, format_spec) utils.print_list(ports, fields, field_labels, formatters=formatters, sortby=1)
def do_event_suppress_list(cc, args={}): '''List Suppressed Event ID's ''' include_unsuppressed = args.include_unsuppressed includeUUID = args.uuid event_suppression_list = _event_suppression_list( cc, include_unsuppressed=include_unsuppressed) no_paging = args.nopaging displayCFG = _get_display_config(includeUUID) field_labels = displayCFG['field_labels'] fields = displayCFG['fields'] formatterSpec = displayCFG['formatterSpec'] formatters = wrapping_formatters.build_wrapping_formatters( event_suppression_list, fields, field_labels, formatterSpec) utils.print_long_list(event_suppression_list, fields, field_labels, formatters=formatters, sortby=1, reversesort=False, no_paging=no_paging)
def print_event_suppression_list(cc, no_paging, includeUUID): event_suppression_list = _event_suppression_list( cc, include_unsuppressed=False) displayCFG = _get_display_config(includeUUID) field_labels = displayCFG['field_labels'] fields = displayCFG['fields'] formatterSpec = displayCFG['formatterSpec'] formatters = wrapping_formatters.build_wrapping_formatters( event_suppression_list, fields, field_labels, formatterSpec) utils.print_long_list(event_suppression_list, fields, field_labels, formatters=formatters, sortby=1, reversesort=False, no_paging=no_paging)
def do_event_list(cc, args={}): '''List event logs.''' queryAsArray = options.cli_to_array(args.query) no_paging = args.nopaging alarms = False logs = False include_suppress = False includeUUID = args.uuid if args.alarms and not args.logs: alarms = True elif args.logs and not args.alarms: logs = True if args.include_suppress: include_suppress = True logs = cc.event_log.list(q=queryAsArray, limit=args.limit, alarms=alarms, logs=logs, include_suppress=include_suppress) for l in logs: utils.normalize_field_data(l, ['entity_instance_id', 'reason_text']) # omit action initially to keep output width sane # (can switch over to vertical formatting when available from CLIFF) def hightlightEventId(event): suppressed = hasattr( event, "suppression_status") and event.suppression_status == "suppressed" if suppressed: value = "S({})".format(event.event_log_id) else: value = event.event_log_id return value if includeUUID: field_labels = [ 'UUID', 'Time Stamp', 'State', 'Event Log ID', 'Reason Text', 'Entity Instance ID', 'Severity' ] fields = [ 'uuid', 'timestamp', 'state', 'event_log_id', 'reason_text', 'entity_instance_id', 'severity' ] formatterSpec = { "uuid": wrapping_formatters.UUID_MIN_LENGTH, "timestamp": .08, "state": .08, "event_log_id": { "formatter": hightlightEventId, "wrapperFormatter": .07 }, "reason_text": .42, "entity_instance_id": .13, "severity": .12 } else: field_labels = [ 'Time Stamp', 'State', 'Event Log ID', 'Reason Text', 'Entity Instance ID', 'Severity' ] fields = [ 'timestamp', 'state', 'event_log_id', 'reason_text', 'entity_instance_id', 'severity' ] # for best results, ensure width ratios add up to 1 (=100%) formatterSpec = { "timestamp": .08, "state": .08, "event_log_id": { "formatter": hightlightEventId, "wrapperFormatter": .07 }, "reason_text": .52, "entity_instance_id": .13, "severity": .12 } formatters = wrapping_formatters.build_wrapping_formatters( logs, fields, field_labels, formatterSpec) utils.print_long_list(logs, fields, field_labels, formatters=formatters, sortby=fields.index('timestamp'), reversesort=True, no_paging=no_paging)