Skip to content

Commit a4483a0

Browse files
Steve Martinellilin-hua-cheng
authored andcommitted
Add support for updating swift account properties
this patch adds support for creating/updating and removing properties (nee: metadata) for object store accounts. Partial-Bug: #1501943 Change-Id: I3ed70a5d8bd8920fedb79adc60cdc602261d5eef
1 parent 0daa096 commit a4483a0

4 files changed

Lines changed: 155 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=======
2+
account
3+
=======
4+
5+
Object Store v1
6+
7+
account set
8+
-----------
9+
10+
Set account properties
11+
12+
.. program:: account set
13+
.. code:: bash
14+
15+
os account set
16+
[--property <key=value> [...] ]
17+
18+
.. option:: --property <key=value>
19+
20+
Set a property on this account (repeat option to set multiple properties)
21+
22+
account unset
23+
-------------
24+
25+
Unset account properties
26+
27+
.. program:: account unset
28+
.. code:: bash
29+
30+
os account unset
31+
[--property <key>]
32+
33+
.. option:: --property <key>
34+
35+
Property to remove from account (repeat option to remove multiple properties)

openstackclient/api/object_store_v1.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,50 @@ def object_show(
386386
data[key.lower()] = value
387387

388388
return data
389+
390+
def account_set(
391+
self,
392+
properties,
393+
):
394+
"""Set account properties
395+
396+
:param dict properties:
397+
properties to add or update for the account
398+
"""
399+
400+
# NOTE(stevemar): As per the API, the headers have to be in the form
401+
# of "X-Account-Meta-Book: MobyDick"
402+
403+
headers = {}
404+
for k, v in properties.iteritems():
405+
header_name = 'X-Account-Meta-%s' % k
406+
headers[header_name] = v
407+
408+
if headers:
409+
# NOTE(stevemar): The URL (first argument) in this case is already
410+
# set to the swift account endpoint, because that's how it's
411+
# registered in the catalog
412+
self.create("", headers=headers)
413+
414+
def account_unset(
415+
self,
416+
properties,
417+
):
418+
"""Unset account properties
419+
420+
:param dict properties:
421+
properties to remove from the account
422+
"""
423+
424+
# NOTE(stevemar): As per the API, the headers have to be in the form
425+
# of "X-Remove-Account-Meta-Book: x". In the case where metadata is
426+
# removed, we can set the value of the header to anything, so it's
427+
# set to 'x'
428+
429+
headers = {}
430+
for k in properties:
431+
header_name = 'X-Remove-Account-Meta-%s' % k
432+
headers[header_name] = "x"
433+
434+
if headers:
435+
self.create("", headers=headers)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
#
13+
14+
"""Account v1 action implementations"""
15+
16+
17+
import logging
18+
19+
from cliff import command
20+
21+
from openstackclient.common import parseractions
22+
from openstackclient.common import utils
23+
24+
25+
class SetAccount(command.Command):
26+
"""Set account properties"""
27+
28+
log = logging.getLogger(__name__ + '.SetAccount')
29+
30+
def get_parser(self, prog_name):
31+
parser = super(SetAccount, self).get_parser(prog_name)
32+
parser.add_argument(
33+
"--property",
34+
metavar="<key=value>",
35+
required=True,
36+
action=parseractions.KeyValueAction,
37+
help="Set a property on this account "
38+
"(repeat option to set multiple properties)"
39+
)
40+
return parser
41+
42+
@utils.log_method(log)
43+
def take_action(self, parsed_args):
44+
self.app.client_manager.object_store.account_set(
45+
properties=parsed_args.property,
46+
)
47+
48+
49+
class UnsetAccount(command.Command):
50+
"""Unset account properties"""
51+
52+
log = logging.getLogger(__name__ + '.UnsetAccount')
53+
54+
def get_parser(self, prog_name):
55+
parser = super(UnsetAccount, self).get_parser(prog_name)
56+
parser.add_argument(
57+
'--property',
58+
metavar='<key>',
59+
required=True,
60+
action='append',
61+
default=[],
62+
help='Property to remove from account '
63+
'(repeat option to remove multiple properties)',
64+
)
65+
return parser
66+
67+
@utils.log_method(log)
68+
def take_action(self, parsed_args):
69+
self.app.client_manager.object_store.account_unset(
70+
properties=parsed_args.property,
71+
)

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ openstack.network.v2 =
331331
network_show = openstackclient.network.v2.network:ShowNetwork
332332

333333
openstack.object_store.v1 =
334+
account_set = openstackclient.object.v1.account:SetAccount
335+
account_unset = openstackclient.object.v1.account:UnsetAccount
334336
container_create = openstackclient.object.v1.container:CreateContainer
335337
container_delete = openstackclient.object.v1.container:DeleteContainer
336338
container_list = openstackclient.object.v1.container:ListContainer

0 commit comments

Comments
 (0)