Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
docker-py
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
docker-py
Commits
7440603d
Kaydet (Commit)
7440603d
authored
Şub 01, 2016
tarafından
Joffrey F
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Improve parse_bytes util method
Signed-off-by:
Joffrey F
<
joffrey@docker.com
>
üst
03279ff9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
40 deletions
+36
-40
utils.py
docker/utils/utils.py
+35
-39
container_test.py
tests/integration/container_test.py
+1
-1
No files found.
docker/utils/utils.py
Dosyayı görüntüle @
7440603d
...
@@ -518,41 +518,43 @@ def longint(n):
...
@@ -518,41 +518,43 @@ def longint(n):
def
parse_bytes
(
s
):
def
parse_bytes
(
s
):
if
isinstance
(
s
,
six
.
integer_types
+
(
float
,)):
return
s
if
len
(
s
)
==
0
:
if
len
(
s
)
==
0
:
s
=
0
return
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
()
# Check if the variable is a string representation of an int
# without a units part. Assuming that the units are bytes.
if
suffix
.
isdigit
():
digits_part
=
s
suffix
=
'b'
else
:
digits_part
=
s
[:
-
1
]
if
suffix
in
units
.
keys
()
or
suffix
.
isdigit
():
if
s
[
-
2
:
-
1
]
.
isalpha
()
and
s
[
-
1
]
.
isalpha
():
try
:
if
s
[
-
1
]
==
"b"
or
s
[
-
1
]
==
"B"
:
digits
=
longint
(
digits_part
)
s
=
s
[:
-
1
]
except
ValueError
:
units
=
BYTE_UNITS
raise
errors
.
DockerException
(
suffix
=
s
[
-
1
]
.
lower
()
'Failed converting the string value for memory ({0}) to'
' an integer.'
.
format
(
digits_part
)
# Check if the variable is a string representation of an int
)
# without a units part. Assuming that the units are bytes.
if
suffix
.
isdigit
():
digits_part
=
s
suffix
=
'b'
else
:
digits_part
=
s
[:
-
1
]
# Reconvert to long for the final result
if
suffix
in
units
.
keys
()
or
suffix
.
isdigit
():
s
=
longint
(
digits
*
units
[
suffix
])
try
:
else
:
digits
=
longint
(
digits_part
)
except
ValueError
:
raise
errors
.
DockerException
(
raise
errors
.
DockerException
(
'The specified value for memory ({0}) should specify the'
'Failed converting the string value for memory ({0}) to'
' units. The postfix should be one of the `b` `k` `m` `g`'
' an integer.'
.
format
(
digits_part
)
' characters'
.
format
(
s
)
)
)
# Reconvert to long for the final result
s
=
longint
(
digits
*
units
[
suffix
])
else
:
raise
errors
.
DockerException
(
'The specified value for memory ({0}) should specify the'
' units. The postfix should be one of the `b` `k` `m` `g`'
' characters'
.
format
(
s
)
)
return
s
return
s
...
@@ -594,16 +596,10 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
...
@@ -594,16 +596,10 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
version
=
constants
.
DEFAULT_DOCKER_API_VERSION
version
=
constants
.
DEFAULT_DOCKER_API_VERSION
if
mem_limit
is
not
None
:
if
mem_limit
is
not
None
:
if
isinstance
(
mem_limit
,
six
.
string_types
):
host_config
[
'Memory'
]
=
parse_bytes
(
mem_limit
)
mem_limit
=
parse_bytes
(
mem_limit
)
host_config
[
'Memory'
]
=
mem_limit
if
memswap_limit
is
not
None
:
if
memswap_limit
is
not
None
:
if
isinstance
(
memswap_limit
,
six
.
string_types
):
host_config
[
'MemorySwap'
]
=
parse_bytes
(
memswap_limit
)
memswap_limit
=
parse_bytes
(
memswap_limit
)
host_config
[
'MemorySwap'
]
=
memswap_limit
if
mem_swappiness
is
not
None
:
if
mem_swappiness
is
not
None
:
if
version_lt
(
version
,
'1.20'
):
if
version_lt
(
version
,
'1.20'
):
...
@@ -873,9 +869,9 @@ def create_container_config(
...
@@ -873,9 +869,9 @@ def create_container_config(
if
isinstance
(
labels
,
list
):
if
isinstance
(
labels
,
list
):
labels
=
dict
((
lbl
,
six
.
text_type
(
''
))
for
lbl
in
labels
)
labels
=
dict
((
lbl
,
six
.
text_type
(
''
))
for
lbl
in
labels
)
if
isinstance
(
mem_limit
,
six
.
string_types
)
:
if
mem_limit
is
not
None
:
mem_limit
=
parse_bytes
(
mem_limit
)
mem_limit
=
parse_bytes
(
mem_limit
)
if
isinstance
(
memswap_limit
,
six
.
string_types
)
:
if
memswap_limit
is
not
None
:
memswap_limit
=
parse_bytes
(
memswap_limit
)
memswap_limit
=
parse_bytes
(
memswap_limit
)
if
isinstance
(
ports
,
list
):
if
isinstance
(
ports
,
list
):
...
...
tests/integration/container_test.py
Dosyayı görüntüle @
7440603d
...
@@ -1045,7 +1045,7 @@ class ContainerUpdateTest(helpers.BaseTestCase):
...
@@ -1045,7 +1045,7 @@ class ContainerUpdateTest(helpers.BaseTestCase):
)
)
self
.
tmp_containers
.
append
(
container
)
self
.
tmp_containers
.
append
(
container
)
self
.
client
.
start
(
container
)
self
.
client
.
start
(
container
)
print
(
self
.
client
.
update_container
(
container
,
mem_limit
=
new_mem_limit
)
)
self
.
client
.
update_container
(
container
,
mem_limit
=
new_mem_limit
)
inspect_data
=
self
.
client
.
inspect_container
(
container
)
inspect_data
=
self
.
client
.
inspect_container
(
container
)
self
.
assertEqual
(
inspect_data
[
'HostConfig'
][
'Memory'
],
new_mem_limit
)
self
.
assertEqual
(
inspect_data
[
'HostConfig'
][
'Memory'
],
new_mem_limit
)
self
.
assertEqual
(
inspect_data
[
'HostConfig'
][
'CpuShares'
],
102
)
self
.
assertEqual
(
inspect_data
[
'HostConfig'
][
'CpuShares'
],
102
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment