Kaydet (Commit) e5edaf4e authored tarafından Leonid Mirsky's avatar Leonid Mirsky

Adding value verifications for mem_limit string representation

üst 019468da
...@@ -112,12 +112,26 @@ class Client(requests.Session): ...@@ -112,12 +112,26 @@ class Client(requests.Session):
] ]
if isinstance(mem_limit, six.string_types): if isinstance(mem_limit, six.string_types):
units = {'k': 1024, if len(mem_limit) == 0:
'm': 1024*1024, mem_limit = 0
'g': 1024*1024*1024} else:
suffix = mem_limit[-1].lower() units = {'k': 1024,
if suffix in units.keys(): 'm': 1024*1024,
mem_limit = int(mem_limit[:-1]) * units[suffix] '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): if isinstance(ports, list):
exposed_ports = {} exposed_ports = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment