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
This commit is contained in:
Rajasi Kulkarni
2016-08-22 00:26:46 +05:30
committed by Steve Martinelli
parent f19240fc29
commit 78312ca9af
6 changed files with 56 additions and 3 deletions

View File

@@ -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'),
}