mirror of https://github.com/docker/docker-py.git
Merge pull request #562 from smothiki/mems
make memory units compatible with native docker cli
This commit is contained in:
commit
7b2fd8cf5e
|
@ -322,6 +322,9 @@ def parse_bytes(s):
|
||||||
if len(s) == 0:
|
if len(s) == 0:
|
||||||
s = 0
|
s = 0
|
||||||
else:
|
else:
|
||||||
|
if s[-2:-1].isalpha() and s[-1].isalpha():
|
||||||
|
if (s[-1] == "b" or s[-1] == "B"):
|
||||||
|
s = s[:-1]
|
||||||
units = BYTE_UNITS
|
units = BYTE_UNITS
|
||||||
suffix = s[-1].lower()
|
suffix = s[-1].lower()
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ from docker.client import Client
|
||||||
from docker.errors import DockerException
|
from docker.errors import DockerException
|
||||||
from docker.utils import (
|
from docker.utils import (
|
||||||
parse_repository_tag, parse_host, convert_filters, kwargs_from_env,
|
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.utils.ports import build_port_bindings, split_port
|
||||||
from docker.auth import resolve_authconfig
|
from docker.auth import resolve_authconfig
|
||||||
|
@ -37,6 +37,12 @@ class UtilsTest(base.BaseTestCase):
|
||||||
self.assertEqual(parse_repository_tag("url:5000/repo:tag"),
|
self.assertEqual(parse_repository_tag("url:5000/repo: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):
|
def test_parse_host(self):
|
||||||
invalid_hosts = [
|
invalid_hosts = [
|
||||||
'0.0.0.0',
|
'0.0.0.0',
|
||||||
|
|
Loading…
Reference in New Issue