diff --git a/doc/source/command-objects/object.rst b/doc/source/command-objects/object.rst index 90bcfa1c91..a9c4049b42 100644 --- a/doc/source/command-objects/object.rst +++ b/doc/source/command-objects/object.rst @@ -119,6 +119,31 @@ Save object locally Object to save +object set +---------- + +Set object properties + +.. program:: object set +.. code:: bash + + os object set + + [] + [--property [...] ] + +.. describe:: + + Modify from + +.. describe:: + + Object to modify + +.. option:: --property + + Set a property on this object (repeat option to set multiple properties) + object show ----------- @@ -138,3 +163,28 @@ Display object details .. describe:: Object to display + +object unset +------------ + +Unset object properties + +.. program:: object unset +.. code:: bash + + os object unset + + [] + [--property ] + +.. describe:: + + Modify from + +.. describe:: + + Object to modify + +.. option:: --property + + Property to remove from object (repeat option to remove multiple properties) diff --git a/openstackclient/api/object_store_v1.py b/openstackclient/api/object_store_v1.py index b47f556b09..c870332aec 100644 --- a/openstackclient/api/object_store_v1.py +++ b/openstackclient/api/object_store_v1.py @@ -366,6 +366,46 @@ class APIv1(api.BaseAPI): for chunk in response.iter_content(): 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( self, container=None, diff --git a/openstackclient/object/v1/object.py b/openstackclient/object/v1/object.py index c90f031918..a023e3a00c 100644 --- a/openstackclient/object/v1/object.py +++ b/openstackclient/object/v1/object.py @@ -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 @@ -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='', + help='Modify from ', + ) + parser.add_argument( + 'object', + metavar='', + help='Object to modify', + ) + parser.add_argument( + "--property", + metavar="", + 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): """Display object details""" @@ -249,3 +286,40 @@ class ShowObject(show.ShowOne): ) 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='', + help='Modify from ', + ) + parser.add_argument( + 'object', + metavar='', + help='Object to modify', + ) + parser.add_argument( + '--property', + metavar='', + 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, + ) diff --git a/setup.cfg b/setup.cfg index 248c9c6604..7265eb883e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -346,7 +346,9 @@ openstack.object_store.v1 = object_delete = openstackclient.object.v1.object:DeleteObject object_list = openstackclient.object.v1.object:ListObject object_save = openstackclient.object.v1.object:SaveObject + object_set = openstackclient.object.v1.object:SetObject object_show = openstackclient.object.v1.object:ShowObject + object_unset = openstackclient.object.v1.object:UnsetObject openstack.volume.v1 = backup_create = openstackclient.volume.v1.backup:CreateBackup