def do_provider_list(cs, args): """Lists all providers.""" search_opts = { 'name': args.name, 'description': args.description, } if args.sort and (args.sort_key or args.sort_dir): raise exceptions.CommandError( 'The --sort_key and --sort_dir arguments are deprecated and are ' 'not supported with --sort.') providers = cs.providers.list(search_opts=search_opts, marker=args.marker, limit=args.limit, sort_key=args.sort_key, sort_dir=args.sort_dir, sort=args.sort) key_list = ['Id', 'Name', 'Description'] if args.sort_key or args.sort_dir or args.sort: sortby_index = None else: sortby_index = 0 utils.print_list(providers, key_list, exclude_unavailable=True, sortby_index=sortby_index)
def do_plan_list(cs, args): """Lists all plans.""" 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, 'name': args.name, 'description': args.description, 'status': args.status, } if args.sort and (args.sort_key or args.sort_dir): raise exceptions.CommandError( 'The --sort_key and --sort_dir arguments are deprecated and are ' 'not supported with --sort.') plans = cs.plans.list(search_opts=search_opts, marker=args.marker, limit=args.limit, sort_key=args.sort_key, sort_dir=args.sort_dir, sort=args.sort) key_list = ['Id', 'Name', 'Description', 'Provider id', 'Status'] if args.sort_key or args.sort_dir or args.sort: sortby_index = None else: sortby_index = 0 utils.print_list(plans, key_list, exclude_unavailable=True, sortby_index=sortby_index)
def do_protectable_list(cs, args): """Lists all protectable types.""" protectables = cs.protectables.list() key_list = ['Protectable type'] utils.print_list(protectables, key_list, exclude_unavailable=True)
def do_checkpoint_list(cs, args): """Lists all checkpoints.""" if args.plan_id is not None: if not uuidutils.is_uuid_like(args.plan_id): raise exceptions.CommandError('The plan_id must be a uuid') if args.start_date: try: datetime.strptime(args.start_date, "%Y-%m-%d") except (ValueError, SyntaxError): raise exceptions.CommandError( "The format of start_date should be %Y-%m-%d") if args.end_date: try: datetime.strptime(args.end_date, "%Y-%m-%d") except (ValueError, SyntaxError): raise exceptions.CommandError( "The format of end_date should be %Y-%m-%d") search_opts = { 'plan_id': args.plan_id, 'start_date': args.start_date, 'end_date': args.end_date, 'project_id': args.project_id, } if args.sort and (args.sort_key or args.sort_dir): raise exceptions.CommandError( 'The --sort_key and --sort_dir arguments are deprecated and are ' 'not supported with --sort.') checkpoints = cs.checkpoints.list(provider_id=args.provider_id, search_opts=search_opts, marker=args.marker, limit=args.limit, sort_key=args.sort_key, sort_dir=args.sort_dir, sort=args.sort) key_list = [ 'Id', 'Project id', 'Status', 'Protection plan', 'Metadata', 'Created at' ] if args.sort_key or args.sort_dir or args.sort: sortby_index = None else: sortby_index = 0 formatters = { "Protection plan": lambda obj: json.dumps(obj.protection_plan, indent=2, sort_keys=True) } utils.print_list(checkpoints, key_list, exclude_unavailable=True, sortby_index=sortby_index, formatters=formatters)
def do_trigger_list(cs, args): """Lists all triggers.""" 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, 'name': args.name, 'type': args.type, 'properties': args.properties, } if args.sort and (args.sort_key or args.sort_dir): raise exceptions.CommandError( 'The --sort_key and --sort_dir arguments are deprecated and are ' 'not supported with --sort.') triggers = cs.triggers.list(search_opts=search_opts, marker=args.marker, limit=args.limit, sort_key=args.sort_key, sort_dir=args.sort_dir, sort=args.sort) key_list = ['Id', 'Name', 'Type', 'Properties'] if args.sort_key or args.sort_dir or args.sort: sortby_index = None else: sortby_index = 0 formatters = { "Properties": lambda obj: json.dumps(obj.properties, indent=2, sort_keys=True) } utils.print_list(triggers, key_list, exclude_unavailable=True, sortby_index=sortby_index, formatters=formatters)
def do_restore_list(cs, args): """Lists all restores.""" 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, 'status': args.status, } if args.sort and (args.sort_key or args.sort_dir): raise exceptions.CommandError( 'The --sort_key and --sort_dir arguments are deprecated and are ' 'not supported with --sort.') restores = cs.restores.list(search_opts=search_opts, marker=args.marker, limit=args.limit, sort_key=args.sort_key, sort_dir=args.sort_dir, sort=args.sort) key_list = [ 'Id', 'Project id', 'Provider id', 'Checkpoint id', 'Restore target', 'Parameters', 'Status' ] if args.sort_key or args.sort_dir or args.sort: sortby_index = None else: sortby_index = 0 formatters = { "Parameters": lambda obj: json.dumps(obj.parameters, indent=2, sort_keys=True) } utils.print_list(restores, key_list, exclude_unavailable=True, sortby_index=sortby_index, formatters=formatters)
def do_protectable_list_instances(cs, args): """Lists all protectable instances.""" search_opts = { 'type': args.type, 'parameters': (_extract_instances_parameters(args) if args.parameters else None), } if args.sort and (args.sort_key or args.sort_dir): raise exceptions.CommandError( 'The --sort_key and --sort_dir arguments are deprecated and are ' 'not supported with --sort.') instances = cs.protectables.list_instances(args.protectable_type, search_opts=search_opts, marker=args.marker, limit=args.limit, sort_key=args.sort_key, sort_dir=args.sort_dir, sort=args.sort) key_list = ['Id', 'Type', 'Name', 'Dependent resources', 'Extra info'] if args.sort_key or args.sort_dir or args.sort: sortby_index = None else: sortby_index = 0 formatters = { "Dependent resources": lambda obj: json.dumps( obj.dependent_resources, indent=2, sort_keys=True) } utils.print_list(instances, key_list, exclude_unavailable=True, sortby_index=sortby_index, formatters=formatters)
def do_scheduledoperation_list(cs, args): """Lists all scheduledoperations.""" 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, 'name': args.name, 'operation_type': args.operation_type, 'trigger_id': args.trigger_id, 'operation_definition': args.operation_definition, } if args.sort and (args.sort_key or args.sort_dir): raise exceptions.CommandError( 'The --sort_key and --sort_dir arguments are deprecated and are ' 'not supported with --sort.') scheduledoperations = cs.scheduled_operations.list(search_opts=search_opts, marker=args.marker, limit=args.limit, sort_key=args.sort_key, sort_dir=args.sort_dir, sort=args.sort) key_list = [ 'Id', 'Name', 'OperationType', 'TriggerId', 'OperationDefinition' ] if args.sort_key or args.sort_dir or args.sort: sortby_index = None else: sortby_index = 0 utils.print_list(scheduledoperations, key_list, exclude_unavailable=True, sortby_index=sortby_index)