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
57b79cb1
Kaydet (Commit)
57b79cb1
authored
Ock 18, 2016
tarafından
Aanand Prasad
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pull request #889 from docker/725-devices-format
Improve host devices support
üst
2f2d50d0
f9b04c10
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
20 deletions
+94
-20
__init__.py
docker/utils/__init__.py
+1
-1
utils.py
docker/utils/utils.py
+14
-5
host-devices.md
docs/host-devices.md
+15
-4
hostconfig.md
docs/hostconfig.md
+4
-9
utils_test.py
tests/unit/utils_test.py
+60
-1
No files found.
docker/utils/__init__.py
Dosyayı görüntüle @
57b79cb1
...
...
@@ -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
,
create_ipam_config
,
create_ipam_pool
,
parse_devices
)
# flake8: noqa
from
.types
import
Ulimit
,
LogConfig
# flake8: noqa
...
...
docker/utils/utils.py
Dosyayı görüntüle @
57b79cb1
...
...
@@ -400,7 +400,7 @@ def parse_host(addr, platform=None):
port
=
int
(
port
)
except
Exception
:
raise
errors
.
DockerException
(
"Invalid port:
%
s"
,
addr
"Invalid port:
{0}"
.
format
(
addr
)
)
elif
proto
in
(
"http"
,
"https"
)
and
':'
not
in
addr
:
...
...
@@ -417,7 +417,14 @@ def parse_host(addr, platform=None):
def
parse_devices
(
devices
):
device_list
=
[]
for
device
in
devices
:
device_mapping
=
device
.
split
(
":"
)
if
isinstance
(
device
,
dict
):
device_list
.
append
(
device
)
continue
if
not
isinstance
(
device
,
six
.
string_types
):
raise
errors
.
DockerException
(
'Invalid device type {0}'
.
format
(
type
(
device
))
)
device_mapping
=
device
.
split
(
':'
)
if
device_mapping
:
path_on_host
=
device_mapping
[
0
]
if
len
(
device_mapping
)
>
1
:
...
...
@@ -428,9 +435,11 @@ def parse_devices(devices):
permissions
=
device_mapping
[
2
]
else
:
permissions
=
'rwm'
device_list
.
append
({
"PathOnHost"
:
path_on_host
,
"PathInContainer"
:
path_in_container
,
"CgroupPermissions"
:
permissions
})
device_list
.
append
({
'PathOnHost'
:
path_on_host
,
'PathInContainer'
:
path_in_container
,
'CgroupPermissions'
:
permissions
})
return
device_list
...
...
docs/host-devices.md
Dosyayı görüntüle @
57b79cb1
...
...
@@ -12,7 +12,18 @@ cli.create_container(
)
```
Each string is a single mapping using the colon (':') as the separator. So the
above example essentially allow the container to have read write permissions to
access the host's /dev/sda via a node named /dev/xvda in the container. The
devices parameter is a list to allow multiple devices to be mapped.
Each string is a single mapping using the following format:
`<path_on_host>:<path_in_container>:<cgroup_permissions>`
The above example allows the container to have read-write access to
the host's
`/dev/sda`
via a node named
`/dev/xvda`
inside the container.
As a more verbose alternative, each host device definition can be specified as
a dictionary with the following keys:
```
python
{
'PathOnHost'
:
'/dev/sda1'
,
'PathInContainer'
:
'/dev/xvda'
,
'CgroupPermissions'
:
'rwm'
}
```
docs/hostconfig.md
Dosyayı görüntüle @
57b79cb1
...
...
@@ -104,17 +104,12 @@ for example:
*
mem_swappiness (int): Tune a container's memory swappiness behavior.
Accepts number between 0 and 100.
*
cpu_group (int): The length of a CPU period in microseconds.
*
cpu_period (int): Microseconds of CPU time that the container can get in a CPU period.
*
cpu_period (int): Microseconds of CPU time that the container can get in a
CPU period.
*
group_add (list): List of additional group names and/or IDs that the
container process will run as.
*
devices (list): A list of devices to add to the container specified as dicts
in the form:
```
{ "PathOnHost": "/dev/deviceName",
"PathInContainer": "/dev/deviceName",
"CgroupPermissions": "mrw"
}
```
*
devices (list): Host device bindings. See
[
host devices
](
host-devices.md
)
for more information.
**Returns**
(dict) HostConfig dictionary
...
...
tests/unit/utils_test.py
Dosyayı görüntüle @
57b79cb1
...
...
@@ -18,7 +18,7 @@ from docker.utils import (
parse_repository_tag
,
parse_host
,
convert_filters
,
kwargs_from_env
,
create_host_config
,
Ulimit
,
LogConfig
,
parse_bytes
,
parse_env_file
,
exclude_paths
,
convert_volume_binds
,
decode_json_header
,
tar
,
split_command
,
create_ipam_config
,
create_ipam_pool
,
split_command
,
create_ipam_config
,
create_ipam_pool
,
parse_devices
,
)
from
docker.utils.utils
import
create_endpoint_config
from
docker.utils.ports
import
build_port_bindings
,
split_port
...
...
@@ -406,6 +406,65 @@ class ParseRepositoryTagTest(base.BaseTestCase):
)
class
ParseDeviceTest
(
base
.
BaseTestCase
):
def
test_dict
(
self
):
devices
=
parse_devices
([{
'PathOnHost'
:
'/dev/sda1'
,
'PathInContainer'
:
'/dev/mnt1'
,
'CgroupPermissions'
:
'r'
}])
self
.
assertEqual
(
devices
[
0
],
{
'PathOnHost'
:
'/dev/sda1'
,
'PathInContainer'
:
'/dev/mnt1'
,
'CgroupPermissions'
:
'r'
})
def
test_partial_string_definition
(
self
):
devices
=
parse_devices
([
'/dev/sda1'
])
self
.
assertEqual
(
devices
[
0
],
{
'PathOnHost'
:
'/dev/sda1'
,
'PathInContainer'
:
'/dev/sda1'
,
'CgroupPermissions'
:
'rwm'
})
def
test_permissionless_string_definition
(
self
):
devices
=
parse_devices
([
'/dev/sda1:/dev/mnt1'
])
self
.
assertEqual
(
devices
[
0
],
{
'PathOnHost'
:
'/dev/sda1'
,
'PathInContainer'
:
'/dev/mnt1'
,
'CgroupPermissions'
:
'rwm'
})
def
test_full_string_definition
(
self
):
devices
=
parse_devices
([
'/dev/sda1:/dev/mnt1:r'
])
self
.
assertEqual
(
devices
[
0
],
{
'PathOnHost'
:
'/dev/sda1'
,
'PathInContainer'
:
'/dev/mnt1'
,
'CgroupPermissions'
:
'r'
})
def
test_hybrid_list
(
self
):
devices
=
parse_devices
([
'/dev/sda1:/dev/mnt1:rw'
,
{
'PathOnHost'
:
'/dev/sda2'
,
'PathInContainer'
:
'/dev/mnt2'
,
'CgroupPermissions'
:
'r'
}
])
self
.
assertEqual
(
devices
[
0
],
{
'PathOnHost'
:
'/dev/sda1'
,
'PathInContainer'
:
'/dev/mnt1'
,
'CgroupPermissions'
:
'rw'
})
self
.
assertEqual
(
devices
[
1
],
{
'PathOnHost'
:
'/dev/sda2'
,
'PathInContainer'
:
'/dev/mnt2'
,
'CgroupPermissions'
:
'r'
})
class
UtilsTest
(
base
.
BaseTestCase
):
longMessage
=
True
...
...
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