def show_remotes(args, remotes): """ :param args: :param linstor.responses.RemoteListResponse remotes: :return: """ tbl = Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable) tbl.add_column("Name") tbl.add_column("Type") tbl.add_column("Info") rows = [] for s3 in remotes.s3_remotes: rows.append({ "name": s3.remote_name, "type": "S3", "info": "{r}.{e}/{b}".format(r=s3.region, e=s3.endpoint, b=s3.bucket) }) for lin_remote in remotes.linstor_remotes: rows.append({ "name": lin_remote.remote_name, "type": "Linstor", "info": lin_remote.url }) for remote in rows: tbl.add_row([remote["name"], remote["type"], remote["info"]]) tbl.show()
def show_volumes(cls, args, lstmsg): """ :param args: :param responses.ResourceResponse lstmsg: resource response data to display :return: None """ tbl = Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable) tbl.add_column("Node") tbl.add_column("Resource") tbl.add_column("StoragePool") tbl.add_column("VolNr", just_txt='>') tbl.add_column("MinorNr", just_txt='>') tbl.add_column("DeviceName") tbl.add_column("Allocated", just_txt='>') tbl.add_column("InUse", color=Output.color(Color.DARKGREEN, args.no_color)) tbl.add_column("State", color=Output.color(Color.DARKGREEN, args.no_color), just_txt='>') rsc_state_lkup = { x.node_name + x.name: x for x in lstmsg.resource_states } reports = [] for rsc in lstmsg.resources: if not args.all and apiconsts.FLAG_TIE_BREAKER in rsc.flags: continue # skip tie breaker resources if apiconsts.FLAG_RSC_INACTIVE in rsc.flags: continue # do not show non existing volumes for inactive resources rsc_state = rsc_state_lkup.get(rsc.node_name + rsc.name) rsc_usage = "" if rsc_state and rsc_state.in_use is not None: if rsc_state.in_use: rsc_usage = tbl.color_cell("InUse", Color.GREEN) else: rsc_usage = "Unused" for vlm in rsc.volumes: vlm_state = cls.get_volume_state( rsc_state.volume_states, vlm.number) if rsc_state else None state_txt, color = cls.volume_state_cell( vlm_state, rsc.flags, vlm.flags) has_errors = any([x.is_error() for x in vlm.reports]) conn_failed = (rsc.layer_data.drbd_resource and any(not v.connected for k, v in rsc.layer_data. drbd_resource.connections.items())) if conn_failed: color = Color.RED state = tbl.color_cell(state_txt, color) if color else state_txt if has_errors: state = tbl.color_cell("Error", Color.RED) for x in vlm.reports: reports.append(x) vlm_drbd_data = vlm.drbd_data tbl.add_row([ rsc.node_name, rsc.name, vlm.storage_pool_name, str(vlm.number), str(vlm_drbd_data.drbd_volume_definition.minor) if vlm_drbd_data else "", vlm.device_path, SizeCalc.approximate_size_string(vlm.allocated_size) if vlm.allocated_size else "", rsc_usage, state ]) tbl.show() for x in reports: Output.handle_ret(x, args.no_color, warn_as_error=args.warn_as_error)
def show_backups_info(cls, args, lstmsg): rsc_tbl = Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable) rsc_tbl.add_column("Resource") rsc_tbl.add_column("Snapshot") rsc_tbl.add_column("Full Backup") rsc_tbl.add_column("Latest Backup") rsc_tbl.add_column("Backup Count") rsc_tbl.add_column("Download Size") rsc_tbl.add_column("Allocated Size") # table will only have a single row row = [ lstmsg.rsc, lstmsg.snap, lstmsg.full, lstmsg.latest, lstmsg.count ] row += [ SizeCalc.approximate_size_string(lstmsg.dl_size), SizeCalc.approximate_size_string(lstmsg.alloc_size) ] rsc_tbl.add_row(row) rsc_tbl.show() stor_pool_tbl = Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable) stor_pool_tbl.add_column("Origin StorPool (Type)") if args.target_node: stor_pool_tbl.add_column("Target Pool") stor_pool_tbl.add_column("Remaining Free Space") stor_pool_tbl.add_column("Volume to Download") stor_pool_tbl.add_column("Type") stor_pool_tbl.add_column("Download Size") stor_pool_tbl.add_column("Allocated Size") stor_pool_tbl.add_column("Usable Size") for stor_pool in lstmsg.storpools: row = [stor_pool.name + " (" + stor_pool.provider_kind + ")"] if args.target_node: row += [ stor_pool.target_name, ] if stor_pool.remaining_space < 0: row += [ stor_pool_tbl.color_cell( "-" + SizeCalc.approximate_size_string( -stor_pool.remaining_space), Color.RED) ] else: row += [ SizeCalc.approximate_size_string( stor_pool.remaining_space) ] vlm_to_dl_cell = [] type_cell = [] dl_size_cell = [] alloc_size_cell = [] usable_size_cell = [] for volume in stor_pool.volumes: vlm_to_dl_cell += [volume.name if volume.name else "-"] type_cell += [volume.layer_type] dl_size_cell += [ SizeCalc.approximate_size_string(volume.dl_size) if volume.dl_size else "-" ] alloc_size_cell += [ SizeCalc.approximate_size_string(volume.alloc_size) if volume.alloc_size else "-" ] usable_size_cell += [ SizeCalc.approximate_size_string(volume.usable_size) if volume.usable_size else "-" ] row += [ "\n".join(vlm_to_dl_cell), "\n".join(type_cell), "\n".join(dl_size_cell), "\n".join(alloc_size_cell), "\n".join(usable_size_cell) ] stor_pool_tbl.add_row(row) stor_pool_tbl.show()