summaryrefslogtreecommitdiff
path: root/docker
diff options
context:
space:
mode:
authorLeonid Mirsky <leonidlm@gmail.com>2014-08-05 15:36:06 +0300
committerLeonid Mirsky <leonidlm@gmail.com>2014-08-05 15:36:06 +0300
commite5edaf4e0b1b3753b7b4b9debdff12759fc71318 (patch)
tree43340d721e543e1f2a19184211ba2f908607ce0a /docker
parent019468dad8330f183e06a9d030701b3906bfc73e (diff)
downloaddocker-py-e5edaf4e0b1b3753b7b4b9debdff12759fc71318.tar.gz
Adding value verifications for mem_limit string representation
Diffstat (limited to 'docker')
-rw-r--r--docker/client.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/docker/client.py b/docker/client.py
index 22aedf5..2844cb5 100644
--- a/docker/client.py
+++ b/docker/client.py
@@ -112,12 +112,26 @@ class Client(requests.Session):
]
if isinstance(mem_limit, six.string_types):
- units = {'k': 1024,
- 'm': 1024*1024,
- 'g': 1024*1024*1024}
- suffix = mem_limit[-1].lower()
- if suffix in units.keys():
- mem_limit = int(mem_limit[:-1]) * units[suffix]
+ if len(mem_limit) == 0:
+ mem_limit = 0
+ else:
+ units = {'k': 1024,
+ 'm': 1024*1024,
+ 'g': 1024*1024*1024}
+ suffix = mem_limit[-1].lower()
+
+ if suffix in units.keys():
+ try:
+ digits = int(mem_limit[:-1])
+ except ValueError:
+ message = ('Failed converting the string value for mem_limit ({0}) to a number.')
+ raise errors.DockerException(message.format(mem_limit[:-1]))
+
+ mem_limit = digits * units[suffix]
+ else:
+ message = ('The specified value for mem_limit parameter ({0}) should specify'
+ ' the units. The postfix should be one of the `k` `m` `g` characters' )
+ raise errors.DockerException(message.format(mem_limit))
if isinstance(ports, list):
exposed_ports = {}