diff options
author | shin- <joffrey@dotcloud.com> | 2013-11-08 18:32:10 +0100 |
---|---|---|
committer | shin- <joffrey@dotcloud.com> | 2013-11-08 18:32:10 +0100 |
commit | f2cf8f98469a63ca899f22abfe9f3a378ea3a07e (patch) | |
tree | 9c66c974baeb33431f5f09cdf56298402e70423a | |
parent | 03719077db30257e4e486cc0f5a89e0044ba8b70 (diff) | |
download | docker-py-f2cf8f98469a63ca899f22abfe9f3a378ea3a07e.tar.gz |
docker.objects first passobjects
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | docker/__init__.py | 1 | ||||
-rw-r--r-- | docker/objects/__init__.py | 1 | ||||
-rw-r--r-- | docker/objects/objects.py | 67 | ||||
-rw-r--r-- | setup.py | 9 |
5 files changed, 76 insertions, 6 deletions
@@ -1,11 +1,7 @@ docker-py ========= -<<<<<<< HEAD [![Build Status](https://travis-ci.org/dotcloud/docker-py.png)](https://travis-ci.org/dotcloud/docker-py) -======= -[![Build Status](https://travis-ci.org/shin-/docker-py.png)](https://travis-ci.org/shin-/docker-py) ->>>>>>> e3dfa3384ad3cee3320c402222f68b667ebc8142 An API client for docker written in Python diff --git a/docker/__init__.py b/docker/__init__.py index 5f642a8..9e59f84 100644 --- a/docker/__init__.py +++ b/docker/__init__.py @@ -13,3 +13,4 @@ # limitations under the License. from .client import Client, APIError # flake8: noqa +import objects
\ No newline at end of file diff --git a/docker/objects/__init__.py b/docker/objects/__init__.py new file mode 100644 index 0000000..f82da2c --- /dev/null +++ b/docker/objects/__init__.py @@ -0,0 +1 @@ +from .objects import init, Image, Container # flake8: noqa diff --git a/docker/objects/objects.py b/docker/objects/objects.py new file mode 100644 index 0000000..b70bcc9 --- /dev/null +++ b/docker/objects/objects.py @@ -0,0 +1,67 @@ +from .. import Client + +CLIENT = None + + +def init(client=None, base_url="unix://var/run/docker.sock", version="1.4"): + global CLIENT + if client: + CLIENT = client + else: + CLIENT = Client(base_url, version) + + +class Identifiable(object): + def __init__(self, id): + if isinstance(id, dict): + id = id.get('Id') + self.id = id + + +class Image(Identifiable): + pass + + +class Container(Identifiable): + @classmethod + def new(cls, image, **kwargs): + res = CLIENT.create_container(image, **kwargs) + return cls(res) + + def start(self, binds=None, lxc_conf=None): + CLIENT.start(self.id, binds, lxc_conf) + + def stop(self, timeout=10): + CLIENT.stop(self.id) + + def restart(self, timeout=10): + CLIENT.restart(self.id) + + def commit(self, repository=None, tag=None, message=None, author=None, + conf=None): + return Image(CLIENT.commit(self.id, repository, tag, message, author, + conf)) + + def diff(self): + return CLIENT.diff(self.id) + + def export(self): + return CLIENT.export(self.id) + + def kill(self): + return CLIENT.kill(self.id) + + def logs(self): + return CLIENT.logs(self.id) + + def port(self, private_port): + return CLIENT.port(self.id, private_port) + + def top(self): + return CLIENT.top(self.id) + + def remove(self, v=False): + return CLIENT.remove_container(self.id, v) + + def wait(self): + return CLIENT.wait(self.id) @@ -13,7 +13,12 @@ setup( name="docker-py", version='0.2.2', description="Python client for Docker.", - packages=['docker', 'docker.auth', 'docker.unixconn', 'docker.utils'], + packages=['docker', + 'docker.auth', + 'docker.objects', + 'docker.unixconn', + 'docker.utils' + ], install_requires=requirements + test_requirements, zip_safe=False, test_suite='tests', @@ -24,5 +29,5 @@ setup( 'Programming Language :: Python', 'Topic :: Utilities', 'License :: OSI Approved :: Apache Software License' - ], + ], ) |