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
f40079d8
Kaydet (Commit)
f40079d8
authored
Şub 21, 2018
tarafından
Joffrey F
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge branch 'BYU-PCCL-master'
üst
759833c1
9b6b306e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
2 deletions
+91
-2
service.py
docker/api/service.py
+5
-0
services.py
docker/types/services.py
+35
-2
api_service_test.py
tests/integration/api_service_test.py
+51
-0
No files found.
docker/api/service.py
Dosyayı görüntüle @
f40079d8
...
...
@@ -73,6 +73,11 @@ def _check_api_features(version, task_template, update_config, endpoint_spec):
if
container_spec
.
get
(
'Isolation'
)
is
not
None
:
raise_version_error
(
'ContainerSpec.isolation'
,
'1.35'
)
if
task_template
.
get
(
'Resources'
):
if
utils
.
version_lt
(
version
,
'1.35'
):
if
task_template
[
'Resources'
]
.
get
(
'GenericResources'
):
raise_version_error
(
'Resources.generic_resources'
,
'1.35'
)
def
_merge_task_template
(
current
,
override
):
merged
=
current
.
copy
()
...
...
docker/types/services.py
Dosyayı görüntüle @
f40079d8
...
...
@@ -306,9 +306,13 @@ class Resources(dict):
mem_limit (int): Memory limit in Bytes.
cpu_reservation (int): CPU reservation in units of 10^9 CPU shares.
mem_reservation (int): Memory reservation in Bytes.
generic_resources (dict or :py:class:`list`): Node level generic
resources, for example a GPU, using the following format:
``{ resource_name: resource_value }``. Alternatively, a list of
of resource specifications as defined by the Engine API.
"""
def
__init__
(
self
,
cpu_limit
=
None
,
mem_limit
=
None
,
cpu_reservation
=
None
,
mem_reservation
=
None
):
mem_reservation
=
None
,
generic_resources
=
None
):
limits
=
{}
reservation
=
{}
if
cpu_limit
is
not
None
:
...
...
@@ -319,13 +323,42 @@ class Resources(dict):
reservation
[
'NanoCPUs'
]
=
cpu_reservation
if
mem_reservation
is
not
None
:
reservation
[
'MemoryBytes'
]
=
mem_reservation
if
generic_resources
is
not
None
:
reservation
[
'GenericResources'
]
=
(
_convert_generic_resources_dict
(
generic_resources
)
)
if
limits
:
self
[
'Limits'
]
=
limits
if
reservation
:
self
[
'Reservations'
]
=
reservation
def
_convert_generic_resources_dict
(
generic_resources
):
if
isinstance
(
generic_resources
,
list
):
return
generic_resources
if
not
isinstance
(
generic_resources
,
dict
):
raise
errors
.
InvalidArgument
(
'generic_resources must be a dict or a list'
' (found {})'
.
format
(
type
(
generic_resources
))
)
resources
=
[]
for
kind
,
value
in
six
.
iteritems
(
generic_resources
):
resource_type
=
None
if
isinstance
(
value
,
int
):
resource_type
=
'DiscreteResourceSpec'
elif
isinstance
(
value
,
str
):
resource_type
=
'NamedResourceSpec'
else
:
raise
errors
.
InvalidArgument
(
'Unsupported generic resource reservation '
'type: {}'
.
format
({
kind
:
value
})
)
resources
.
append
({
resource_type
:
{
'Kind'
:
kind
,
'Value'
:
value
}
})
return
resources
class
UpdateConfig
(
dict
):
"""
...
...
tests/integration/api_service_test.py
Dosyayı görüntüle @
f40079d8
...
...
@@ -4,6 +4,7 @@ import random
import
time
import
docker
import
pytest
import
six
from
..helpers
import
(
...
...
@@ -212,6 +213,56 @@ class ServiceTest(BaseAPIIntegrationTest):
'Reservations'
]
def
_create_service_with_generic_resources
(
self
,
generic_resources
):
container_spec
=
docker
.
types
.
ContainerSpec
(
BUSYBOX
,
[
'true'
])
resources
=
docker
.
types
.
Resources
(
generic_resources
=
generic_resources
)
task_tmpl
=
docker
.
types
.
TaskTemplate
(
container_spec
,
resources
=
resources
)
name
=
self
.
get_service_name
()
svc_id
=
self
.
client
.
create_service
(
task_tmpl
,
name
=
name
)
return
resources
,
self
.
client
.
inspect_service
(
svc_id
)
@requires_api_version
(
'1.35'
)
def
test_create_service_with_generic_resources
(
self
):
successful
=
[{
'input'
:
[
{
'DiscreteResourceSpec'
:
{
'Kind'
:
'gpu'
,
'Value'
:
1
}},
{
'NamedResourceSpec'
:
{
'Kind'
:
'gpu'
,
'Value'
:
'test'
}}
]},
{
'input'
:
{
'gpu'
:
2
,
'mpi'
:
'latest'
},
'expected'
:
[
{
'DiscreteResourceSpec'
:
{
'Kind'
:
'gpu'
,
'Value'
:
2
}},
{
'NamedResourceSpec'
:
{
'Kind'
:
'mpi'
,
'Value'
:
'latest'
}}
]}
]
for
test
in
successful
:
t
=
test
[
'input'
]
resrcs
,
svc_info
=
self
.
_create_service_with_generic_resources
(
t
)
assert
'TaskTemplate'
in
svc_info
[
'Spec'
]
res_template
=
svc_info
[
'Spec'
][
'TaskTemplate'
]
assert
'Resources'
in
res_template
res_reservations
=
res_template
[
'Resources'
][
'Reservations'
]
assert
res_reservations
==
resrcs
[
'Reservations'
]
assert
'GenericResources'
in
res_reservations
def
_key
(
d
,
specs
=
(
'DiscreteResourceSpec'
,
'NamedResourceSpec'
)):
return
[
d
.
get
(
s
,
{})
.
get
(
'Kind'
,
''
)
for
s
in
specs
]
actual
=
res_reservations
[
'GenericResources'
]
expected
=
test
.
get
(
'expected'
,
test
[
'input'
])
assert
sorted
(
actual
,
key
=
_key
)
==
sorted
(
expected
,
key
=
_key
)
def
test_create_service_with_invalid_generic_resources
(
self
):
for
test_input
in
[
'1'
,
1.0
,
lambda
:
'1'
,
{
1
,
2
}]:
with
pytest
.
raises
(
docker
.
errors
.
InvalidArgument
):
self
.
_create_service_with_generic_resources
(
test_input
)
def
test_create_service_with_update_config
(
self
):
container_spec
=
docker
.
types
.
ContainerSpec
(
BUSYBOX
,
[
'true'
])
task_tmpl
=
docker
.
types
.
TaskTemplate
(
container_spec
)
...
...
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