@utils.arg('--reservation-id', dest='reservation_id', metavar='<reservation-id>', default=None, help=_('Only return servers that match reservation-id.'))
@utils.arg('--ip', dest='ip', metavar='<ip-regexp>', default=None, help=_('Search with regular expression match by IP address.'))
@utils.arg('--ip6', dest='ip6', metavar='<ip6-regexp>', default=None, help=_('Search with regular expression match by IPv6 address.'))
@utils.arg('--name', dest='name', metavar='<name-regexp>', default=None, help=_('Search with regular expression match by name.'))
@utils.arg('--instance-name', dest='instance_name', metavar='<name-regexp>', default=None, help=_('Search with regular expression match by server name.'))
@utils.arg('--status', dest='status', metavar='<status>', default=None, help=_('Search by server status.'))
@utils.arg('--flavor', dest='flavor', metavar='<flavor>', default=None, help=_('Search by flavor name or ID.'))
@utils.arg('--image', dest='image', metavar='<image>', default=None, help=_('Search by image name or ID.'))
@utils.arg('--host', dest='host', metavar='<hostname>', default=None, help=_('Search servers by hostname to which they are assigned (Admin only).'))
@utils.arg('--all-tenants', dest='all_tenants', metavar='<0|1>', nargs='?', type=int, const=1, default=int(strutils.bool_from_string(os.environ.get('ALL_TENANTS', 'false'), True)), help=_('Display information from all tenants (Admin only).'))
@utils.arg('--tenant', dest='tenant', metavar='<tenant>', nargs='?', help=_('Display information from single tenant (Admin only).'))
@utils.arg('--user', dest='user', metavar='<user>', nargs='?', help=_('Display information from single user (Admin only).'))
@utils.arg('--deleted', dest='deleted', action='store_true', default=False, help=_('Only display deleted servers (Admin only).'))
@utils.arg('--fields', default=None, metavar='<fields>', help=_('Comma-separated list of fields to display. Use the show command to see which fields are available.'))
@utils.arg('--minimal', dest='minimal', action='store_true', default=False, help=_('Get only UUID and name.'))
@utils.arg('--sort', dest='sort', metavar='<key>[:<direction>]', help=_('Comma-separated list of sort keys and directions in the form of <key>[:<asc|desc>]. The direction defaults to descending if not specified.'))
@utils.arg('--marker', dest='marker', metavar='<marker>', default=None, help=_('The last server UUID of the previous page; displays list of servers after "marker".'))
@utils.arg('--limit', dest='limit', metavar='<limit>', type=int, default=None, help=_("Maximum number of servers to display. If limit == -1, all servers will be displayed. If limit is bigger than 'CONF.api.max_limit' option of Nova API, limit 'CONF.api.max_limit' will be used instead."))
@utils.arg('--changes-since', dest='changes_since', metavar='<changes_since>', default=None, help=_('List only servers changed after a certain point of time.The provided time should be an ISO 8061 formatted time.ex 2016-03-04T06:27:59Z .'))
@utils.arg('--tags', dest='tags', metavar='<tags>', default=None, help=_("The given tags must all be present for a server to be included in the list result. Boolean expression in this case is 't1 AND t2'. Tags must be separated by commas: --tags <tag1,tag2>"), start_version='2.26')
@utils.arg('--tags-any', dest='tags-any', metavar='<tags-any>', default=None, help=_("If one of the given tags is present the server will be included in the list result. Boolean expression in this case is 't1 OR t2'. Tags must be separated by commas: --tags-any <tag1,tag2>"), start_version='2.26')
@utils.arg('--not-tags', dest='not-tags', metavar='<not-tags>', default=None, help=_("Only the servers that do not have any of the given tags will be included in the list results. Boolean expression in this case is 'NOT(t1 AND t2)'. Tags must be separated by commas: --not-tags <tag1,tag2>"), start_version='2.26')
@utils.arg('--not-tags-any', dest='not-tags-any', metavar='<not-tags-any>', default=None, help=_("Only the servers that do not have at least one of the given tags will be included in the list result. Boolean expression in this case is 'NOT(t1 OR t2)'. Tags must be separated by commas: --not-tags-any <tag1,tag2>"), start_version='2.26')
def do_list(cs, args):
 imageid = None
 flavorid = None
 if args.image:
  imageid = _find_image(cs, args.image).id
 if args.flavor:
  flavorid = _find_flavor(cs, args.flavor).id
 if (args.tenant or args.user):
  args.all_tenants = 1
 search_opts = {'all_tenants': args.all_tenants, 'reservation_id': args.reservation_id, 'ip': args.ip, 'ip6': args.ip6, 'name': args.name, 'image': imageid, 'flavor': flavorid, 'status': args.status, 'tenant_id': args.tenant, 'user_id': args.user, 'host': args.host, 'deleted': args.deleted, 'instance_name': args.instance_name, 'changes-since': args.changes_since}
 for arg in ('tags', 'tags-any', 'not-tags', 'not-tags-any'):
  if (arg in args):
   search_opts[arg] = getattr(args, arg)
 filters = {'flavor': (lambda f: f['id']), 'security_groups': utils.format_security_groups}
 id_col = 'ID'
 detailed = (not args.minimal)
 sort_keys = []
 sort_dirs = []
 if args.sort:
  for sort in args.sort.split(','):
   (sort_key, _sep, sort_dir) = sort.partition(':')
   if (not sort_dir):
    sort_dir = 'desc'
   elif (sort_dir not in ('asc', 'desc')):
    raise exceptions.CommandError((_('Unknown sort direction: %s') % sort_dir))
   sort_keys.append(sort_key)
   sort_dirs.append(sort_dir)
 if search_opts['changes-since']:
  try:
   timeutils.parse_isotime(search_opts['changes-since'])
  except ValueError:
   raise exceptions.CommandError((_('Invalid changes-since value: %s') % search_opts['changes-since']))
 servers = cs.servers.list(detailed=detailed, search_opts=search_opts, sort_keys=sort_keys, sort_dirs=sort_dirs, marker=args.marker, limit=args.limit)
 convert = [('OS-EXT-SRV-ATTR:host', 'host'), ('OS-EXT-STS:task_state', 'task_state'), ('OS-EXT-SRV-ATTR:instance_name', 'instance_name'), ('OS-EXT-STS:power_state', 'power_state'), ('hostId', 'host_id')]
 _translate_keys(servers, convert)
 _translate_extended_states(servers)
 formatters = {}
 (cols, fmts) = _get_list_table_columns_and_formatters(args.fields, servers, exclude_fields=('id',), filters=filters)
 if args.minimal:
  columns = [id_col, 'Name']
 elif cols:
  columns = ([id_col] + cols)
  formatters.update(fmts)
 else:
  columns = [id_col, 'Name', 'Status', 'Task State', 'Power State', 'Networks']
  if search_opts['all_tenants']:
   columns.insert(2, 'Tenant ID')
  if search_opts['changes-since']:
   columns.append('Updated')
 formatters['Networks'] = utils.format_servers_list_networks
 sortby_index = 1
 if args.sort:
  sortby_index = None
 utils.print_list(servers, columns, formatters, sortby_index=sortby_index)

@ utils . arg ( '--reservation-id' , dest = 'reservation_id' , metavar = '<reservation-id>' , default = None , help = _ ( 'Only return servers that match reservation-id.' ) ) @ utils . arg ( '--ip' , dest = 'ip' , metavar = '<ip-regexp>' , default = None , help = _ ( 'Search with regular expression match by IP address.' ) ) @ utils . arg ( '--ip6' , dest = 'ip6' , metavar = '<ip6-regexp>' , default = None , help = _ ( 'Search with regular expression match by IPv6 address.' ) ) @ utils . arg ( '--name' , dest = 'name' , metavar = '<name-regexp>' , default = None , help = _ ( 'Search with regular expression match by name.' ) ) @ utils . arg ( '--instance-name' , dest = 'instance_name' , metavar = '<name-regexp>' , default = None , help = _ ( 'Search with regular expression match by server name.' ) ) @ utils . arg ( '--status' , dest = 'status' , metavar = '<status>' , default = None , help = _ ( 'Search by server status.' ) ) @ utils . arg ( '--flavor' , dest = 'flavor' , metavar = '<flavor>' , default = None , help = _ ( 'Search by flavor name or ID.' ) ) @ utils . arg ( '--image' , dest = 'image' , metavar = '<image>' , default = None , help = _ ( 'Search by image name or ID.' ) ) @ utils . arg ( '--host' , dest = 'host' , metavar = '<hostname>' , default = None , help = _ ( 'Search servers by hostname to which they are assigned (Admin only).' ) ) @ utils . arg ( '--all-tenants' , dest = 'all_tenants' , metavar = '<0|1>' , nargs = '?' , type = int , const = 1 , default = int ( strutils . bool_from_string ( os . environ . get ( 'ALL_TENANTS' , 'false' ) , True ) ) , help = _ ( 'Display information from all tenants (Admin only).' ) ) @ utils . arg ( '--tenant' , dest = 'tenant' , metavar = '<tenant>' , nargs = '?' , help = _ ( 'Display information from single tenant (Admin only).' ) ) @ utils . arg ( '--user' , dest = 'user' , metavar = '<user>' , nargs = '?' , help = _ ( 'Display information from single user (Admin only).' ) ) @ utils . arg ( '--deleted' , dest = 'deleted' , action = 'store_true' , default = False , help = _ ( 'Only display deleted servers (Admin only).' ) ) @ utils . arg ( '--fields' , default = None , metavar = '<fields>' , help = _ ( 'Comma-separated list of fields to display. Use the show command to see which fields are available.' ) ) @ utils . arg ( '--minimal' , dest = 'minimal' , action = 'store_true' , default = False , help = _ ( 'Get only UUID and name.' ) ) @ utils . arg ( '--sort' , dest = 'sort' , metavar = '<key>[:<direction>]' , help = _ ( 'Comma-separated list of sort keys and directions in the form of <key>[:<asc|desc>]. The direction defaults to descending if not specified.' ) ) @ utils . arg ( '--marker' , dest = 'marker' , metavar = '<marker>' , default = None , help = _ ( 'The last server UUID of the previous page; displays list of servers after "marker".' ) ) @ utils . arg ( '--limit' , dest = 'limit' , metavar = '<limit>' , type = int , default = None , help = _ ( "Maximum number of servers to display. If limit == -1, all servers will be displayed. If limit is bigger than 'CONF.api.max_limit' option of Nova API, limit 'CONF.api.max_limit' will be used instead." ) ) @ utils . arg ( '--changes-since' , dest = 'changes_since' , metavar = '<changes_since>' , default = None , help = _ ( 'List only servers changed after a certain point of time.The provided time should be an ISO 8061 formatted time.ex 2016-03-04T06:27:59Z .' ) ) @ utils . arg ( '--tags' , dest = 'tags' , metavar = '<tags>' , default = None , help = _ ( "The given tags must all be present for a server to be included in the list result. Boolean expression in this case is 't1 AND t2'. Tags must be separated by commas: --tags <tag1,tag2>" ) , start_version = '2.26' ) @ utils . arg ( '--tags-any' , dest = 'tags-any' , metavar = '<tags-any>' , default = None , help = _ ( "If one of the given tags is present the server will be included in the list result. Boolean expression in this case is 't1 OR t2'. Tags must be separated by commas: --tags-any <tag1,tag2>" ) , start_version = '2.26' ) @ utils . arg ( '--not-tags' , dest = 'not-tags' , metavar = '<not-tags>' , default = None , help = _ ( "Only the servers that do not have any of the given tags will be included in the list results. Boolean expression in this case is 'NOT(t1 AND t2)'. Tags must be separated by commas: --not-tags <tag1,tag2>" ) , start_version = '2.26' ) @ utils . arg ( '--not-tags-any' , dest = 'not-tags-any' , metavar = '<not-tags-any>' , default = None , help = _ ( "Only the servers that do not have at least one of the given tags will be included in the list result. Boolean expression in this case is 'NOT(t1 OR t2)'. Tags must be separated by commas: --not-tags-any <tag1,tag2>" ) , start_version = '2.26' ) def do_list ( cs , args ) : imageid = None flavorid = None if args . image : imageid = _find_image ( cs , args . image ) . id if args . flavor : flavorid = _find_flavor ( cs , args . flavor ) . id if ( args . tenant or args . user ) : args . all_tenants = 1 search_opts = { 'all_tenants' : args . all_tenants , 'reservation_id' : args . reservation_id , 'ip' : args . ip , 'ip6' : args . ip6 , 'name' : args . name , 'image' : imageid , 'flavor' : flavorid , 'status' : args . status , 'tenant_id' : args . tenant , 'user_id' : args . user , 'host' : args . host , 'deleted' : args . deleted , 'instance_name' : args . instance_name , 'changes-since' : args . changes_since } for arg in ( 'tags' , 'tags-any' , 'not-tags' , 'not-tags-any' ) : if ( arg in args ) : search_opts [ arg ] = getattr ( args , arg ) filters = { 'flavor' : ( lambda f : f [ 'id' ] ) , 'security_groups' : utils . format_security_groups } id_col = 'ID' detailed = ( not args . minimal ) sort_keys = [ ] sort_dirs = [ ] if args . sort : for sort in args . sort . split ( ',' ) : ( sort_key , _sep , sort_dir ) = sort . partition ( ':' ) if ( not sort_dir ) : sort_dir = 'desc' elif ( sort_dir not in ( 'asc' , 'desc' ) ) : raise exceptions . CommandError ( ( _ ( 'Unknown sort direction: %s' ) % sort_dir ) ) sort_keys . append ( sort_key ) sort_dirs . append ( sort_dir ) if search_opts [ 'changes-since' ] : try : timeutils . parse_isotime ( search_opts [ 'changes-since' ] ) except ValueError : raise exceptions . CommandError ( ( _ ( 'Invalid changes-since value: %s' ) % search_opts [ 'changes-since' ] ) ) servers = cs . servers . list ( detailed = detailed , search_opts = search_opts , sort_keys = sort_keys , sort_dirs = sort_dirs , marker = args . marker , limit = args . limit ) convert = [ ( 'OS-EXT-SRV-ATTR:host' , 'host' ) , ( 'OS-EXT-STS:task_state' , 'task_state' ) , ( 'OS-EXT-SRV-ATTR:instance_name' , 'instance_name' ) , ( 'OS-EXT-STS:power_state' , 'power_state' ) , ( 'hostId' , 'host_id' ) ] _translate_keys ( servers , convert ) _translate_extended_states ( servers ) formatters = { } ( cols , fmts ) = _get_list_table_columns_and_formatters ( args . fields , servers , exclude_fields = ( 'id' , ) , filters = filters ) if args . minimal : columns = [ id_col , 'Name' ] elif cols : columns = ( [ id_col ] + cols ) formatters . update ( fmts ) else : columns = [ id_col , 'Name' , 'Status' , 'Task State' , 'Power State' , 'Networks' ] if search_opts [ 'all_tenants' ] : columns . insert ( 2 , 'Tenant ID' ) if search_opts [ 'changes-since' ] : columns . append ( 'Updated' ) formatters [ 'Networks' ] = utils . format_servers_list_networks sortby_index = 1 if args . sort : sortby_index = None utils . print_list ( servers , columns , formatters , sortby_index = sortby_index )
convert the value into a list .