summaryrefslogtreecommitdiff
path: root/openstackclient/compute/v2/usage.py
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2023-05-08 10:48:54 +0100
committerStephen Finucane <sfinucan@redhat.com>2023-05-10 10:51:30 +0100
commit28ffa2bf9f017212da5eb84b0cf74df62e2f5eb9 (patch)
treee272d2bd82826a10df7e00855e35c78a27d2b6c9 /openstackclient/compute/v2/usage.py
parent5cb16aebcc53033ff1fd785b957eef0b7c9773e2 (diff)
downloadpython-openstackclient-28ffa2bf9f017212da5eb84b0cf74df62e2f5eb9.tar.gz
Blacken openstackclient.compute
Black used with the '-l 79 -S' flags. A future change will ignore this commit in git-blame history by adding a 'git-blame-ignore-revs' file. Change-Id: I9af45c062d179ab3dc2a5e969e1c467932753a2b Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'openstackclient/compute/v2/usage.py')
-rw-r--r--openstackclient/compute/v2/usage.py90
1 files changed, 53 insertions, 37 deletions
diff --git a/openstackclient/compute/v2/usage.py b/openstackclient/compute/v2/usage.py
index 86f538a7..3b8bda2d 100644
--- a/openstackclient/compute/v2/usage.py
+++ b/openstackclient/compute/v2/usage.py
@@ -54,13 +54,11 @@ class ProjectColumn(cliff_columns.FormattableColumn):
class CountColumn(cliff_columns.FormattableColumn):
-
def human_readable(self):
return len(self._value) if self._value is not None else None
class FloatColumn(cliff_columns.FormattableColumn):
-
def human_readable(self):
return float("%.2f" % self._value)
@@ -68,7 +66,8 @@ class FloatColumn(cliff_columns.FormattableColumn):
def _formatters(project_cache):
return {
'project_id': functools.partial(
- ProjectColumn, project_cache=project_cache),
+ ProjectColumn, project_cache=project_cache
+ ),
'server_usages': CountColumn,
'total_memory_mb_usage': FloatColumn,
'total_vcpus_usage': FloatColumn,
@@ -115,19 +114,20 @@ class ListUsage(command.Lister):
"--start",
metavar="<start>",
default=None,
- help=_("Usage range start date, ex 2012-01-20"
- " (default: 4 weeks ago)")
+ help=_(
+ "Usage range start date, ex 2012-01-20"
+ " (default: 4 weeks ago)"
+ ),
)
parser.add_argument(
"--end",
metavar="<end>",
default=None,
- help=_("Usage range end date, ex 2012-01-20 (default: tomorrow)")
+ help=_("Usage range end date, ex 2012-01-20 (default: tomorrow)"),
)
return parser
def take_action(self, parsed_args):
-
def _format_project(project):
if not project:
return ""
@@ -142,14 +142,14 @@ class ListUsage(command.Lister):
"server_usages",
"total_memory_mb_usage",
"total_vcpus_usage",
- "total_local_gb_usage"
+ "total_local_gb_usage",
)
column_headers = (
"Project",
"Servers",
"RAM MB-Hours",
"CPU Hours",
- "Disk GB-Hours"
+ "Disk GB-Hours",
)
date_cli_format = "%Y-%m-%d"
@@ -158,7 +158,8 @@ class ListUsage(command.Lister):
if parsed_args.start:
start = datetime.datetime.strptime(
- parsed_args.start, date_cli_format)
+ parsed_args.start, date_cli_format
+ )
else:
start = now - datetime.timedelta(weeks=4)
@@ -167,10 +168,13 @@ class ListUsage(command.Lister):
else:
end = now + datetime.timedelta(days=1)
- usage_list = list(compute_client.usages(
- start=start.strftime(date_api_format),
- end=end.strftime(date_api_format),
- detailed=True))
+ usage_list = list(
+ compute_client.usages(
+ start=start.strftime(date_api_format),
+ end=end.strftime(date_api_format),
+ detailed=True,
+ )
+ )
# Cache the project list
project_cache = {}
@@ -182,18 +186,23 @@ class ListUsage(command.Lister):
pass
if parsed_args.formatter == 'table' and len(usage_list) > 0:
- self.app.stdout.write(_("Usage from %(start)s to %(end)s: \n") % {
- "start": start.strftime(date_cli_format),
- "end": end.strftime(date_cli_format),
- })
+ self.app.stdout.write(
+ _("Usage from %(start)s to %(end)s: \n")
+ % {
+ "start": start.strftime(date_cli_format),
+ "end": end.strftime(date_cli_format),
+ }
+ )
return (
column_headers,
(
utils.get_item_properties(
- s, columns,
+ s,
+ columns,
formatters=_formatters(project_cache),
- ) for s in usage_list
+ )
+ for s in usage_list
),
)
@@ -207,20 +216,22 @@ class ShowUsage(command.ShowOne):
"--project",
metavar="<project>",
default=None,
- help=_("Name or ID of project to show usage for")
+ help=_("Name or ID of project to show usage for"),
)
parser.add_argument(
"--start",
metavar="<start>",
default=None,
- help=_("Usage range start date, ex 2012-01-20"
- " (default: 4 weeks ago)")
+ help=_(
+ "Usage range start date, ex 2012-01-20"
+ " (default: 4 weeks ago)"
+ ),
)
parser.add_argument(
"--end",
metavar="<end>",
default=None,
- help=_("Usage range end date, ex 2012-01-20 (default: tomorrow)")
+ help=_("Usage range end date, ex 2012-01-20 (default: tomorrow)"),
)
return parser
@@ -233,7 +244,8 @@ class ShowUsage(command.ShowOne):
if parsed_args.start:
start = datetime.datetime.strptime(
- parsed_args.start, date_cli_format)
+ parsed_args.start, date_cli_format
+ )
else:
start = now - datetime.timedelta(weeks=4)
@@ -252,33 +264,37 @@ class ShowUsage(command.ShowOne):
project = self.app.client_manager.auth_ref.project_id
usage = compute_client.get_usage(
- project=project, start=start.strftime(date_api_format),
- end=end.strftime(date_api_format))
+ project=project,
+ start=start.strftime(date_api_format),
+ end=end.strftime(date_api_format),
+ )
if parsed_args.formatter == 'table':
- self.app.stdout.write(_(
- "Usage from %(start)s to %(end)s on project %(project)s: \n"
- ) % {
- "start": start.strftime(date_cli_format),
- "end": end.strftime(date_cli_format),
- "project": project,
- })
+ self.app.stdout.write(
+ _("Usage from %(start)s to %(end)s on project %(project)s: \n")
+ % {
+ "start": start.strftime(date_cli_format),
+ "end": end.strftime(date_cli_format),
+ "project": project,
+ }
+ )
columns = (
"project_id",
"server_usages",
"total_memory_mb_usage",
"total_vcpus_usage",
- "total_local_gb_usage"
+ "total_local_gb_usage",
)
column_headers = (
"Project",
"Servers",
"RAM MB-Hours",
"CPU Hours",
- "Disk GB-Hours"
+ "Disk GB-Hours",
)
data = utils.get_item_properties(
- usage, columns, formatters=_formatters(None))
+ usage, columns, formatters=_formatters(None)
+ )
return column_headers, data