Skip to content

Commit 9912fdd

Browse files
author
zheng yin
committed
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
1 parent 465a5d0 commit 9912fdd

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

openstackclient/object/v1/container.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@
1515

1616
"""Container v1 action implementations"""
1717

18+
import logging
19+
1820
from osc_lib.cli import parseractions
1921
from osc_lib.command import command
2022
from osc_lib import utils
2123
import six
2224

25+
from openstackclient.i18n import _
26+
27+
28+
LOG = logging.getLogger(__name__)
29+
2330

2431
class CreateContainer(command.Lister):
2532
"""Create new container"""
@@ -38,6 +45,10 @@ def take_action(self, parsed_args):
3845

3946
results = []
4047
for container in parsed_args.containers:
48+
if len(container) > 256:
49+
LOG.warning(
50+
_('Container name is %s characters long, the default limit'
51+
' is 256'), len(container))
4152
data = self.app.client_manager.object_store.container_create(
4253
container=container,
4354
)

openstackclient/object/v1/object.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@
1515

1616
"""Object v1 action implementations"""
1717

18+
import logging
1819

1920
from osc_lib.cli import parseractions
2021
from osc_lib.command import command
2122
from osc_lib import utils
2223
import six
2324

25+
from openstackclient.i18n import _
26+
27+
28+
LOG = logging.getLogger(__name__)
29+
2430

2531
class CreateObject(command.Lister):
2632
"""Upload object to container"""
@@ -44,6 +50,10 @@ def take_action(self, parsed_args):
4450

4551
results = []
4652
for obj in parsed_args.objects:
53+
if len(obj) > 1024:
54+
LOG.warning(
55+
_('Object name is %s characters long, default limit'
56+
' is 1024'), len(obj))
4757
data = self.app.client_manager.object_store.object_create(
4858
container=parsed_args.container,
4959
object=obj,

0 commit comments

Comments
 (0)