Skip to content

Commit bc11c4d

Browse files
author
Dean Troyer
committed
Deprecate project usage list command
Rather than pointing the 'project usage list' entry point directly to ListUsage, this makes a ListProjectUsage subclass to alias the desired command and still allow for changing behaviour or issuing a deprecation messages. This implementation simply sets a new 'deprecated' attribute in the command class that cliff will use to skip this command when generating help output. The actual skipping of the command in help output is dependant on https://review.openstack.org/147349 merging in cliff, this review will simply have no effect on help output until a version of cliff with that update is present. The deprecation message printed is somewhat generic until https://review.openstack.org/147381 is merged in cliff. Until that is merged, the deprecation message will not have the name of the actual command given by the user in it, but rather the text 'this command'. Closes-bug: #1406654 Change-Id: Ie08d4f88d71a660fca1862405351109cd0aa86b6
1 parent 4a8a2fb commit bc11c4d

4 files changed

Lines changed: 30 additions & 12 deletions

File tree

‎doc/source/command-objects/usage.rst‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ List resource usage per project
1818
1919
.. option:: --start <start>
2020

21-
Usage range start date, ex 2012-01-20 (default: 4 weeks ago).
21+
Usage range start date, ex 2012-01-20 (default: 4 weeks ago)
2222

2323
.. option:: --end <end>
2424

@@ -27,7 +27,7 @@ List resource usage per project
2727
usage show
2828
----------
2929

30-
Show resource usage for a single project.
30+
Show resource usage for a single project
3131

3232
.. program:: usage show
3333
.. code:: bash
@@ -39,11 +39,11 @@ Show resource usage for a single project.
3939
4040
.. option:: --project <project>
4141

42-
Name or ID of project to show usage for.
42+
Name or ID of project to show usage for
4343

4444
.. option:: --start <start>
4545

46-
Usage range start date, ex 2012-01-20 (default: 4 weeks ago).
46+
Usage range start date, ex 2012-01-20 (default: 4 weeks ago)
4747

4848
.. option:: --end <end>
4949

‎openstackclient/compute/v2/usage.py‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
class ListUsage(lister.Lister):
30-
"""List resource usage per project. """
30+
"""List resource usage per project"""
3131

3232
log = logging.getLogger(__name__ + ".ListUsage")
3333

@@ -38,7 +38,7 @@ def get_parser(self, prog_name):
3838
metavar="<start>",
3939
default=None,
4040
help="Usage range start date, ex 2012-01-20"
41-
" (default: 4 weeks ago)."
41+
" (default: 4 weeks ago)"
4242
)
4343
parser.add_argument(
4444
"--end",
@@ -119,7 +119,7 @@ def _format_project(project):
119119

120120

121121
class ShowUsage(show.ShowOne):
122-
"""Show resource usage for a single project. """
122+
"""Show resource usage for a single project"""
123123

124124
log = logging.getLogger(__name__ + ".ShowUsage")
125125

@@ -129,20 +129,20 @@ def get_parser(self, prog_name):
129129
"--project",
130130
metavar="<project>",
131131
default=None,
132-
help="Name or ID of project to show usage for."
132+
help="Name or ID of project to show usage for"
133133
)
134134
parser.add_argument(
135135
"--start",
136136
metavar="<start>",
137137
default=None,
138138
help="Usage range start date, ex 2012-01-20"
139-
" (default: 4 weeks ago)."
139+
" (default: 4 weeks ago)"
140140
)
141141
parser.add_argument(
142142
"--end",
143143
metavar="<end>",
144144
default=None,
145-
help="Usage range end date, ex 2012-01-20 (default: tomorrow)."
145+
help="Usage range end date, ex 2012-01-20 (default: tomorrow)"
146146
)
147147
return parser
148148

@@ -188,3 +188,20 @@ def take_action(self, parsed_args):
188188
info['CPU Hours'] = float("%.2f" % usage.total_vcpus_usage)
189189
info['Disk GB-Hours'] = float("%.2f" % usage.total_local_gb_usage)
190190
return zip(*sorted(six.iteritems(info)))
191+
192+
193+
# This is out of order due to the subclass, will eventually be removed
194+
195+
class ListProjectUsage(ListUsage):
196+
"""List resource usage per project"""
197+
198+
deprecated = True
199+
200+
log = logging.getLogger('DEPRECATED:')
201+
202+
def take_action(self, parsed_args):
203+
self.log.warning(
204+
"%s is deprecated, use 'usage list'",
205+
getattr(self, 'cmd_name', 'this command'),
206+
)
207+
return super(ListProjectUsage, self).take_action(parsed_args)

‎openstackclient/shell.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ def initialize_app(self, argv):
303303
def prepare_to_run_command(self, cmd):
304304
"""Set up auth and API versions"""
305305
self.log.info(
306-
'command: %s.%s',
306+
'command: %s -> %s.%s',
307+
getattr(cmd, 'cmd_name', '<none>'),
307308
cmd.__class__.__module__,
308309
cmd.__class__.__name__,
309310
)

‎setup.cfg‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ openstack.compute.v2 =
9797
keypair_list = openstackclient.compute.v2.keypair:ListKeypair
9898
keypair_show = openstackclient.compute.v2.keypair:ShowKeypair
9999

100-
project_usage_list = openstackclient.compute.v2.usage:ListUsage
100+
project_usage_list = openstackclient.compute.v2.usage:ListProjectUsage
101101

102102
security_group_create = openstackclient.compute.v2.security_group:CreateSecurityGroup
103103
security_group_delete = openstackclient.compute.v2.security_group:DeleteSecurityGroup

0 commit comments

Comments
 (0)