From 9912fdd7ff037462d295e77ac58aadc3d7f8f972 Mon Sep 17 00:00:00 2001 From: zheng yin Date: Fri, 23 Sep 2016 19:42:40 +0800 Subject: [PATCH] Add default limit for container/object Default container name length less than or equal to 256 in link[1], as the same time,default object name length less than or equal to 1024 in link[2]. Thereforce, I check the length of container and object in take_action. and if it's greater than 256/1024 I warn the user. [1] https://github.com/openstack/swift/blob/master/swift/common/constraints.py#L39 [2] https://github.com/openstack/swift/blob/master/swift/common/constraints.py#L35 Change-Id: I304b77cbc464eaba041321654cc29248cbe4b9a6 --- openstackclient/object/v1/container.py | 11 +++++++++++ openstackclient/object/v1/object.py | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/openstackclient/object/v1/container.py b/openstackclient/object/v1/container.py index f00cc1509..2f0d4ac2e 100644 --- a/openstackclient/object/v1/container.py +++ b/openstackclient/object/v1/container.py @@ -15,11 +15,18 @@ """Container v1 action implementations""" +import logging + from osc_lib.cli import parseractions from osc_lib.command import command from osc_lib import utils import six +from openstackclient.i18n import _ + + +LOG = logging.getLogger(__name__) + class CreateContainer(command.Lister): """Create new container""" @@ -38,6 +45,10 @@ class CreateContainer(command.Lister): results = [] for container in parsed_args.containers: + if len(container) > 256: + LOG.warning( + _('Container name is %s characters long, the default limit' + ' is 256'), len(container)) data = self.app.client_manager.object_store.container_create( container=container, ) diff --git a/openstackclient/object/v1/object.py b/openstackclient/object/v1/object.py index 39dba3d5c..db61d638e 100644 --- a/openstackclient/object/v1/object.py +++ b/openstackclient/object/v1/object.py @@ -15,12 +15,18 @@ """Object v1 action implementations""" +import logging from osc_lib.cli import parseractions from osc_lib.command import command from osc_lib import utils import six +from openstackclient.i18n import _ + + +LOG = logging.getLogger(__name__) + class CreateObject(command.Lister): """Upload object to container""" @@ -44,6 +50,10 @@ class CreateObject(command.Lister): results = [] for obj in parsed_args.objects: + if len(obj) > 1024: + LOG.warning( + _('Object name is %s characters long, default limit' + ' is 1024'), len(obj)) data = self.app.client_manager.object_store.object_create( container=parsed_args.container, object=obj,