add set/unset support for objects in object store

add docs and command support to set and unset metadata of objects
that are stored in an object store (swift).

Closes-Bug: #1501945

Change-Id: If838a4b3343b6ddb97cd4bd1cb63f0ba1c1a00a1
This commit is contained in:
Steve Martinelli 2015-09-11 00:38:56 -05:00
parent abaf711e24
commit e48c7afee4
4 changed files with 166 additions and 0 deletions

View File

@ -119,6 +119,31 @@ Save object locally
Object to save Object to save
object set
----------
Set object properties
.. program:: object set
.. code:: bash
os object set
<container>
[<object>]
[--property <key=value> [...] ]
.. describe:: <container>
Modify <object> from <container>
.. describe:: <object>
Object to modify
.. option:: --property <key=value>
Set a property on this object (repeat option to set multiple properties)
object show object show
----------- -----------
@ -138,3 +163,28 @@ Display object details
.. describe:: <object> .. describe:: <object>
Object to display Object to display
object unset
------------
Unset object properties
.. program:: object unset
.. code:: bash
os object unset
<container>
[<object>]
[--property <key>]
.. describe:: <container>
Modify <object> from <container>
.. describe:: <object>
Object to modify
.. option:: --property <key>
Property to remove from object (repeat option to remove multiple properties)

View File

@ -366,6 +366,46 @@ class APIv1(api.BaseAPI):
for chunk in response.iter_content(): for chunk in response.iter_content():
f.write(chunk) f.write(chunk)
def object_set(
self,
container,
object,
properties,
):
"""Set object properties
:param string container:
container name for object to modify
:param string object:
name of object to modify
:param dict properties:
properties to add or update for the container
"""
headers = self._set_properties(properties, 'X-Object-Meta-%s')
if headers:
self.create("%s/%s" % (container, object), headers=headers)
def object_unset(
self,
container,
object,
properties,
):
"""Unset object properties
:param string container:
container name for object to modify
:param string object:
name of object to modify
:param dict properties:
properties to remove from the object
"""
headers = self._unset_properties(properties, 'X-Remove-Object-Meta-%s')
if headers:
self.create("%s/%s" % (container, object), headers=headers)
def object_show( def object_show(
self, self,
container=None, container=None,

View File

@ -23,6 +23,7 @@ from cliff import command
from cliff import lister from cliff import lister
from cliff import show from cliff import show
from openstackclient.common import parseractions
from openstackclient.common import utils from openstackclient.common import utils
@ -221,6 +222,42 @@ class SaveObject(command.Command):
) )
class SetObject(command.Command):
"""Set object properties"""
log = logging.getLogger(__name__ + '.SetObject')
def get_parser(self, prog_name):
parser = super(SetObject, self).get_parser(prog_name)
parser.add_argument(
'container',
metavar='<container>',
help='Modify <object> from <container>',
)
parser.add_argument(
'object',
metavar='<object>',
help='Object to modify',
)
parser.add_argument(
"--property",
metavar="<key=value>",
required=True,
action=parseractions.KeyValueAction,
help="Set a property on this object "
"(repeat option to set multiple properties)"
)
return parser
@utils.log_method(log)
def take_action(self, parsed_args):
self.app.client_manager.object_store.object_set(
parsed_args.container,
parsed_args.object,
properties=parsed_args.property,
)
class ShowObject(show.ShowOne): class ShowObject(show.ShowOne):
"""Display object details""" """Display object details"""
@ -249,3 +286,40 @@ class ShowObject(show.ShowOne):
) )
return zip(*sorted(six.iteritems(data))) return zip(*sorted(six.iteritems(data)))
class UnsetObject(command.Command):
"""Unset object properties"""
log = logging.getLogger(__name__ + '.UnsetObject')
def get_parser(self, prog_name):
parser = super(UnsetObject, self).get_parser(prog_name)
parser.add_argument(
'container',
metavar='<container>',
help='Modify <object> from <container>',
)
parser.add_argument(
'object',
metavar='<object>',
help='Object to modify',
)
parser.add_argument(
'--property',
metavar='<key>',
required=True,
action='append',
default=[],
help='Property to remove from object '
'(repeat option to remove multiple properties)',
)
return parser
@utils.log_method(log)
def take_action(self, parsed_args):
self.app.client_manager.object_store.object_unset(
parsed_args.container,
parsed_args.object,
properties=parsed_args.property,
)

View File

@ -346,7 +346,9 @@ openstack.object_store.v1 =
object_delete = openstackclient.object.v1.object:DeleteObject object_delete = openstackclient.object.v1.object:DeleteObject
object_list = openstackclient.object.v1.object:ListObject object_list = openstackclient.object.v1.object:ListObject
object_save = openstackclient.object.v1.object:SaveObject object_save = openstackclient.object.v1.object:SaveObject
object_set = openstackclient.object.v1.object:SetObject
object_show = openstackclient.object.v1.object:ShowObject object_show = openstackclient.object.v1.object:ShowObject
object_unset = openstackclient.object.v1.object:UnsetObject
openstack.volume.v1 = openstack.volume.v1 =
backup_create = openstackclient.volume.v1.backup:CreateBackup backup_create = openstackclient.volume.v1.backup:CreateBackup