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={}):
|
def get_item_properties(item, fields, mixed_case_fields=[], formatters={}):
|
||||||
"""Return a tuple containing the item properties.
|
"""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 fields: tuple of strings with the desired field names
|
||||||
:param mixed_case_fields: tuple of field names to preserve case
|
:param mixed_case_fields: tuple of field names to preserve case
|
||||||
:param formatters: dictionary mapping field names to callables
|
:param formatters: dictionary mapping field names to callables
|
||||||
|
@ -414,10 +414,10 @@ class ListServer(lister.Lister):
|
|||||||
metavar='<server-name>',
|
metavar='<server-name>',
|
||||||
help='regular expression to match instance name (admin only)')
|
help='regular expression to match instance name (admin only)')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--all-tenants',
|
'--all-projects',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=bool(int(os.environ.get("ALL_TENANTS", 0))),
|
default=bool(int(os.environ.get("ALL_PROJECTS", 0))),
|
||||||
help='display information from all tenants (admin only)')
|
help='Include all projects (admin only)')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--long',
|
'--long',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
@ -438,7 +438,7 @@ class ListServer(lister.Lister):
|
|||||||
'flavor': parsed_args.flavor,
|
'flavor': parsed_args.flavor,
|
||||||
'image': parsed_args.image,
|
'image': parsed_args.image,
|
||||||
'host': parsed_args.host,
|
'host': parsed_args.host,
|
||||||
'all_tenants': parsed_args.all_tenants,
|
'all_tenants': parsed_args.all_projects,
|
||||||
}
|
}
|
||||||
self.log.debug('search options: %s', search_opts)
|
self.log.debug('search options: %s', search_opts)
|
||||||
|
|
||||||
|
@ -47,6 +47,15 @@ class ListUsage(lister.Lister):
|
|||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug("take_action(%s)" % 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
|
compute_client = self.app.client_manager.compute
|
||||||
columns = (
|
columns = (
|
||||||
"tenant_id",
|
"tenant_id",
|
||||||
@ -55,7 +64,7 @@ class ListUsage(lister.Lister):
|
|||||||
"total_local_gb_usage"
|
"total_local_gb_usage"
|
||||||
)
|
)
|
||||||
column_headers = (
|
column_headers = (
|
||||||
"Project ID",
|
"Project",
|
||||||
"RAM MB-Hours",
|
"RAM MB-Hours",
|
||||||
"CPU Hours",
|
"CPU Hours",
|
||||||
"Disk GB-Hours"
|
"Disk GB-Hours"
|
||||||
@ -76,6 +85,15 @@ class ListUsage(lister.Lister):
|
|||||||
|
|
||||||
usage_list = compute_client.usage.list(start, end)
|
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:
|
if len(usage_list) > 0:
|
||||||
print("Usage from %s to %s:" % (start.strftime(dateformat),
|
print("Usage from %s to %s:" % (start.strftime(dateformat),
|
||||||
end.strftime(dateformat)))
|
end.strftime(dateformat)))
|
||||||
@ -84,6 +102,7 @@ class ListUsage(lister.Lister):
|
|||||||
(utils.get_item_properties(
|
(utils.get_item_properties(
|
||||||
s, columns,
|
s, columns,
|
||||||
formatters={
|
formatters={
|
||||||
|
'tenant_id': _format_project,
|
||||||
'total_memory_mb_usage': lambda x: float("%.2f" % x),
|
'total_memory_mb_usage': lambda x: float("%.2f" % x),
|
||||||
'total_vcpus_usage': lambda x: float("%.2f" % x),
|
'total_vcpus_usage': lambda x: float("%.2f" % x),
|
||||||
'total_local_gb_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(
|
parser.add_argument(
|
||||||
"--owner",
|
"--owner",
|
||||||
metavar="<tenant>",
|
metavar="<project>",
|
||||||
help="Owner of the image",
|
help="Image owner (project name or ID)",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--size",
|
"--size",
|
||||||
@ -296,8 +296,8 @@ class SetImage(show.ShowOne):
|
|||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--owner",
|
"--owner",
|
||||||
metavar="<tenant>",
|
metavar="<project>",
|
||||||
help="Owner of the image",
|
help="Image owner (project name or ID)",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--min-disk",
|
"--min-disk",
|
||||||
|
@ -179,10 +179,10 @@ class ListVolume(lister.Lister):
|
|||||||
help='Filter results by name',
|
help='Filter results by name',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--all-tenants',
|
'--all-projects',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help='Display information from all tenants (admin only)',
|
help='Include all projects (admin only)',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--long',
|
'--long',
|
||||||
@ -232,7 +232,7 @@ class ListVolume(lister.Lister):
|
|||||||
'Attached',
|
'Attached',
|
||||||
)
|
)
|
||||||
search_opts = {
|
search_opts = {
|
||||||
'all_tenants': parsed_args.all_tenants,
|
'all_tenants': parsed_args.all_projects,
|
||||||
'display_name': parsed_args.name,
|
'display_name': parsed_args.name,
|
||||||
'status': parsed_args.status,
|
'status': parsed_args.status,
|
||||||
}
|
}
|
||||||
@ -322,7 +322,11 @@ class ShowVolume(show.ShowOne):
|
|||||||
volume._info.update(
|
volume._info.update(
|
||||||
{'properties': utils.format_dict(volume._info.pop('metadata'))}
|
{'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)))
|
return zip(*sorted(six.iteritems(volume._info)))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user