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
d9a149f3
Kaydet (Commit)
d9a149f3
authored
Agu 25, 2015
tarafından
Aanand Prasad
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pull request #732 from docker/version-dependent-hostconfig
Version dependent hostconfig
üst
4d2c15fa
75e3b8bb
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
15 deletions
+46
-15
client.py
docker/client.py
+12
-3
utils.py
docker/utils/utils.py
+10
-2
api.md
docs/api.md
+1
-1
hostconfig.md
docs/hostconfig.md
+4
-3
test.py
tests/test.py
+0
-0
utils_test.py
tests/utils_test.py
+19
-6
No files found.
docker/client.py
Dosyayı görüntüle @
d9a149f3
...
...
@@ -248,8 +248,8 @@ class Client(clientbase.ClientBase):
'host_config is not supported in API < 1.15'
)
config
=
utils
.
create_container_config
(
self
.
_version
,
image
,
command
,
hostname
,
user
,
detach
,
stdin_open
,
config
=
self
.
create_container_config
(
image
,
command
,
hostname
,
user
,
detach
,
stdin_open
,
tty
,
mem_limit
,
ports
,
environment
,
dns
,
volumes
,
volumes_from
,
network_disabled
,
entrypoint
,
cpu_shares
,
working_dir
,
domainname
,
memswap_limit
,
cpuset
,
host_config
,
mac_address
,
labels
,
...
...
@@ -257,6 +257,9 @@ class Client(clientbase.ClientBase):
)
return
self
.
create_container_from_config
(
config
,
name
)
def
create_container_config
(
self
,
*
args
,
**
kwargs
):
return
utils
.
create_container_config
(
self
.
_version
,
*
args
,
**
kwargs
)
def
create_container_from_config
(
self
,
config
,
name
=
None
):
u
=
self
.
_url
(
"/containers/create"
)
params
=
{
...
...
@@ -265,6 +268,12 @@ class Client(clientbase.ClientBase):
res
=
self
.
_post_json
(
u
,
data
=
config
,
params
=
params
)
return
self
.
_result
(
res
,
True
)
def
create_host_config
(
self
,
*
args
,
**
kwargs
):
if
not
kwargs
:
kwargs
=
{}
kwargs
[
'version'
]
=
self
.
_version
return
utils
.
create_host_config
(
*
args
,
**
kwargs
)
@check_resource
def
diff
(
self
,
container
):
return
self
.
_result
(
self
.
_get
(
self
.
_url
(
"/containers/{0}/changes"
.
...
...
@@ -815,7 +824,7 @@ class Client(clientbase.ClientBase):
'Please use host_config in create_container instead!'
,
DeprecationWarning
)
start_config
=
utils
.
create_host_config
(
**
start_config_kwargs
)
start_config
=
self
.
create_host_config
(
**
start_config_kwargs
)
url
=
self
.
_url
(
"/containers/{0}/start"
.
format
(
container
))
res
=
self
.
_post_json
(
url
,
data
=
start_config
)
...
...
docker/utils/utils.py
Dosyayı görüntüle @
d9a149f3
...
...
@@ -27,6 +27,7 @@ from datetime import datetime
import
requests
import
six
from
..
import
constants
from
..
import
errors
from
..
import
tls
from
.types
import
Ulimit
,
LogConfig
...
...
@@ -395,10 +396,17 @@ def create_host_config(
restart_policy
=
None
,
cap_add
=
None
,
cap_drop
=
None
,
devices
=
None
,
extra_hosts
=
None
,
read_only
=
None
,
pid_mode
=
None
,
ipc_mode
=
None
,
security_opt
=
None
,
ulimits
=
None
,
log_config
=
None
,
mem_limit
=
None
,
memswap_limit
=
None
,
cgroup_parent
=
None
memswap_limit
=
None
,
cgroup_parent
=
None
,
version
=
None
):
host_config
=
{}
if
not
version
:
warnings
.
warn
(
'docker.utils.create_host_config() is deprecated. Please use '
'Client.create_host_config() instead.'
)
version
=
constants
.
DEFAULT_DOCKER_API_VERSION
if
mem_limit
is
not
None
:
if
isinstance
(
mem_limit
,
six
.
string_types
):
mem_limit
=
parse_bytes
(
mem_limit
)
...
...
@@ -433,7 +441,7 @@ def create_host_config(
if
network_mode
:
host_config
[
'NetworkMode'
]
=
network_mode
elif
network_mode
is
None
:
elif
network_mode
is
None
and
compare_version
(
'1.19'
,
version
)
>
0
:
host_config
[
'NetworkMode'
]
=
'default'
if
restart_policy
:
...
...
docs/api.md
Dosyayı görüntüle @
d9a149f3
...
...
@@ -234,7 +234,7 @@ from. Optionally a single string joining container id's with commas
'Warnings'
:
None
}
```
### parse_env_file
###
docker.utils.
parse_env_file
A utility for parsing an environment file.
...
...
docs/hostconfig.md
Dosyayı görüntüle @
d9a149f3
...
...
@@ -6,7 +6,7 @@ The Docker Remote API introduced [support for HostConfig in version 1.15](http:/
## HostConfig helper
###
docker.utils
.create_host_config
###
Client
.create_host_config
Creates a HostConfig dictionary to be used with
`Client.create_container`
.
...
...
@@ -97,7 +97,8 @@ for example:
**Returns**
(dict) HostConfig dictionary
```
python
>>>
from
docker.utils
import
create_host_config
>>>
create_host_config
(
privileged
=
True
,
cap_drop
=
[
'MKNOD'
],
volumes_from
=
[
'nostalgic_newton'
])
>>>
from
docker
import
Client
>>>
c
=
Client
()
>>>
c
.
create_host_config
(
privileged
=
True
,
cap_drop
=
[
'MKNOD'
],
volumes_from
=
[
'nostalgic_newton'
])
{
'CapDrop'
:
[
'MKNOD'
],
'LxcConf'
:
None
,
'Privileged'
:
True
,
'VolumesFrom'
:
[
'nostalgic_newton'
],
'PublishAllPorts'
:
False
}
```
tests/test.py
Dosyayı görüntüle @
d9a149f3
This diff is collapsed.
Click to expand it.
tests/utils_test.py
Dosyayı görüntüle @
d9a149f3
...
...
@@ -4,6 +4,7 @@ import unittest
import
tempfile
from
docker.client
import
Client
from
docker.constants
import
DEFAULT_DOCKER_API_VERSION
from
docker.errors
import
DockerException
from
docker.utils
import
(
parse_repository_tag
,
parse_host
,
convert_filters
,
kwargs_from_env
,
...
...
@@ -144,12 +145,16 @@ class UtilsTest(base.BaseTestCase):
self
.
assertEqual
(
convert_filters
(
filters
),
expected
)
def
test_create_empty_host_config
(
self
):
empty_config
=
create_host_config
(
network_mode
=
''
)
empty_config
=
create_host_config
(
network_mode
=
''
,
version
=
DEFAULT_DOCKER_API_VERSION
)
self
.
assertEqual
(
empty_config
,
{})
def
test_create_host_config_dict_ulimit
(
self
):
ulimit_dct
=
{
'name'
:
'nofile'
,
'soft'
:
8096
}
config
=
create_host_config
(
ulimits
=
[
ulimit_dct
])
config
=
create_host_config
(
ulimits
=
[
ulimit_dct
],
version
=
DEFAULT_DOCKER_API_VERSION
)
self
.
assertIn
(
'Ulimits'
,
config
)
self
.
assertEqual
(
len
(
config
[
'Ulimits'
]),
1
)
ulimit_obj
=
config
[
'Ulimits'
][
0
]
...
...
@@ -160,7 +165,9 @@ class UtilsTest(base.BaseTestCase):
def
test_create_host_config_dict_ulimit_capitals
(
self
):
ulimit_dct
=
{
'Name'
:
'nofile'
,
'Soft'
:
8096
,
'Hard'
:
8096
*
4
}
config
=
create_host_config
(
ulimits
=
[
ulimit_dct
])
config
=
create_host_config
(
ulimits
=
[
ulimit_dct
],
version
=
DEFAULT_DOCKER_API_VERSION
)
self
.
assertIn
(
'Ulimits'
,
config
)
self
.
assertEqual
(
len
(
config
[
'Ulimits'
]),
1
)
ulimit_obj
=
config
[
'Ulimits'
][
0
]
...
...
@@ -172,7 +179,9 @@ class UtilsTest(base.BaseTestCase):
def
test_create_host_config_obj_ulimit
(
self
):
ulimit_dct
=
Ulimit
(
name
=
'nofile'
,
soft
=
8096
)
config
=
create_host_config
(
ulimits
=
[
ulimit_dct
])
config
=
create_host_config
(
ulimits
=
[
ulimit_dct
],
version
=
DEFAULT_DOCKER_API_VERSION
)
self
.
assertIn
(
'Ulimits'
,
config
)
self
.
assertEqual
(
len
(
config
[
'Ulimits'
]),
1
)
ulimit_obj
=
config
[
'Ulimits'
][
0
]
...
...
@@ -186,14 +195,18 @@ class UtilsTest(base.BaseTestCase):
def
test_create_host_config_dict_logconfig
(
self
):
dct
=
{
'type'
:
LogConfig
.
types
.
SYSLOG
,
'config'
:
{
'key1'
:
'val1'
}}
config
=
create_host_config
(
log_config
=
dct
)
config
=
create_host_config
(
log_config
=
dct
,
version
=
DEFAULT_DOCKER_API_VERSION
)
self
.
assertIn
(
'LogConfig'
,
config
)
self
.
assertTrue
(
isinstance
(
config
[
'LogConfig'
],
LogConfig
))
self
.
assertEqual
(
dct
[
'type'
],
config
[
'LogConfig'
]
.
type
)
def
test_create_host_config_obj_logconfig
(
self
):
obj
=
LogConfig
(
type
=
LogConfig
.
types
.
SYSLOG
,
config
=
{
'key1'
:
'val1'
})
config
=
create_host_config
(
log_config
=
obj
)
config
=
create_host_config
(
log_config
=
obj
,
version
=
DEFAULT_DOCKER_API_VERSION
)
self
.
assertIn
(
'LogConfig'
,
config
)
self
.
assertTrue
(
isinstance
(
config
[
'LogConfig'
],
LogConfig
))
self
.
assertEqual
(
obj
,
config
[
'LogConfig'
])
...
...
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