Remove tenant round 3 - other commands
Mostly options and help strings: * image, server, project usage, volume Change-Id: I788b0660f8c2daacde53c20a72dd1afc60cf5159
This commit is contained in:
parent
c385180df2
commit
7d138b94ec
@ -91,7 +91,7 @@ def format_dict(data):
|
||||
def get_item_properties(item, fields, mixed_case_fields=[], formatters={}):
|
||||
"""Return a tuple containing the item properties.
|
||||
|
||||
:param item: a single item resource (e.g. Server, Tenant, etc)
|
||||
:param item: a single item resource (e.g. Server, Project, etc)
|
||||
:param fields: tuple of strings with the desired field names
|
||||
:param mixed_case_fields: tuple of field names to preserve case
|
||||
:param formatters: dictionary mapping field names to callables
|
||||
|
@ -414,10 +414,10 @@ class ListServer(lister.Lister):
|
||||
metavar='<server-name>',
|
||||
help='regular expression to match instance name (admin only)')
|
||||
parser.add_argument(
|
||||
'--all-tenants',
|
||||
'--all-projects',
|
||||
action='store_true',
|
||||
default=bool(int(os.environ.get("ALL_TENANTS", 0))),
|
||||
help='display information from all tenants (admin only)')
|
||||
default=bool(int(os.environ.get("ALL_PROJECTS", 0))),
|
||||
help='Include all projects (admin only)')
|
||||
parser.add_argument(
|
||||
'--long',
|
||||
action='store_true',
|
||||
@ -438,7 +438,7 @@ class ListServer(lister.Lister):
|
||||
'flavor': parsed_args.flavor,
|
||||
'image': parsed_args.image,
|
||||
'host': parsed_args.host,
|
||||
'all_tenants': parsed_args.all_tenants,
|
||||
'all_tenants': parsed_args.all_projects,
|
||||
}
|
||||
self.log.debug('search options: %s', search_opts)
|
||||
|
||||
|
@ -47,6 +47,15 @@ class ListUsage(lister.Lister):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)" % parsed_args)
|
||||
|
||||
def _format_project(project):
|
||||
if not project:
|
||||
return ""
|
||||
if project in project_cache.keys():
|
||||
return project_cache[project].name
|
||||
else:
|
||||
return project
|
||||
|
||||
compute_client = self.app.client_manager.compute
|
||||
columns = (
|
||||
"tenant_id",
|
||||
@ -55,7 +64,7 @@ class ListUsage(lister.Lister):
|
||||
"total_local_gb_usage"
|
||||
)
|
||||
column_headers = (
|
||||
"Project ID",
|
||||
"Project",
|
||||
"RAM MB-Hours",
|
||||
"CPU Hours",
|
||||
"Disk GB-Hours"
|
||||
@ -76,6 +85,15 @@ class ListUsage(lister.Lister):
|
||||
|
||||
usage_list = compute_client.usage.list(start, end)
|
||||
|
||||
# Cache the project list
|
||||
project_cache = {}
|
||||
try:
|
||||
for p in self.app.client_manager.identity.tenants.list():
|
||||
project_cache[p.id] = p
|
||||
except Exception:
|
||||
# Just forget it if there's any trouble
|
||||
pass
|
||||
|
||||
if len(usage_list) > 0:
|
||||
print("Usage from %s to %s:" % (start.strftime(dateformat),
|
||||
end.strftime(dateformat)))
|
||||
@ -84,6 +102,7 @@ class ListUsage(lister.Lister):
|
||||
(utils.get_item_properties(
|
||||
s, columns,
|
||||
formatters={
|
||||
'tenant_id': _format_project,
|
||||
'total_memory_mb_usage': lambda x: float("%.2f" % x),
|
||||
'total_vcpus_usage': lambda x: float("%.2f" % x),
|
||||
'total_local_gb_usage': lambda x: float("%.2f" % x),
|
||||
|
@ -71,8 +71,8 @@ class CreateImage(show.ShowOne):
|
||||
)
|
||||
parser.add_argument(
|
||||
"--owner",
|
||||
metavar="<tenant>",
|
||||
help="Owner of the image",
|
||||
metavar="<project>",
|
||||
help="Image owner (project name or ID)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--size",
|
||||
@ -296,8 +296,8 @@ class SetImage(show.ShowOne):
|
||||
)
|
||||
parser.add_argument(
|
||||
"--owner",
|
||||
metavar="<tenant>",
|
||||
help="Owner of the image",
|
||||
metavar="<project>",
|
||||
help="Image owner (project name or ID)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--min-disk",
|
||||
|
@ -179,10 +179,10 @@ class ListVolume(lister.Lister):
|
||||
help='Filter results by name',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--all-tenants',
|
||||
'--all-projects',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='Display information from all tenants (admin only)',
|
||||
help='Include all projects (admin only)',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--long',
|
||||
@ -232,7 +232,7 @@ class ListVolume(lister.Lister):
|
||||
'Attached',
|
||||
)
|
||||
search_opts = {
|
||||
'all_tenants': parsed_args.all_tenants,
|
||||
'all_tenants': parsed_args.all_projects,
|
||||
'display_name': parsed_args.name,
|
||||
'status': parsed_args.status,
|
||||
}
|
||||
@ -322,7 +322,11 @@ class ShowVolume(show.ShowOne):
|
||||
volume._info.update(
|
||||
{'properties': utils.format_dict(volume._info.pop('metadata'))}
|
||||
)
|
||||
|
||||
if 'os-vol-tenant-attr:tenant_id' in volume._info:
|
||||
volume._info.update(
|
||||
{'project_id': volume._info.pop(
|
||||
'os-vol-tenant-attr:tenant_id')}
|
||||
)
|
||||
return zip(*sorted(six.iteritems(volume._info)))
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user