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 /docker | |
parent | 03719077db30257e4e486cc0f5a89e0044ba8b70 (diff) | |
download | docker-py-objects.tar.gz |
docker.objects first passobjects
Diffstat (limited to 'docker')
-rw-r--r-- | docker/__init__.py | 1 | ||||
-rw-r--r-- | docker/objects/__init__.py | 1 | ||||
-rw-r--r-- | docker/objects/objects.py | 67 |
3 files changed, 69 insertions, 0 deletions
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) |