def do_message_list(cs, args): """Lists all messages.""" search_opts = { 'resource_uuid': args.resource_uuid, 'event_id': args.event_id, 'request_id': args.request_id, } if args.resource_type: search_opts['resource_type'] = args.resource_type.upper() if args.level: search_opts['message_level'] = args.level.upper() marker = args.marker if hasattr(args, 'marker') else None limit = args.limit if hasattr(args, 'limit') else None sort = args.sort if hasattr(args, 'sort') else None messages = cs.messages.list(search_opts=search_opts, marker=marker, limit=limit, sort=sort) columns = ['ID', 'Resource Type', 'Resource UUID', 'Event ID', 'User Message'] if sort: sortby_index = None else: sortby_index = 0 utils.print_list(messages, columns, sortby_index=sortby_index)
def do_list_extensions(client, _args): """ List all the os-api extensions that are available. """ extensions = client.list_extensions.show_all() fields = ["Name", "Summary", "Alias", "Updated"] utils.print_list(extensions, fields)
def _print_volume_encryption_type_list(encryption_types): """ Display a tabularized list of volume encryption types. :param encryption_types: a list of :class: VolumeEncryptionType instances """ utils.print_list(encryption_types, ["Volume Type ID", "Provider", "Cipher", "Key Size", "Control Location"])
def do_list(cs, args): """Lists all volumes.""" all_tenants = 1 if args.tenant else \ int(os.environ.get("ALL_TENANTS", args.all_tenants)) search_opts = { 'all_tenants': all_tenants, 'project_id': args.tenant, 'display_name': args.display_name, 'status': args.status, 'metadata': _extract_metadata(args) if args.metadata else None, } volumes = cs.volumes.list(search_opts=search_opts, limit=args.limit) _translate_volume_keys(volumes) # Create a list of servers to which the volume is attached for vol in volumes: servers = [s.get('server_id') for s in vol.attachments] setattr(vol, 'attached_to', ','.join(map(str, servers))) if all_tenants: key_list = ['ID', 'Tenant ID', 'Status', 'Display Name', 'Size', 'Volume Type', 'Bootable', 'Attached to'] else: key_list = ['ID', 'Status', 'Display Name', 'Size', 'Volume Type', 'Bootable', 'Attached to'] utils.print_list(volumes, key_list)
def do_transfer_list(cs, args): """Lists all transfers.""" all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) search_opts = {"all_tenants": all_tenants} transfers = cs.transfers.list(search_opts=search_opts) columns = ["ID", "Volume ID", "Name"] utils.print_list(transfers, columns)
def do_transfer_list(cs, args): """Lists all transfers.""" all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) search_opts = { 'all_tenants': all_tenants, } transfers = cs.transfers.list(search_opts=search_opts) columns = ['ID', 'Volume ID', 'Name'] utils.print_list(transfers, columns)
def do_service_list(cs, args): """Lists all services. Filter by host and service binary.""" result = cs.services.list(host=args.host, binary=args.binary) columns = ["Binary", "Host", "Zone", "Status", "State", "Updated_at"] # NOTE(jay-lau-513): we check if the response has disabled_reason # so as not to add the column when the extended ext is not enabled. if result and hasattr(result[0], 'disabled_reason'): columns.append("Disabled Reason") utils.print_list(result, columns)
def _print_volume_encryption_type_list(encryption_types): """ Lists volume encryption types. :param encryption_types: a list of :class: VolumeEncryptionType instances """ utils.print_list(encryption_types, ['Volume Type ID', 'Provider', 'Cipher', 'Key Size', 'Control Location'])
def do_service_disable(cs, args): """Disables the service.""" columns = ["Host", "Binary", "Status"] if args.reason: columns.append("Disabled Reason") result = cs.services.disable_log_reason(args.host, args.binary, args.reason) else: result = cs.services.disable(args.host, args.binary) utils.print_list([result], columns)
def do_snapshot_list(cs, args): """List all the snapshots.""" all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) search_opts = {'all_tenants': all_tenants} snapshots = cs.volume_snapshots.list(search_opts=search_opts) _translate_volume_snapshot_keys(snapshots) utils.print_list(snapshots, ['ID', 'Volume ID', 'Status', 'Display Name', 'Size'])
def do_service_disable(cs, args): """Disables the service.""" columns = ["Host", "Binary", "Status"] if args.reason: columns.append('Disabled Reason') result = cs.services.disable_log_reason(args.host, args.binary, args.reason) else: result = cs.services.disable(args.host, args.binary) utils.print_list([result], columns)
def do_manageable_list(cs, args): """Lists all manageable volumes.""" detailed = strutils.bool_from_string(args.detailed) volumes = cs.volumes.list_manageable(host=args.host, detailed=detailed, marker=args.marker, limit=args.limit, offset=args.offset, sort=args.sort) columns = ['reference', 'size', 'safe_to_manage'] if detailed: columns.extend(['reason_not_safe', 'cinder_id', 'extra_info']) utils.print_list(volumes, columns, sortby_index=None)
def print_volumes(self): columns = ['ID', 'Status', 'Display Name', 'Size', 'Volume Type', 'Bootable', 'Attached to'] volumes = self.cinder.volume_list() for v in volumes: servers = [s.get('server_id') for s in v.attachments] setattr(v, 'attached_to', ','.join(map(str, servers))) print('\n\nVOLUMES') cinder_utils.print_list(volumes, columns, {})
def do_list(cs, args): """List all the volumes.""" volumes = cs.volumes.list() _translate_volume_keys(volumes) # Create a list of servers to which the volume is attached for vol in volumes: servers = [s.get('server_id') for s in vol.attachments] setattr(vol, 'attached_to', ','.join(map(str, servers))) utils.print_list(volumes, ['ID', 'Status', 'Display Name', 'Size', 'Volume Type', 'Attached to'])
def do_list(cs, args): """List all the volumes.""" all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) search_opts = {"all_tenants": all_tenants, "display_name": args.display_name, "status": args.status} volumes = cs.volumes.list(search_opts=search_opts) _translate_volume_keys(volumes) # Create a list of servers to which the volume is attached for vol in volumes: servers = [s.get("server_id") for s in vol.attachments] setattr(vol, "attached_to", ",".join(map(str, servers))) utils.print_list(volumes, ["ID", "Status", "Display Name", "Size", "Volume Type", "Bootable", "Attached to"])
def do_list(cs, args): """List all the volumes.""" all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) search_opts = {'all_tenants': all_tenants} volumes = cs.volumes.list(search_opts=search_opts) _translate_volume_keys(volumes) # Create a list of servers to which the volume is attached for vol in volumes: servers = [s.get('server_id') for s in vol.attachments] setattr(vol, 'attached_to', ','.join(map(str, servers))) utils.print_list(volumes, ['ID', 'Status', 'Display Name', 'Size', 'Volume Type', 'Attached to'])
def do_snapshot_manageable_list(cs, args): """Lists all manageable snapshots.""" detailed = strutils.bool_from_string(args.detailed) snapshots = cs.volume_snapshots.list_manageable(host=args.host, detailed=detailed, marker=args.marker, limit=args.limit, offset=args.offset, sort=args.sort) columns = ['reference', 'size', 'safe_to_manage', 'source_reference'] if detailed: columns.extend(['reason_not_safe', 'cinder_id', 'extra_info']) utils.print_list(snapshots, columns, sortby_index=None)
def test_print_list_with_list(self): Row = collections.namedtuple('Row', ['a', 'b']) to_print = [Row(a=1, b=2), Row(a=3, b=4)] with CaptureStdout() as cso: utils.print_list(to_print, ['a', 'b']) self.assertEqual(cso.read(), """\ +---+---+ | a | b | +---+---+ | 1 | 2 | | 3 | 4 | +---+---+ """)
def do_cluster_list(cs, args): """Lists clustered services with optional filtering.""" clusters = cs.clusters.list(name=args.name, binary=args.binary, is_up=args.is_up, disabled=args.disabled, num_hosts=args.num_hosts, num_down_hosts=args.num_down_hosts, detailed=args.detailed) columns = ['Name', 'Binary', 'State', 'Status'] if args.detailed: columns.extend(('Num Hosts', 'Num Down Hosts', 'Last Heartbeat', 'Disabled Reason', 'Created At', 'Updated at')) utils.print_list(clusters, columns)
def test_print_list_with_list(self): Row = collections.namedtuple('Row', ['a', 'b']) to_print = [Row(a=1, b=2), Row(a=3, b=4)] with CaptureStdout() as cso: utils.print_list(to_print, ['a', 'b']) self.assertEqual("""\ +---+---+ | a | b | +---+---+ | 1 | 2 | | 3 | 4 | +---+---+ """, cso.read())
def do_snapshot_list(cs, args): """List all the snapshots.""" all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) search_opts = { "all_tenants": all_tenants, "display_name": args.display_name, "status": args.status, "volume_id": args.volume_id, } snapshots = cs.volume_snapshots.list(search_opts=search_opts) _translate_volume_snapshot_keys(snapshots) utils.print_list(snapshots, ["ID", "Volume ID", "Status", "Display Name", "Size"])
def test_print_list_with_list_no_sort(self): Row = collections.namedtuple('Row', ['a', 'b']) to_print = [Row(a=3, b=4), Row(a=1, b=2)] with CaptureStdout() as cso: utils.print_list(to_print, ['a', 'b'], sortby_index=None) # Output should be in the order given self.assertEqual("""\ +---+---+ | a | b | +---+---+ | 3 | 4 | | 1 | 2 | +---+---+ """, cso.read())
def do_snapshot_list(cs, args): """List all the snapshots.""" all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) search_opts = { 'all_tenants': all_tenants, 'display_name': args.display_name, 'status': args.status, 'volume_id': args.volume_id, } snapshots = cs.volume_snapshots.list(search_opts=search_opts) _translate_volume_snapshot_keys(snapshots) utils.print_list(snapshots, ['ID', 'Volume ID', 'Status', 'Display Name', 'Size'])
def test_print_list_with_list_sortby(self): Row = collections.namedtuple('Row', ['a', 'b']) to_print = [Row(a=4, b=3), Row(a=2, b=1)] with CaptureStdout() as cso: utils.print_list(to_print, ['a', 'b'], sortby_index=1) # Output should be sorted by the second key (b) self.assertEqual("""\ +---+---+ | a | b | +---+---+ | 2 | 1 | | 4 | 3 | +---+---+ """, cso.read())
def do_service_list(cs, args): """Lists all services. Filter by host and service binary.""" replication = strutils.bool_from_string(args.withreplication, strict=True) result = cs.services.list(host=args.host, binary=args.binary) columns = ["Binary", "Host", "Zone", "Status", "State", "Updated_at"] if cs.api_version.matches('3.7'): columns.append('Cluster') if replication: columns.extend(["Replication Status", "Active Backend ID", "Frozen"]) # NOTE(jay-lau-513): we check if the response has disabled_reason # so as not to add the column when the extended ext is not enabled. if result and hasattr(result[0], 'disabled_reason'): columns.append("Disabled Reason") utils.print_list(result, columns)
def test_print_list_with_return(self): Row = collections.namedtuple('Row', ['a', 'b']) to_print = [Row(a=3, b='a\r'), Row(a=1, b='c\rd')] with CaptureStdout() as cso: utils.print_list(to_print, ['a', 'b']) # Output should be sorted by the first key (a) self.assertEqual("""\ +---+-----+ | a | b | +---+-----+ | 1 | c d | | 3 | a | +---+-----+ """, cso.read())
def _quota_usage_show(quotas): quota_list = [] for resource in quotas._info.keys(): good_name = False for name in _quota_resources: if resource.startswith(name): good_name = True if not good_name: continue quota_info = getattr(quotas, resource, None) quota_info['Type'] = resource quota_info = dict((k.capitalize(), v) for k, v in quota_info.items()) quota_list.append(quota_info) utils.print_list(quota_list, _quota_infos)
def test_print_list_with_None_data(self): Row = collections.namedtuple('Row', ['a', 'b']) to_print = [Row(a=3, b=None), Row(a=1, b=2)] with CaptureStdout() as cso: utils.print_list(to_print, ['a', 'b']) # Output should be sorted by the first key (a) self.assertEqual("""\ +---+---+ | a | b | +---+---+ | 1 | 2 | | 3 | - | +---+---+ """, cso.read())
def do_group_snapshot_list(cs, args): """Lists all group snapshots.""" all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) search_opts = { 'all_tenants': all_tenants, 'status': args.status, 'group_id': args.group_id, } group_snapshots = cs.group_snapshots.list(search_opts=search_opts) columns = ['ID', 'Status', 'Name'] utils.print_list(group_snapshots, columns)
def do_availability_zone_list(cs, _args): """Lists all availability zones.""" try: availability_zones = cs.availability_zones.list() except exceptions.Forbidden as e: # policy doesn't allow probably try: availability_zones = cs.availability_zones.list(detailed=False) except Exception: raise e result = [] for zone in availability_zones: result += _treeizeAvailabilityZone(zone) _translate_availability_zone_keys(result) utils.print_list(result, ['Name', 'Status'])
def do_availability_zone_list(cs, _args): """List all the availability zones.""" try: availability_zones = cs.availability_zones.list() except exceptions.Forbidden as e: # policy doesn't allow probably try: availability_zones = cs.availability_zones.list(detailed=False) except Exception: raise e result = [] for zone in availability_zones: result += _treeizeAvailabilityZone(zone) _translate_availability_zone_keys(result) utils.print_list(result, ['Name', 'Status'])
def test_print_list_with_generator(self): Row = collections.namedtuple('Row', ['a', 'b']) def gen_rows(): for row in [Row(a=1, b=2), Row(a=3, b=4)]: yield row with CaptureStdout() as cso: utils.print_list(gen_rows(), ['a', 'b']) self.assertEqual("""\ +---+---+ | a | b | +---+---+ | 1 | 2 | | 3 | 4 | +---+---+ """, cso.read())
def test_print_list_with_list(self): Row = collections.namedtuple("Row", ["a", "b"]) to_print = [Row(a=3, b=4), Row(a=1, b=2)] with CaptureStdout() as cso: utils.print_list(to_print, ["a", "b"]) # Output should be sorted by the first key (a) self.assertEqual( """\ +---+---+ | a | b | +---+---+ | 1 | 2 | | 3 | 4 | +---+---+ """, cso.read(), )
def do_list(cs, args): """List all the volumes.""" all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) search_opts = { 'all_tenants': all_tenants, 'display_name': args.display_name, 'status': args.status, 'metadata': _extract_metadata(args) if args.metadata else None, } volumes = cs.volumes.list(search_opts=search_opts) _translate_volume_keys(volumes) # Create a list of servers to which the volume is attached for vol in volumes: servers = [s.get('server_id') for s in vol.attachments] setattr(vol, 'attached_to', ','.join(map(str, servers))) utils.print_list(volumes, ['ID', 'Status', 'Display Name', 'Size', 'Volume Type', 'Bootable', 'Attached to'])
def do_snapshot_list(cs, args): """List all the snapshots.""" all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) if args.display_name is not None: args.name = args.display_name search_opts = { 'all_tenants': all_tenants, 'display_name': args.name, 'status': args.status, 'volume_id': args.volume_id, } snapshots = cs.volume_snapshots.list(search_opts=search_opts) _translate_volume_snapshot_keys(snapshots) utils.print_list(snapshots, ['ID', 'Volume ID', 'Status', 'Name', 'Size'])
def do_list(cs, args): """List all the volumes.""" # NOTE(thingee): Backwards-compatibility with v1 args if args.display_name is not None: args.name = args.display_name all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) search_opts = { "all_tenants": all_tenants, "name": args.name, "status": args.status, "metadata": _extract_metadata(args) if args.metadata else None, } volumes = cs.volumes.list(search_opts=search_opts) _translate_volume_keys(volumes) # Create a list of servers to which the volume is attached for vol in volumes: servers = [s.get("server_id") for s in vol.attachments] setattr(vol, "attached_to", ",".join(map(str, servers))) utils.print_list(volumes, ["ID", "Status", "Name", "Size", "Volume Type", "Bootable", "Attached to"])
def do_list(cs, args): """List all the volumes.""" # NOTE(thingee): Backwards-compatibility with v1 args if args.display_name is not None: args.name = args.display_name all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) search_opts = { 'all_tenants': all_tenants, 'name': args.name, 'status': args.status, } volumes = cs.volumes.list(search_opts=search_opts) _translate_volume_keys(volumes) # Create a list of servers to which the volume is attached for vol in volumes: servers = [s.get('server_id') for s in vol.attachments] setattr(vol, 'attached_to', ','.join(map(str, servers))) utils.print_list(volumes, ['ID', 'Status', 'Name', 'Size', 'Volume Type', 'Bootable', 'Attached to'])
def do_list(cs, args): """List all the volumes.""" # NOTE(thingee): Backwards-compatibility with v1 args if args.display_name is not None: args.name = args.display_name all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) search_opts = { 'all_tenants': all_tenants, 'name': args.name, 'status': args.status, } volumes = cs.volumes.list(search_opts=search_opts) _translate_volume_keys(volumes) # Create a list of servers to which the volume is attached for vol in volumes: servers = [s.get('server_id') for s in vol.attachments] setattr(vol, 'attached_to', ','.join(map(str, servers))) utils.print_list(volumes, [ 'ID', 'Status', 'Name', 'Size', 'Volume Type', 'Bootable', 'Attached to' ])
def print_group_type_list(gtypes): utils.print_list(gtypes, ['ID', 'Name', 'Description'])
def do_backup_list(cs, args): """List all the backups.""" backups = cs.backups.list() columns = ['ID', 'Volume ID', 'Status', 'Name', 'Size', 'Object Count', 'Container'] utils.print_list(backups, columns)
def do_transfer_list(cs, args): """List all the transfers.""" transfers = cs.transfers.list() columns = ['ID', 'Volume ID', 'Name'] utils.print_list(transfers, columns)
def do_service_enable(cs, args): """Enable the service.""" result = cs.services.enable(args.host, args.binary) columns = ["Host", "Binary", "Status"] utils.print_list([result], columns)
def print_associations_list(associations): utils.print_list(associations, ['Association_Type', 'Name', 'ID'])
def _print_qos_specs_list(q_specs): utils.print_list(q_specs, ['ID', 'Name', 'Consumer', 'specs'])
def do_service_list(cs, args): """List all the services. Filter by host & service binary.""" result = cs.services.list(host=args.host, binary=args.binary) columns = ["Binary", "Host", "Zone", "Status", "State", "Updated_at"] utils.print_list(result, columns)
def do_rate_limits(cs, args): """Print a list of rate limits for a user""" limits = cs.limits.get().rate columns = ['Verb', 'URI', 'Value', 'Remain', 'Unit', 'Next_Available'] utils.print_list(limits, columns)
def print_volume_type_list(vtypes): utils.print_list(vtypes, ['ID', 'Name', 'Description', 'Is_Public'])
def _print_type_and_extra_specs_list(vtypes): formatters = {'extra_specs': _print_type_extra_specs} utils.print_list(vtypes, ['ID', 'Name', 'extra_specs'], formatters)
def do_absolute_limits(cs, args): """Print a list of absolute limits for a user""" limits = cs.limits.get().absolute columns = ['Name', 'Value'] utils.print_list(limits, columns)
def print_resource_filter_list(filters): formatter = {'Filters': lambda resource: ', '.join(resource.filters)} utils.print_list(filters, ['Resource', 'Filters'], formatters=formatter)
def _print_volume_type_list(vtypes): utils.print_list(vtypes, ['ID', 'Name'])
def print_qos_specs_and_associations_list(q_specs): utils.print_list(q_specs, ['ID', 'Name', 'Consumer', 'specs'])