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
2218dbaa
Kaydet (Commit)
2218dbaa
authored
Ara 19, 2014
tarafından
Joffrey F
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Use create_host_config in start (unifying parameter processing)
üst
53d61a77
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
81 deletions
+27
-81
client.py
docker/client.py
+11
-72
utils.py
docker/utils/utils.py
+10
-7
test.py
tests/test.py
+0
-1
utils_test.py
tests/utils_test.py
+6
-1
No files found.
docker/client.py
Dosyayı görüntüle @
2218dbaa
...
...
@@ -911,63 +911,7 @@ class Client(requests.Session):
restart_policy
=
None
,
cap_add
=
None
,
cap_drop
=
None
,
devices
=
None
,
extra_hosts
=
None
):
start_config
=
{}
if
isinstance
(
container
,
dict
):
container
=
container
.
get
(
'Id'
)
if
isinstance
(
lxc_conf
,
dict
):
formatted
=
[]
for
k
,
v
in
six
.
iteritems
(
lxc_conf
):
formatted
.
append
({
'Key'
:
k
,
'Value'
:
str
(
v
)})
lxc_conf
=
formatted
if
lxc_conf
:
start_config
[
'LxcConf'
]
=
lxc_conf
if
binds
:
start_config
[
'Binds'
]
=
utils
.
convert_volume_binds
(
binds
)
if
port_bindings
:
start_config
[
'PortBindings'
]
=
utils
.
convert_port_bindings
(
port_bindings
)
if
publish_all_ports
:
start_config
[
'PublishAllPorts'
]
=
publish_all_ports
if
links
:
if
isinstance
(
links
,
dict
):
links
=
six
.
iteritems
(
links
)
formatted_links
=
[
'{0}:{1}'
.
format
(
k
,
v
)
for
k
,
v
in
sorted
(
links
)
]
start_config
[
'Links'
]
=
formatted_links
if
extra_hosts
:
if
isinstance
(
extra_hosts
,
dict
):
extra_hosts
=
six
.
iteritems
(
extra_hosts
)
formatted_extra_hosts
=
[
'{0}:{1}'
.
format
(
k
,
v
)
for
k
,
v
in
sorted
(
extra_hosts
)
]
start_config
[
'ExtraHosts'
]
=
formatted_extra_hosts
if
privileged
:
start_config
[
'Privileged'
]
=
privileged
if
utils
.
compare_version
(
'1.10'
,
self
.
_version
)
>=
0
:
if
dns
is
not
None
:
start_config
[
'Dns'
]
=
dns
if
volumes_from
is
not
None
:
if
isinstance
(
volumes_from
,
six
.
string_types
):
volumes_from
=
volumes_from
.
split
(
','
)
start_config
[
'VolumesFrom'
]
=
volumes_from
else
:
if
utils
.
compare_version
(
'1.10'
,
self
.
_version
)
<
0
:
if
dns
is
not
None
:
raise
errors
.
APIError
(
'dns is only supported for API version >= 1.10'
...
...
@@ -976,23 +920,18 @@ class Client(requests.Session):
raise
errors
.
APIError
(
'volumes_from is only supported for API version >= 1.10'
)
if
dns_search
:
start_config
[
'DnsSearch'
]
=
dns_search
if
network_mode
:
start_config
[
'NetworkMode'
]
=
network_mode
if
restart_policy
:
start_config
[
'RestartPolicy'
]
=
restart_policy
if
cap_add
:
start_config
[
'CapAdd'
]
=
cap_add
if
cap_drop
:
start_config
[
'CapDrop'
]
=
cap_drop
start_config
=
utils
.
create_host_config
(
binds
=
binds
,
port_bindings
=
port_bindings
,
lxc_conf
=
lxc_conf
,
publish_all_ports
=
publish_all_ports
,
links
=
links
,
dns
=
dns
,
privileged
=
privileged
,
dns_search
=
dns_search
,
cap_add
=
cap_add
,
cap_drop
=
cap_drop
,
volumes_from
=
volumes_from
,
devices
=
devices
,
network_mode
=
network_mode
,
restart_policy
=
restart_policy
,
extra_hosts
=
extra_hosts
)
if
devices
:
start_config
[
'Devices'
]
=
utils
.
parse_devices
(
devices
)
if
isinstance
(
container
,
dict
)
:
container
=
container
.
get
(
'Id'
)
url
=
self
.
_url
(
"/containers/{0}/start"
.
format
(
container
))
if
not
start_config
:
...
...
docker/utils/utils.py
Dosyayı görüntüle @
2218dbaa
...
...
@@ -303,10 +303,13 @@ def create_host_config(
restart_policy
=
None
,
cap_add
=
None
,
cap_drop
=
None
,
devices
=
None
,
extra_hosts
=
None
):
host_config
=
{
'Privileged'
:
privileged
,
'PublishAllPorts'
:
publish_all_ports
,
}
host_config
=
{}
if
privileged
:
host_config
[
'Privileged'
]
=
privileged
if
publish_all_ports
:
host_config
[
'PublishAllPorts'
]
=
publish_all_ports
if
dns_search
:
host_config
[
'DnsSearch'
]
=
dns_search
...
...
@@ -351,8 +354,6 @@ def create_host_config(
host_config
[
'ExtraHosts'
]
=
extra_hosts
host_config
[
'PublishAllPorts'
]
=
publish_all_ports
if
links
:
if
isinstance
(
links
,
dict
):
links
=
six
.
iteritems
(
links
)
...
...
@@ -368,6 +369,8 @@ def create_host_config(
for
k
,
v
in
six
.
iteritems
(
lxc_conf
):
formatted
.
append
({
'Key'
:
k
,
'Value'
:
str
(
v
)})
lxc_conf
=
formatted
host_config
[
'LxcConf'
]
=
lxc_conf
if
lxc_conf
:
host_config
[
'LxcConf'
]
=
lxc_conf
return
host_config
tests/test.py
Dosyayı görüntüle @
2218dbaa
...
...
@@ -733,7 +733,6 @@ class DockerClientTest(Cleanup, unittest.TestCase):
args
=
fake_request
.
call_args
self
.
assertEqual
(
args
[
0
][
0
],
url_prefix
+
'containers/create'
)
data
=
json
.
loads
(
args
[
1
][
'data'
])
self
.
assertEqual
(
data
[
'HostConfig'
][
'PublishAllPorts'
],
False
)
port_bindings
=
data
[
'HostConfig'
][
'PortBindings'
]
self
.
assertTrue
(
'1111/tcp'
in
port_bindings
)
self
.
assertTrue
(
'2222/tcp'
in
port_bindings
)
...
...
tests/utils_test.py
Dosyayı görüntüle @
2218dbaa
...
...
@@ -5,7 +5,8 @@ import unittest
from
docker.client
import
Client
from
docker.errors
import
DockerException
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
)
...
...
@@ -95,6 +96,10 @@ class UtilsTest(unittest.TestCase):
for
filters
,
expected
in
tests
:
self
.
assertEqual
(
convert_filters
(
filters
),
expected
)
def
test_create_host_config
(
self
):
empty_config
=
create_host_config
()
self
.
assertEqual
(
empty_config
,
{})
if
__name__
==
'__main__'
:
unittest
.
main
()
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