add support for set/unset of container properties
include docs and commands to set and unset container properties Partial-Bug: #1501945 Change-Id: I8d7e8cf356a2321a37ed940c4e10cae411b94dfd
This commit is contained in:
parent
bf11960d55
commit
abaf711e24
@ -89,6 +89,26 @@ Save container contents locally
|
||||
|
||||
Container to save
|
||||
|
||||
container set
|
||||
-------------
|
||||
|
||||
Set container properties
|
||||
|
||||
.. program:: container set
|
||||
.. code:: bash
|
||||
|
||||
os container set
|
||||
[<container>]
|
||||
[--property <key=value> [...] ]
|
||||
|
||||
.. describe:: <container>
|
||||
|
||||
Container to modify
|
||||
|
||||
.. option:: --property <key=value>
|
||||
|
||||
Set a property on this container (repeat option to set multiple properties)
|
||||
|
||||
container show
|
||||
--------------
|
||||
|
||||
@ -103,3 +123,23 @@ Display container details
|
||||
.. describe:: <container>
|
||||
|
||||
Container to display
|
||||
|
||||
container unset
|
||||
---------------
|
||||
|
||||
Unset container properties
|
||||
|
||||
.. program:: container unset
|
||||
.. code:: bash
|
||||
|
||||
os container unset
|
||||
[<container>]
|
||||
[--property <key>]
|
||||
|
||||
.. describe:: <container>
|
||||
|
||||
Container to modify
|
||||
|
||||
.. option:: --property <key>
|
||||
|
||||
Property to remove from container (repeat option to remove multiple properties)
|
||||
|
@ -139,6 +139,23 @@ class APIv1(api.BaseAPI):
|
||||
for object in objects:
|
||||
self.object_save(container=container, object=object['name'])
|
||||
|
||||
def container_set(
|
||||
self,
|
||||
container,
|
||||
properties,
|
||||
):
|
||||
"""Set container properties
|
||||
|
||||
:param string container:
|
||||
name of container to modify
|
||||
:param dict properties:
|
||||
properties to add or update for the container
|
||||
"""
|
||||
|
||||
headers = self._set_properties(properties, 'X-Container-Meta-%s')
|
||||
if headers:
|
||||
self.create(container, headers=headers)
|
||||
|
||||
def container_show(
|
||||
self,
|
||||
container=None,
|
||||
@ -168,6 +185,24 @@ class APIv1(api.BaseAPI):
|
||||
}
|
||||
return data
|
||||
|
||||
def container_unset(
|
||||
self,
|
||||
container,
|
||||
properties,
|
||||
):
|
||||
"""Unset container properties
|
||||
|
||||
:param string container:
|
||||
name of container to modify
|
||||
:param dict properties:
|
||||
properties to remove from the container
|
||||
"""
|
||||
|
||||
headers = self._unset_properties(properties,
|
||||
'X-Remove-Container-Meta-%s')
|
||||
if headers:
|
||||
self.create(container, headers=headers)
|
||||
|
||||
def object_create(
|
||||
self,
|
||||
container=None,
|
||||
@ -397,14 +432,7 @@ class APIv1(api.BaseAPI):
|
||||
properties to add or update for the account
|
||||
"""
|
||||
|
||||
# NOTE(stevemar): As per the API, the headers have to be in the form
|
||||
# of "X-Account-Meta-Book: MobyDick"
|
||||
|
||||
headers = {}
|
||||
for k, v in properties.iteritems():
|
||||
header_name = 'X-Account-Meta-%s' % k
|
||||
headers[header_name] = v
|
||||
|
||||
headers = self._set_properties(properties, 'X-Account-Meta-%s')
|
||||
if headers:
|
||||
# NOTE(stevemar): The URL (first argument) in this case is already
|
||||
# set to the swift account endpoint, because that's how it's
|
||||
@ -438,19 +466,37 @@ class APIv1(api.BaseAPI):
|
||||
properties to remove from the account
|
||||
"""
|
||||
|
||||
# NOTE(stevemar): As per the API, the headers have to be in the form
|
||||
# of "X-Remove-Account-Meta-Book: x". In the case where metadata is
|
||||
# removed, we can set the value of the header to anything, so it's
|
||||
# set to 'x'
|
||||
|
||||
headers = {}
|
||||
for k in properties:
|
||||
header_name = 'X-Remove-Account-Meta-%s' % k
|
||||
headers[header_name] = "x"
|
||||
|
||||
headers = self._unset_properties(properties,
|
||||
'X-Remove-Account-Meta-%s')
|
||||
if headers:
|
||||
self.create("", headers=headers)
|
||||
|
||||
def _find_account_id(self):
|
||||
url_parts = urlparse(self.endpoint)
|
||||
return url_parts.path.split('/')[-1]
|
||||
|
||||
def _unset_properties(self, properties, header_tag):
|
||||
# NOTE(stevemar): As per the API, the headers have to be in the form
|
||||
# of "X-Remove-Account-Meta-Book: x". In the case where metadata is
|
||||
# removed, we can set the value of the header to anything, so it's
|
||||
# set to 'x'. In the case of a Container property we use:
|
||||
# "X-Remove-Container-Meta-Book: x", and the same logic applies for
|
||||
# Object properties
|
||||
|
||||
headers = {}
|
||||
for k in properties:
|
||||
header_name = header_tag % k
|
||||
headers[header_name] = 'x'
|
||||
return headers
|
||||
|
||||
def _set_properties(self, properties, header_tag):
|
||||
# NOTE(stevemar): As per the API, the headers have to be in the form
|
||||
# of "X-Account-Meta-Book: MobyDick". In the case of a Container
|
||||
# property we use: "X-Add-Container-Meta-Book: MobyDick", and the same
|
||||
# logic applies for Object properties
|
||||
|
||||
headers = {}
|
||||
for k, v in properties.iteritems():
|
||||
header_name = header_tag % k
|
||||
headers[header_name] = v
|
||||
return headers
|
||||
|
@ -23,6 +23,7 @@ from cliff import command
|
||||
from cliff import lister
|
||||
from cliff import show
|
||||
|
||||
from openstackclient.common import parseractions
|
||||
from openstackclient.common import utils
|
||||
|
||||
|
||||
@ -178,6 +179,36 @@ class SaveContainer(command.Command):
|
||||
)
|
||||
|
||||
|
||||
class SetContainer(command.Command):
|
||||
"""Set container properties"""
|
||||
|
||||
log = logging.getLogger(__name__ + '.SetContainer')
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(SetContainer, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'container',
|
||||
metavar='<container>',
|
||||
help='Container to modify',
|
||||
)
|
||||
parser.add_argument(
|
||||
"--property",
|
||||
metavar="<key=value>",
|
||||
required=True,
|
||||
action=parseractions.KeyValueAction,
|
||||
help="Set a property on this container "
|
||||
"(repeat option to set multiple properties)"
|
||||
)
|
||||
return parser
|
||||
|
||||
@utils.log_method(log)
|
||||
def take_action(self, parsed_args):
|
||||
self.app.client_manager.object_store.container_set(
|
||||
parsed_args.container,
|
||||
properties=parsed_args.property,
|
||||
)
|
||||
|
||||
|
||||
class ShowContainer(show.ShowOne):
|
||||
"""Display container details"""
|
||||
|
||||
@ -200,3 +231,34 @@ class ShowContainer(show.ShowOne):
|
||||
)
|
||||
|
||||
return zip(*sorted(six.iteritems(data)))
|
||||
|
||||
|
||||
class UnsetContainer(command.Command):
|
||||
"""Unset container properties"""
|
||||
|
||||
log = logging.getLogger(__name__ + '.UnsetContainer')
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(UnsetContainer, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'container',
|
||||
metavar='<container>',
|
||||
help='Container to modify',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--property',
|
||||
metavar='<key>',
|
||||
required=True,
|
||||
action='append',
|
||||
default=[],
|
||||
help='Property to remove from container '
|
||||
'(repeat option to remove multiple properties)',
|
||||
)
|
||||
return parser
|
||||
|
||||
@utils.log_method(log)
|
||||
def take_action(self, parsed_args):
|
||||
self.app.client_manager.object_store.container_unset(
|
||||
parsed_args.container,
|
||||
properties=parsed_args.property,
|
||||
)
|
||||
|
@ -339,7 +339,9 @@ openstack.object_store.v1 =
|
||||
container_delete = openstackclient.object.v1.container:DeleteContainer
|
||||
container_list = openstackclient.object.v1.container:ListContainer
|
||||
container_save = openstackclient.object.v1.container:SaveContainer
|
||||
container_set = openstackclient.object.v1.container:SetContainer
|
||||
container_show = openstackclient.object.v1.container:ShowContainer
|
||||
container_unset = openstackclient.object.v1.container:UnsetContainer
|
||||
object_create = openstackclient.object.v1.object:CreateObject
|
||||
object_delete = openstackclient.object.v1.object:DeleteObject
|
||||
object_list = openstackclient.object.v1.object:ListObject
|
||||
|
Loading…
x
Reference in New Issue
Block a user