Skip to content

Commit a02e7c8

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add support for showing account details"
2 parents 1dc9854 + 4733fd0 commit a02e7c8

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

doc/source/command-objects/account.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ Set account properties
1919

2020
Set a property on this account (repeat option to set multiple properties)
2121

22+
account show
23+
------------
24+
25+
Display account details
26+
27+
.. program:: account show
28+
.. code:: bash
29+
30+
os account show
31+
2232
account unset
2333
-------------
2434

openstackclient/api/object_store_v1.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,23 @@ def account_set(
411411
# registered in the catalog
412412
self.create("", headers=headers)
413413

414+
def account_show(self):
415+
"""Show account details"""
416+
417+
# NOTE(stevemar): Just a HEAD request to the endpoint already in the
418+
# catalog should be enough.
419+
response = self._request("HEAD", "")
420+
data = {}
421+
for k, v in response.headers.iteritems():
422+
data[k] = v
423+
# Map containers, bytes and objects a bit nicer
424+
data['Containers'] = data.pop('x-account-container-count', None)
425+
data['Objects'] = data.pop('x-account-object-count', None)
426+
data['Bytes'] = data.pop('x-account-bytes-used', None)
427+
# Add in Account info too
428+
data['Account'] = self._find_account_id()
429+
return data
430+
414431
def account_unset(
415432
self,
416433
properties,
@@ -433,3 +450,7 @@ def account_unset(
433450

434451
if headers:
435452
self.create("", headers=headers)
453+
454+
def _find_account_id(self):
455+
url_parts = urlparse(self.endpoint)
456+
return url_parts.path.split('/')[-1]

openstackclient/object/v1/account.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313

1414
"""Account v1 action implementations"""
1515

16-
1716
import logging
1817

1918
from cliff import command
19+
from cliff import show
20+
import six
2021

2122
from openstackclient.common import parseractions
2223
from openstackclient.common import utils
@@ -46,6 +47,17 @@ def take_action(self, parsed_args):
4647
)
4748

4849

50+
class ShowAccount(show.ShowOne):
51+
"""Display account details"""
52+
53+
log = logging.getLogger(__name__ + '.ShowAccount')
54+
55+
@utils.log_method(log)
56+
def take_action(self, parsed_args):
57+
data = self.app.client_manager.object_store.account_show()
58+
return zip(*sorted(six.iteritems(data)))
59+
60+
4961
class UnsetAccount(command.Command):
5062
"""Unset account properties"""
5163

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ openstack.network.v2 =
333333

334334
openstack.object_store.v1 =
335335
account_set = openstackclient.object.v1.account:SetAccount
336+
account_show = openstackclient.object.v1.account:ShowAccount
336337
account_unset = openstackclient.object.v1.account:UnsetAccount
337338
container_create = openstackclient.object.v1.container:CreateContainer
338339
container_delete = openstackclient.object.v1.container:DeleteContainer

0 commit comments

Comments
 (0)