From 78312ca9afea22f6511f2421dccb0736f394e9c8 Mon Sep 17 00:00:00 2001 From: Rajasi Kulkarni Date: Mon, 22 Aug 2016 00:26:46 +0530 Subject: Add option "--name" to command "openstack object create" Option "--name" can be used to set as the object name of the file to be uploaded in the container. Similar to option "--object-name" in command "swift upload". Added unit test case to ensure an exception is raised when using option "--name" for uploading multiple objects. Change-Id: Ied7827841f6ca1cf9d4b48e304cbe5d62eda38ab Closes-Bug: #1607972 --- openstackclient/api/object_store_v1.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'openstackclient/api') diff --git a/openstackclient/api/object_store_v1.py b/openstackclient/api/object_store_v1.py index faa55118..184814c6 100644 --- a/openstackclient/api/object_store_v1.py +++ b/openstackclient/api/object_store_v1.py @@ -214,6 +214,7 @@ class APIv1(api.BaseAPI): self, container=None, object=None, + name=None, ): """Create an object inside a container @@ -221,6 +222,8 @@ class APIv1(api.BaseAPI): name of container to store object :param string object: local path to object + :param string name: + name of object to create :returns: dict of returned headers """ @@ -229,8 +232,12 @@ class APIv1(api.BaseAPI): # TODO(dtroyer): What exception to raise here? return {} + # For uploading a file, if name is provided then set it as the + # object's name in the container. + object_name_str = name if name else object + full_url = "%s/%s" % (urllib.parse.quote(container), - urllib.parse.quote(object)) + urllib.parse.quote(object_name_str)) with io.open(object, 'rb') as f: response = self.create( full_url, @@ -240,7 +247,7 @@ class APIv1(api.BaseAPI): data = { 'account': self._find_account_id(), 'container': container, - 'object': object, + 'object': object_name_str, 'x-trans-id': response.headers.get('X-Trans-Id'), 'etag': response.headers.get('Etag'), } -- cgit v1.2.1