diff options
author | smothiki <sivaram.mothiki@gmail.com> | 2015-04-24 13:45:20 -0600 |
---|---|---|
committer | smothiki <smothiki@engineyard.com> | 2015-05-07 20:05:32 -0600 |
commit | ef452ed4c1161a0b71369be7c86e450fd41b52f8 (patch) | |
tree | f5a524bb0107eb8466400ca683cffe0cac790314 | |
parent | f28e90bfabb0f671743133210cb16a5cdd3c2a9c (diff) | |
download | docker-py-ef452ed4c1161a0b71369be7c86e450fd41b52f8.tar.gz |
make memory units compatible with native docker cli
Signed-off-by: sivaram mothiki <smothiki@engineyard.com>
-rw-r--r-- | docker/utils/utils.py | 3 | ||||
-rw-r--r-- | tests/utils_test.py | 8 |
2 files changed, 10 insertions, 1 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py index a18939d..96b3e76 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -322,6 +322,9 @@ def parse_bytes(s): if len(s) == 0: s = 0 else: + if s[-2:-1].isalpha() and s[-1].isalpha(): + if (s[-1] == "b" or s[-1] == "B"): + s = s[:-1] units = BYTE_UNITS suffix = s[-1].lower() diff --git a/tests/utils_test.py b/tests/utils_test.py index 454a14e..716cde5 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -6,7 +6,7 @@ from docker.client import Client from docker.errors import DockerException from docker.utils import ( parse_repository_tag, parse_host, convert_filters, kwargs_from_env, - create_host_config, Ulimit, LogConfig + create_host_config, Ulimit, LogConfig, parse_bytes ) from docker.utils.ports import build_port_bindings, split_port from docker.auth import resolve_authconfig @@ -37,6 +37,12 @@ class UtilsTest(base.BaseTestCase): self.assertEqual(parse_repository_tag("url:5000/repo:tag"), ("url:5000/repo", "tag")) + def test_parse_bytes(self): + self.assertEqual(parse_bytes("512MB"), (536870912)) + self.assertEqual(parse_bytes("512M"), (536870912)) + self.assertRaises(DockerException, parse_bytes, "512MK") + self.assertRaises(DockerException, parse_bytes, "512L") + def test_parse_host(self): invalid_hosts = [ '0.0.0.0', |