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
08089056
Kaydet (Commit)
08089056
authored
Eki 15, 2013
tarafından
shin-
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Refactoring, Python 3 compatibility, Tests working with python 3, cleaned up imports.
üst
07d791d5
128cdb91
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
201 additions
and
18 deletions
+201
-18
__init__.py
docker/__init__.py
+0
-1
__init__.py
docker/auth/__init__.py
+2
-0
auth.py
docker/auth/auth.py
+5
-2
client.py
docker/client.py
+5
-4
__init__.py
docker/unixconn/__init__.py
+1
-0
unixconn.py
docker/unixconn/unixconn.py
+5
-1
__init__.py
docker/utils/__init__.py
+1
-0
utils.py
docker/utils/utils.py
+12
-9
requirements.txt
requirements.txt
+2
-1
fake_api.py
tests/fake_api.py
+168
-0
integration_test.py
tests/integration_test.py
+0
-0
test.py
tests/test.py
+0
-0
No files found.
docker/__init__.py
Dosyayı görüntüle @
08089056
...
...
@@ -13,4 +13,3 @@
# limitations under the License.
from
.client
import
Client
,
APIError
import
auth
docker/auth/__init__.py
0 → 100644
Dosyayı görüntüle @
08089056
from
.auth
import
*
\ No newline at end of file
docker/auth.py
→
docker/auth
/auth
.py
Dosyayı görüntüle @
08089056
...
...
@@ -18,10 +18,11 @@ import os
import
six
import
utils
import
docker.utils
as
utils
INDEX_URL
=
'https://index.docker.io/v1/'
def
swap_protocol
(
url
):
if
url
.
startswith
(
'http://'
):
return
url
.
replace
(
'http://'
,
'https://'
,
1
)
...
...
@@ -84,8 +85,10 @@ def resolve_authconfig(authconfig, registry):
def
decode_auth
(
auth
):
if
isinstance
(
auth
,
six
.
string_types
):
auth
=
auth
.
encode
(
'ascii'
)
s
=
base64
.
b64decode
(
auth
)
login
,
pwd
=
s
.
split
(
':'
)
login
,
pwd
=
s
.
split
(
b
':'
)
return
login
,
pwd
...
...
docker/client.py
Dosyayı görüntüle @
08089056
...
...
@@ -20,9 +20,9 @@ import requests
import
requests.exceptions
import
six
import
auth
import
unixconn
import
utils
import
docker.auth
as
auth
import
docker.unixconn
as
unixconn
import
docker.utils
as
utils
class
APIError
(
requests
.
exceptions
.
HTTPError
):
...
...
@@ -75,7 +75,7 @@ class Client(requests.Session):
"""Raises stored :class:`APIError`, if one occurred."""
try
:
response
.
raise_for_status
()
except
requests
.
exceptions
.
HTTPError
,
e
:
except
requests
.
exceptions
.
HTTPError
as
e
:
raise
APIError
(
e
,
response
=
response
,
explanation
=
explanation
)
def
_result
(
self
,
response
,
json
=
False
):
...
...
@@ -384,6 +384,7 @@ class Client(requests.Session):
'fromImage'
:
repository
}
headers
=
{}
if
utils
.
compare_version
(
'1.5'
,
self
.
_version
)
>=
0
:
if
getattr
(
self
,
'_cfg'
,
None
)
is
None
:
self
.
_cfg
=
auth
.
load_config
()
...
...
docker/unixconn/__init__.py
0 → 100644
Dosyayı görüntüle @
08089056
from
.unixconn
import
UnixAdapter
docker/unixconn.py
→
docker/unixconn
/unixconn
.py
Dosyayı görüntüle @
08089056
...
...
@@ -11,8 +11,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
six
import
httplib
if
six
.
PY3
:
from
http
import
client
as
httplib
else
:
import
httplib
import
requests.adapters
import
socket
...
...
docker/utils/__init__.py
0 → 100644
Dosyayı görüntüle @
08089056
from
.utils
import
mkbuildcontext
,
tar
,
compare_version
docker/utils.py
→
docker/utils
/utils
.py
Dosyayı görüntüle @
08089056
...
...
@@ -12,24 +12,27 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
io
import
tarfile
import
tempfile
import
requests
import
six
if
six
.
PY3
:
from
io
import
StringIO
else
:
from
StringIO
import
StringIO
def
mkbuildcontext
(
dockerfile
):
f
=
tempfile
.
TemporaryFile
()
f
=
tempfile
.
Named
TemporaryFile
()
t
=
tarfile
.
open
(
mode
=
'w'
,
fileobj
=
f
)
if
isinstance
(
dockerfile
,
StringIO
):
if
isinstance
(
dockerfile
,
io
.
StringIO
):
dfinfo
=
tarfile
.
TarInfo
(
'Dockerfile'
)
if
six
.
PY3
:
raise
TypeError
(
'Please use io.BytesIO to create in-memory '
'Dockerfiles with Python 3'
)
else
:
dfinfo
.
size
=
len
(
dockerfile
.
getvalue
())
elif
isinstance
(
dockerfile
,
io
.
BytesIO
):
dfinfo
=
tarfile
.
TarInfo
(
'Dockerfile'
)
dfinfo
.
size
=
dockerfile
.
len
dfinfo
.
size
=
len
(
dockerfile
.
getvalue
())
else
:
dfinfo
=
t
.
gettarinfo
(
fileobj
=
dockerfile
,
arcname
=
'Dockerfile'
)
t
.
addfile
(
dfinfo
,
dockerfile
)
...
...
@@ -39,7 +42,7 @@ def mkbuildcontext(dockerfile):
def
tar
(
path
):
f
=
tempfile
.
TemporaryFile
()
f
=
tempfile
.
Named
TemporaryFile
()
t
=
tarfile
.
open
(
mode
=
'w'
,
fileobj
=
f
)
t
.
add
(
path
,
arcname
=
'.'
)
t
.
close
()
...
...
requirements.txt
Dosyayı görüntüle @
08089056
requests
==1.2.0
mock
==1.0.1
requests
==1.2.3
six
==1.3.0
tests/fake_api.py
0 → 100644
Dosyayı görüntüle @
08089056
import
json
CURRENT_VERSION
=
'v1.4'
FAKE_CONTAINER_ID
=
'3cc2351ab11b'
FAKE_IMAGE_ID
=
'e9aa60c60128'
### Each method is prefixed with HTTP method (get, post...)
### for clarity and readability
def
get_fake_version
():
status_code
=
200
response
=
{
'GoVersion'
:
'1'
,
'Version'
:
'1.1.1'
}
return
status_code
,
response
def
get_fake_info
():
status_code
=
200
response
=
{
'Containers'
:
1
,
'Images'
:
1
,
'Debug'
:
''
}
return
status_code
,
response
def
get_fake_search
():
status_code
=
200
response
=
[{
'Name'
:
'busybox'
,
'Description'
:
'Fake Description'
}]
return
status_code
,
response
def
get_fake_images
():
status_code
=
200
response
=
[
{
'Id'
:
FAKE_IMAGE_ID
,
'Created'
:
'2 days ago'
,
'Repository'
:
'busybox'
,
'Tag'
:
'latest'
}
]
return
status_code
,
response
def
get_fake_containers
():
status_code
=
200
response
=
[
{
'Id'
:
FAKE_CONTAINER_ID
,
'Image'
:
'busybox:latest'
,
'Created'
:
'2 days ago'
,
'Command'
:
'true'
,
'Status'
:
'fake status'
}
]
return
status_code
,
response
def
post_fake_start_container
():
status_code
=
200
response
=
{
'Id'
:
FAKE_CONTAINER_ID
}
return
status_code
,
response
def
post_fake_create_container
():
status_code
=
200
response
=
{
'Id'
:
FAKE_CONTAINER_ID
}
return
status_code
,
response
def
get_fake_inspect_container
():
status_code
=
200
response
=
{
'Id'
:
FAKE_CONTAINER_ID
,
'Config'
:
{
'Privileged'
:
True
},
'ID'
:
FAKE_CONTAINER_ID
,
'Image'
:
'busybox:latest'
,
"State"
:
{
"Running"
:
True
,
"Pid"
:
0
,
"ExitCode"
:
0
,
"StartedAt"
:
"2013-09-25T14:01:18.869545111+02:00"
,
"Ghost"
:
False
},
}
return
status_code
,
response
def
get_fake_wait
():
status_code
=
200
response
=
{
'StatusCode'
:
0
}
return
status_code
,
response
def
get_fake_logs
():
status_code
=
200
response
=
'Flowering Nights (Sakuya Iyazoi)'
return
status_code
,
response
def
get_fake_diff
():
status_code
=
200
response
=
[{
'Path'
:
'/test'
,
'Kind'
:
1
}]
return
status_code
,
response
def
post_fake_stop_container
():
status_code
=
200
response
=
{
'Id'
:
FAKE_CONTAINER_ID
}
return
status_code
,
response
def
post_fake_kill_container
():
status_code
=
200
response
=
{
'Id'
:
FAKE_CONTAINER_ID
}
return
status_code
,
response
def
post_fake_restart_container
():
status_code
=
200
response
=
{
'Id'
:
FAKE_CONTAINER_ID
}
return
status_code
,
response
def
delete_fake_remove_container
():
status_code
=
200
response
=
{
'Id'
:
FAKE_CONTAINER_ID
}
return
status_code
,
response
def
post_fake_image_create
():
status_code
=
200
response
=
{
'Id'
:
FAKE_IMAGE_ID
}
return
status_code
,
response
def
delete_fake_remove_image
():
status_code
=
200
response
=
{
'Id'
:
FAKE_IMAGE_ID
}
return
status_code
,
response
def
post_fake_commit
():
status_code
=
200
response
=
{
'Id'
:
FAKE_CONTAINER_ID
}
return
status_code
,
response
def
post_fake_build_container
():
status_code
=
200
response
=
{
'Id'
:
FAKE_CONTAINER_ID
}
return
status_code
,
response
## maps real api url to fake response callback
fake_responses
=
{
'unix://var/run/docker.sock/{0}/version'
.
format
(
CURRENT_VERSION
):
get_fake_version
,
'unix://var/run/docker.sock/{0}/info'
.
format
(
CURRENT_VERSION
):
get_fake_info
,
'unix://var/run/docker.sock/{0}/images/search'
.
format
(
CURRENT_VERSION
):
get_fake_search
,
'unix://var/run/docker.sock/{0}/images/json'
.
format
(
CURRENT_VERSION
):
get_fake_images
,
'unix://var/run/docker.sock/{0}/containers/ps'
.
format
(
CURRENT_VERSION
):
get_fake_containers
,
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/start'
.
format
(
CURRENT_VERSION
):
post_fake_start_container
,
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/json'
.
format
(
CURRENT_VERSION
):
get_fake_inspect_container
,
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/wait'
.
format
(
CURRENT_VERSION
):
get_fake_wait
,
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/attach'
.
format
(
CURRENT_VERSION
):
get_fake_logs
,
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/changes'
.
format
(
CURRENT_VERSION
):
get_fake_diff
,
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/stop'
.
format
(
CURRENT_VERSION
):
post_fake_stop_container
,
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/kill'
.
format
(
CURRENT_VERSION
):
post_fake_kill_container
,
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/restart'
.
format
(
CURRENT_VERSION
):
post_fake_restart_container
,
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b'
.
format
(
CURRENT_VERSION
):
delete_fake_remove_container
,
'unix://var/run/docker.sock/{0}/images/create'
.
format
(
CURRENT_VERSION
):
post_fake_image_create
,
'unix://var/run/docker.sock/{0}/images/e9aa60c60128'
.
format
(
CURRENT_VERSION
):
delete_fake_remove_image
,
'unix://var/run/docker.sock/{0}/commit'
.
format
(
CURRENT_VERSION
):
post_fake_commit
,
'unix://var/run/docker.sock/{0}/containers/create'
.
format
(
CURRENT_VERSION
):
post_fake_create_container
,
'unix://var/run/docker.sock/{0}/build'
.
format
(
CURRENT_VERSION
):
post_fake_build_container
}
tests/integration_test.py
0 → 100644
Dosyayı görüntüle @
08089056
This diff is collapsed.
Click to expand it.
tests/test.py
Dosyayı görüntüle @
08089056
This diff is collapsed.
Click to expand it.
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