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
75d8ff16
Kaydet (Commit)
75d8ff16
authored
Eki 29, 2014
tarafından
Joffrey F
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge branch 'support-devices' of github.com:dims/docker-py into dims-support-devices
Conflicts: README.md
üst
465e4d9a
7a917cc7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
1 deletion
+73
-1
client.py
docker/client.py
+4
-1
utils.py
docker/utils/utils.py
+20
-0
host-devices.md
docs/host-devices.md
+13
-0
mkdocs.yml
mkdocs.yml
+1
-0
test.py
tests/test.py
+35
-0
No files found.
docker/client.py
Dosyayı görüntüle @
75d8ff16
...
...
@@ -871,7 +871,7 @@ class Client(requests.Session):
def
start
(
self
,
container
,
binds
=
None
,
port_bindings
=
None
,
lxc_conf
=
None
,
publish_all_ports
=
False
,
links
=
None
,
privileged
=
False
,
dns
=
None
,
dns_search
=
None
,
volumes_from
=
None
,
network_mode
=
None
,
restart_policy
=
None
,
cap_add
=
None
,
cap_drop
=
None
):
restart_policy
=
None
,
cap_add
=
None
,
cap_drop
=
None
,
devices
=
None
):
if
isinstance
(
container
,
dict
):
container
=
container
.
get
(
'Id'
)
...
...
@@ -939,6 +939,9 @@ class Client(requests.Session):
if
cap_drop
:
start_config
[
'CapDrop'
]
=
cap_drop
if
devices
:
start_config
[
'Devices'
]
=
utils
.
parse_devices
(
devices
)
url
=
self
.
_url
(
"/containers/{0}/start"
.
format
(
container
))
res
=
self
.
_post_json
(
url
,
data
=
start_config
)
self
.
_raise_for_status
(
res
)
...
...
docker/utils/utils.py
Dosyayı görüntüle @
75d8ff16
...
...
@@ -237,3 +237,23 @@ def parse_host(addr):
if
proto
==
"http+unix"
:
return
"
%
s://
%
s"
%
(
proto
,
host
)
return
"
%
s://
%
s:
%
d"
%
(
proto
,
host
,
port
)
def
parse_devices
(
devices
):
device_list
=
[]
for
device
in
devices
:
device_mapping
=
device
.
split
(
","
)
if
device_mapping
:
path_on_host
=
device_mapping
[
0
]
if
len
(
device_mapping
)
>
1
:
path_in_container
=
device_mapping
[
1
]
else
:
path_in_container
=
path_on_host
if
len
(
device_mapping
)
>
2
:
permissions
=
device_mapping
[
2
]
else
:
permissions
=
'rwm'
device_list
.
append
({
"PathOnHost"
:
path_on_host
,
"PathInContainer"
:
path_in_container
,
"CgroupPermissions"
:
permissions
})
return
device_list
docs/host-devices.md
0 → 100644
Dosyayı görüntüle @
75d8ff16
# Access to devices on the host
If you need to directly expose some host devices to a container, you can use
the devices parameter in the
`Client.start`
method as shown below
```
python
c
.
start
(
container_id
,
devices
=
[
'/dev/sda:/dev/xvda:rwm'
])
```
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.
mkdocs.yml
Dosyayı görüntüle @
75d8ff16
...
...
@@ -10,5 +10,6 @@ pages:
-
[
port-bindings.md
,
Port Bindings
]
-
[
volumes.md
,
Using Volumes
]
-
[
tls.md
,
Using TLS
]
-
[
host-devices.md
,
Host devices
]
-
[
change_log.md
,
Change Log
]
-
[
contributing.md
,
Contributing
]
tests/test.py
Dosyayı görüntüle @
75d8ff16
...
...
@@ -915,6 +915,41 @@ class DockerClientTest(Cleanup, unittest.TestCase):
docker
.
client
.
DEFAULT_TIMEOUT_SECONDS
)
def
test_start_container_with_devices
(
self
):
try
:
self
.
client
.
start
(
fake_api
.
FAKE_CONTAINER_ID
,
devices
=
[
'/dev/sda:/dev/xvda:rwm'
,
'/dev/sdb:/dev/xvdb'
,
'/dev/sdc'
])
except
Exception
as
e
:
self
.
fail
(
'Command should not raise exception: {0}'
.
format
(
e
))
args
=
fake_request
.
call_args
self
.
assertEqual
(
args
[
0
][
0
],
url_prefix
+
'containers/3cc2351ab11b/start'
)
self
.
assertEqual
(
json
.
loads
(
args
[
1
][
'data'
]),
{
"PublishAllPorts"
:
False
,
"Privileged"
:
False
,
"Devices"
:
[{
'CgroupPermissions'
:
'rwm'
,
'PathInContainer'
:
'/dev/sda:/dev/xvda:rwm'
,
'PathOnHost'
:
'/dev/sda:/dev/xvda:rwm'
},
{
'CgroupPermissions'
:
'rwm'
,
'PathInContainer'
:
'/dev/sdb:/dev/xvdb'
,
'PathOnHost'
:
'/dev/sdb:/dev/xvdb'
},
{
'CgroupPermissions'
:
'rwm'
,
'PathInContainer'
:
'/dev/sdc'
,
'PathOnHost'
:
'/dev/sdc'
}]}
)
self
.
assertEqual
(
args
[
1
][
'headers'
],
{
'Content-Type'
:
'application/json'
}
)
self
.
assertEqual
(
args
[
1
][
'timeout'
],
docker
.
client
.
DEFAULT_TIMEOUT_SECONDS
)
def
test_resize_container
(
self
):
try
:
self
.
client
.
resize
(
...
...
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