summaryrefslogtreecommitdiff
path: root/openstackclient/api
diff options
context:
space:
mode:
authorRajasi Kulkarni <rajasikulkarni18@gmail.com>2016-08-22 00:26:46 +0530
committerSteve Martinelli <s.martinelli@gmail.com>2016-09-26 22:42:10 -0400
commit78312ca9afea22f6511f2421dccb0736f394e9c8 (patch)
treea642188484c98b61a01ec6483d80b14dc4b519dd /openstackclient/api
parentf19240fc29c542726acd11a7f71f307be219695f (diff)
downloadpython-openstackclient-78312ca9afea22f6511f2421dccb0736f394e9c8.tar.gz
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
Diffstat (limited to 'openstackclient/api')
-rw-r--r--openstackclient/api/object_store_v1.py11
1 files changed, 9 insertions, 2 deletions
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'),
}