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
01a754a7
Kaydet (Commit)
01a754a7
authored
Ock 20, 2016
tarafından
Aanand Prasad
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Support links when creating containers or connecting to networks
Signed-off-by:
Aanand Prasad
<
aanand.prasad@gmail.com
>
üst
656e6cff
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
85 additions
and
10 deletions
+85
-10
network.py
docker/api/network.py
+4
-2
__init__.py
docker/utils/__init__.py
+1
-1
utils.py
docker/utils/utils.py
+14
-7
helpers.py
tests/helpers.py
+15
-0
network_test.py
tests/integration/network_test.py
+49
-0
network_test.py
tests/unit/network_test.py
+2
-0
No files found.
docker/api/network.py
Dosyayı görüntüle @
01a754a7
import
json
from
..utils
import
check_resource
,
minimum_version
from
..utils
import
check_resource
,
minimum_version
,
normalize_links
class
NetworkApiMixin
(
object
):
...
...
@@ -47,11 +47,13 @@ class NetworkApiMixin(object):
@check_resource
@minimum_version
(
'1.21'
)
def
connect_container_to_network
(
self
,
container
,
net_id
,
aliases
=
None
):
def
connect_container_to_network
(
self
,
container
,
net_id
,
aliases
=
None
,
links
=
None
):
data
=
{
"Container"
:
container
,
"EndpointConfig"
:
{
"Aliases"
:
aliases
,
"Links"
:
normalize_links
(
links
)
if
links
else
None
,
},
}
url
=
self
.
_url
(
"/networks/{0}/connect"
,
net_id
)
...
...
docker/utils/__init__.py
Dosyayı görüntüle @
01a754a7
...
...
@@ -4,7 +4,7 @@ from .utils import (
kwargs_from_env
,
convert_filters
,
datetime_to_timestamp
,
create_host_config
,
create_container_config
,
parse_bytes
,
ping_registry
,
parse_env_file
,
version_lt
,
version_gte
,
decode_json_header
,
split_command
,
create_ipam_config
,
create_ipam_pool
,
parse_devices
create_ipam_config
,
create_ipam_pool
,
parse_devices
,
normalize_links
,
)
# flake8: noqa
from
.types
import
Ulimit
,
LogConfig
# flake8: noqa
...
...
docker/utils/utils.py
Dosyayı görüntüle @
01a754a7
...
...
@@ -674,12 +674,7 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
host_config
[
'ExtraHosts'
]
=
extra_hosts
if
links
is
not
None
:
if
isinstance
(
links
,
dict
):
links
=
six
.
iteritems
(
links
)
formatted_links
=
[
'{0}:{1}'
.
format
(
k
,
v
)
for
k
,
v
in
sorted
(
links
)]
host_config
[
'Links'
]
=
formatted_links
host_config
[
'Links'
]
=
normalize_links
(
links
)
if
isinstance
(
lxc_conf
,
dict
):
formatted
=
[]
...
...
@@ -731,6 +726,13 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
return
host_config
def
normalize_links
(
links
):
if
isinstance
(
links
,
dict
):
links
=
six
.
iteritems
(
links
)
return
[
'{0}:{1}'
.
format
(
k
,
v
)
for
k
,
v
in
sorted
(
links
)]
def
create_networking_config
(
endpoints_config
=
None
):
networking_config
=
{}
...
...
@@ -740,7 +742,7 @@ def create_networking_config(endpoints_config=None):
return
networking_config
def
create_endpoint_config
(
version
,
aliases
=
None
):
def
create_endpoint_config
(
version
,
aliases
=
None
,
links
=
None
):
endpoint_config
=
{}
if
aliases
:
...
...
@@ -748,6 +750,11 @@ def create_endpoint_config(version, aliases=None):
raise
host_config_version_error
(
'endpoint_config.aliases'
,
'1.22'
)
endpoint_config
[
"Aliases"
]
=
aliases
if
links
:
if
version_lt
(
version
,
'1.22'
):
raise
host_config_version_error
(
'endpoint_config.links'
,
'1.22'
)
endpoint_config
[
"Links"
]
=
normalize_links
(
links
)
return
endpoint_config
...
...
tests/helpers.py
Dosyayı görüntüle @
01a754a7
...
...
@@ -168,3 +168,18 @@ class BaseTestCase(unittest.TestCase):
.
format
(
exitcode
,
output
))
return
container
def
create_and_start
(
self
,
image
=
'busybox'
,
command
=
'top'
,
**
kwargs
):
container
=
self
.
client
.
create_container
(
image
=
image
,
command
=
command
,
**
kwargs
)
self
.
tmp_containers
.
append
(
container
)
self
.
client
.
start
(
container
)
return
container
def
execute
(
self
,
container
,
cmd
,
exit_code
=
0
,
**
kwargs
):
exc
=
self
.
client
.
exec_create
(
container
,
cmd
,
**
kwargs
)
output
=
self
.
client
.
exec_start
(
exc
)
actual_exit_code
=
self
.
client
.
exec_inspect
(
exc
)[
'ExitCode'
]
msg
=
"Expected `{}` to exit with code {} but returned {}:
\n
{}"
.
format
(
" "
.
join
(
cmd
),
exit_code
,
actual_exit_code
,
output
)
assert
actual_exit_code
==
exit_code
,
msg
tests/integration/network_test.py
Dosyayı görüntüle @
01a754a7
...
...
@@ -180,3 +180,52 @@ class TestNetworks(helpers.BaseTestCase):
self
.
assertEqual
(
container_data
[
'NetworkSettings'
][
'Networks'
][
net_name
][
'Aliases'
],
[
'foo'
,
'bar'
])
@requires_api_version
(
'1.22'
)
def
test_create_with_links
(
self
):
net_name
,
net_id
=
self
.
create_network
()
container
=
self
.
create_and_start
(
host_config
=
self
.
client
.
create_host_config
(
network_mode
=
net_name
),
networking_config
=
self
.
client
.
create_networking_config
({
net_name
:
self
.
client
.
create_endpoint_config
(
links
=
[(
'docker-py-test-upstream'
,
'bar'
)],
),
}),
)
container_data
=
self
.
client
.
inspect_container
(
container
)
self
.
assertEqual
(
container_data
[
'NetworkSettings'
][
'Networks'
][
net_name
][
'Links'
],
[
'docker-py-test-upstream:bar'
])
self
.
create_and_start
(
name
=
'docker-py-test-upstream'
,
host_config
=
self
.
client
.
create_host_config
(
network_mode
=
net_name
),
)
self
.
execute
(
container
,
[
'nslookup'
,
'bar'
])
@requires_api_version
(
'1.22'
)
def
test_connect_with_links
(
self
):
net_name
,
net_id
=
self
.
create_network
()
container
=
self
.
create_and_start
(
host_config
=
self
.
client
.
create_host_config
(
network_mode
=
net_name
))
self
.
client
.
disconnect_container_from_network
(
container
,
net_name
)
self
.
client
.
connect_container_to_network
(
container
,
net_name
,
links
=
[(
'docker-py-test-upstream'
,
'bar'
)])
container_data
=
self
.
client
.
inspect_container
(
container
)
self
.
assertEqual
(
container_data
[
'NetworkSettings'
][
'Networks'
][
net_name
][
'Links'
],
[
'docker-py-test-upstream:bar'
])
self
.
create_and_start
(
name
=
'docker-py-test-upstream'
,
host_config
=
self
.
client
.
create_host_config
(
network_mode
=
net_name
),
)
self
.
execute
(
container
,
[
'nslookup'
,
'bar'
])
tests/unit/network_test.py
Dosyayı görüntüle @
01a754a7
...
...
@@ -150,6 +150,7 @@ class NetworkTest(DockerClientTest):
{
'Id'
:
container_id
},
network_id
,
aliases
=
[
'foo'
,
'bar'
],
links
=
[(
'baz'
,
'quux'
)]
)
self
.
assertEqual
(
...
...
@@ -162,6 +163,7 @@ class NetworkTest(DockerClientTest):
'Container'
:
container_id
,
'EndpointConfig'
:
{
'Aliases'
:
[
'foo'
,
'bar'
],
'Links'
:
[
'baz:quux'
],
},
})
...
...
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