Command to list the boards of a fleet.
Change-Id: Ica347ca88867e17e9b2c85c19fe54d9fc0b4bc8e
This commit is contained in:
parent
bed504ca53
commit
1b8b99dfc1
@ -95,3 +95,67 @@ class FleetManager(base.CreateManager):
|
|||||||
def update(self, fleet_id, patch, http_method='PATCH'):
|
def update(self, fleet_id, patch, http_method='PATCH'):
|
||||||
return self._update(resource_id=fleet_id, patch=patch,
|
return self._update(resource_id=fleet_id, patch=patch,
|
||||||
method=http_method)
|
method=http_method)
|
||||||
|
|
||||||
|
def boards_in_fleets(self, status=None, marker=None, limit=None,
|
||||||
|
detail=False, sort_key=None, sort_dir=None,
|
||||||
|
fields=None,
|
||||||
|
project=None, fleet=None):
|
||||||
|
"""Retrieve a list of boards.
|
||||||
|
|
||||||
|
:param marker: Optional, the UUID of a board, eg the last
|
||||||
|
board from a previous result set. Return
|
||||||
|
the next result set.
|
||||||
|
:param limit: The maximum number of results to return per
|
||||||
|
request, if:
|
||||||
|
|
||||||
|
1) limit > 0, the maximum number of boards to return.
|
||||||
|
2) limit == 0, return the entire list of boards.
|
||||||
|
3) limit param is NOT specified (None), the number of items
|
||||||
|
returned respect the maximum imposed by the Iotronic API
|
||||||
|
(see Iotronic's api.max_limit option).
|
||||||
|
|
||||||
|
:param detail: Optional, boolean whether to return detailed information
|
||||||
|
about boards.
|
||||||
|
|
||||||
|
:param sort_key: Optional, field used for sorting.
|
||||||
|
|
||||||
|
:param sort_dir: Optional, direction of sorting, either 'asc' (the
|
||||||
|
default) or 'desc'.
|
||||||
|
|
||||||
|
:param fields: Optional, a list with a specified set of fields
|
||||||
|
of the resource to be returned. Can not be used
|
||||||
|
when 'detail' is set.
|
||||||
|
|
||||||
|
:param project: Optional string value to get
|
||||||
|
only boards of the project.
|
||||||
|
|
||||||
|
:returns: A list of boards.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if limit is not None:
|
||||||
|
limit = int(limit)
|
||||||
|
|
||||||
|
if detail and fields:
|
||||||
|
raise exc.InvalidAttribute(_("Can't fetch a subset of fields "
|
||||||
|
"with 'detail' set"))
|
||||||
|
|
||||||
|
filters = utils.common_filters(marker, limit, sort_key, sort_dir,
|
||||||
|
fields)
|
||||||
|
if project is not None:
|
||||||
|
filters.append('project=%s' % project)
|
||||||
|
if status is not None:
|
||||||
|
filters.append('status=%s' % status)
|
||||||
|
|
||||||
|
path = fleet + '/'
|
||||||
|
|
||||||
|
if detail:
|
||||||
|
path += 'detail'
|
||||||
|
if filters:
|
||||||
|
path += '?' + '&'.join(filters)
|
||||||
|
|
||||||
|
if limit is None:
|
||||||
|
return self._list(self._path(path), "boards")
|
||||||
|
else:
|
||||||
|
return self._list_pagination(self._path(path), "boards",
|
||||||
|
limit=limit)
|
||||||
|
@ -116,6 +116,97 @@ def do_fleet_list(cc, args):
|
|||||||
json_flag=args.json)
|
json_flag=args.json)
|
||||||
|
|
||||||
|
|
||||||
|
@cliutils.arg(
|
||||||
|
'fleet',
|
||||||
|
metavar='<id>',
|
||||||
|
help="Name or UUID of the fleet ")
|
||||||
|
@cliutils.arg(
|
||||||
|
'--limit',
|
||||||
|
metavar='<limit>',
|
||||||
|
type=int,
|
||||||
|
help='Maximum number of boards to return per request, '
|
||||||
|
'0 for no limit. Default is the maximum number used '
|
||||||
|
'by the Iotronic API Service.')
|
||||||
|
@cliutils.arg(
|
||||||
|
'--marker',
|
||||||
|
metavar='<board>',
|
||||||
|
help='Board UUID (for example, of the last board in the list from '
|
||||||
|
'a previous request). Returns the list of boards after this UUID.')
|
||||||
|
@cliutils.arg(
|
||||||
|
'--sort-key',
|
||||||
|
metavar='<field>',
|
||||||
|
help='Board field that will be used for sorting.')
|
||||||
|
@cliutils.arg(
|
||||||
|
'--status',
|
||||||
|
metavar='<field>',
|
||||||
|
help='Filter by board status ')
|
||||||
|
@cliutils.arg(
|
||||||
|
'--sort-dir',
|
||||||
|
metavar='<direction>',
|
||||||
|
choices=['asc', 'desc'],
|
||||||
|
help='Sort direction: "asc" (the default) or "desc".')
|
||||||
|
@cliutils.arg(
|
||||||
|
'--project',
|
||||||
|
metavar='<project>',
|
||||||
|
help="Project of the list.")
|
||||||
|
@cliutils.arg(
|
||||||
|
'--detail',
|
||||||
|
dest='detail',
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help="Show detailed information about the boards.")
|
||||||
|
@cliutils.arg(
|
||||||
|
'--fields',
|
||||||
|
nargs='+',
|
||||||
|
dest='fields',
|
||||||
|
metavar='<field>',
|
||||||
|
action='append',
|
||||||
|
default=[],
|
||||||
|
help="One or more board fields. Only these fields will be fetched from "
|
||||||
|
"the server. Can not be used when '--detail' is specified.")
|
||||||
|
def do_boards_in_fleets(cc, args):
|
||||||
|
"""List the boards which are registered in a Iotronic Fleet."""
|
||||||
|
fields = args.fields[0] if args.fields else None
|
||||||
|
utils.check_empty_arg(args.fleet, '<id>')
|
||||||
|
utils.check_for_invalid_fields(
|
||||||
|
fields, res_fields.FLEET_DETAILED_RESOURCE.fields)
|
||||||
|
|
||||||
|
params = {}
|
||||||
|
params['fleet'] = args.fleet
|
||||||
|
|
||||||
|
if args.status:
|
||||||
|
params['status'] = args.status
|
||||||
|
|
||||||
|
if args.project is not None:
|
||||||
|
params['project'] = args.project
|
||||||
|
|
||||||
|
if args.detail:
|
||||||
|
fields = res_fields.BOARD_DETAILED_RESOURCE.fields
|
||||||
|
field_labels = res_fields.BOARD_DETAILED_RESOURCE.labels
|
||||||
|
elif args.fields:
|
||||||
|
utils.check_for_invalid_fields(
|
||||||
|
args.fields[0], res_fields.BOARD_DETAILED_RESOURCE.fields)
|
||||||
|
resource = res_fields.Resource(args.fields[0])
|
||||||
|
fields = resource.fields
|
||||||
|
field_labels = resource.labels
|
||||||
|
else:
|
||||||
|
fields = res_fields.BOARD_RESOURCE.fields
|
||||||
|
field_labels = res_fields.BOARD_RESOURCE.labels
|
||||||
|
|
||||||
|
sort_fields = res_fields.BOARD_DETAILED_RESOURCE.sort_fields
|
||||||
|
sort_field_labels = res_fields.BOARD_DETAILED_RESOURCE.sort_labels
|
||||||
|
|
||||||
|
params.update(utils.common_params_for_list(args,
|
||||||
|
sort_fields,
|
||||||
|
sort_field_labels))
|
||||||
|
|
||||||
|
boards = cc.fleet.boards_in_fleets(**params)
|
||||||
|
cliutils.print_list(boards, fields,
|
||||||
|
field_labels=field_labels,
|
||||||
|
sortby_index=None,
|
||||||
|
json_flag=args.json)
|
||||||
|
|
||||||
|
|
||||||
@cliutils.arg(
|
@cliutils.arg(
|
||||||
'name',
|
'name',
|
||||||
metavar='<name>',
|
metavar='<name>',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user