summaryrefslogtreecommitdiff
path: root/openstackclient/object
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/object
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/object')
-rw-r--r--openstackclient/object/v1/object.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/openstackclient/object/v1/object.py b/openstackclient/object/v1/object.py
index db61d638..88f6815e 100644
--- a/openstackclient/object/v1/object.py
+++ b/openstackclient/object/v1/object.py
@@ -19,6 +19,7 @@ import logging
from osc_lib.cli import parseractions
from osc_lib.command import command
+from osc_lib import exceptions
from osc_lib import utils
import six
@@ -44,10 +45,20 @@ class CreateObject(command.Lister):
nargs="+",
help='Local filename(s) to upload',
)
+ parser.add_argument(
+ '--name',
+ metavar='<name>',
+ help='Upload a file and rename it. '
+ 'Can only be used when uploading a single object'
+ )
return parser
def take_action(self, parsed_args):
-
+ if parsed_args.name:
+ if len(parsed_args.objects) > 1:
+ msg = _('Attempting to upload multiple objects and '
+ 'using --name is not permitted')
+ raise exceptions.CommandError(msg)
results = []
for obj in parsed_args.objects:
if len(obj) > 1024:
@@ -57,6 +68,7 @@ class CreateObject(command.Lister):
data = self.app.client_manager.object_store.object_create(
container=parsed_args.container,
object=obj,
+ name=parsed_args.name,
)
results.append(data)