码迷,mamicode.com
首页 > 其他好文 > 详细

1111

时间:2015-03-12 18:41:13      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

class DockerManager_Slave(object):
    def __init__(self):
        self.idict={}
        self.rinfo={}
        try:
            self.c = docker.Client(base_url=unix://var/run/docker.sock,version=1.0.1,timeout=15)
        except Exception,e:
            print "Connection docker server error:"+str(e)
            sys.exit()
    def Create_Container(self,image,command=None,mem_limit=0,ports=None,name=None,cpu_shares=None):
        """
        :param image (str): The image to run
        :param command (str or list): The command to be run in the container
        :param mem_limit (float or str): Memory limit (format: [number][optional unit], where unit = b, k, m, or g)
        :param ports (list of ints): A list of port numbers
        :param name (str): A name for the container
        :param cpu_shares (int or float): CPU shares (relative weight)
        Returns (dict): A dictionary with an image ‘Id‘ key and a ‘Warnings‘ key.
        return container id
        """
        try:
            self.container = self.c.create_container(image=image, command=command,mem_limit=mem_limit,ports=ports,                                                 name=name,cpu_shares=cpu_shares)
        except Exception,e:
            print "Create Container error:"+str(e)
            sys.exit()
        return self.container[Id]
    def Inspect_Container(self,containerid):
        """
        :param containerid:The container to inspect
        :return:Nearly the same output as docker inspect, just as a single dict
        """
        try:
            self.container_info=self.c.inspect_container(containerid)
        except Exception,e:
            print "Inspect Container"+containerid+"error:"+str(e)
            sys.exit()
    def Pull(self,repository,tag=None):
        """
        :param repository (str): The repository to pull
        :param tag (str): The tag to pull
        :return (generator or str): The output
        """
        try:
            self.pull_detail=self.c.pull(repository,tag)
        except Exception,e:
            print "Pull images"+repository+":"+tag+"error:"+str(e)
            sys.exit()
    def Start(self,containerid):
        try:
            self.c.start(containerid)
        except Exception,e:
            print "Start Container"+containerid+"error:"+str(e)
    def Stop(self,containerid,timeout=10):
        """
        :param container (str): The container to stop
        :param timeout (int): Timeout in seconds to wait for the container to stop before sending a SIGKILL
        :return:
        """
        try:
            self.c.stop(containerid,timeout=timeout)
        except Exception,e:
            print "Stop"+containerid+"error:"+str(e)
            sys.exit()
    def Remove_Container(self,containerid):
        """
        container (str): The container to remove
        v (bool): Remove the volumes associated with the container
        link (bool): Remove the specified link and not the underlying container
        force (bool): Force the removal of a running container (uses SIGKILL)
        """
        try:
            self.c.remove_container(containerid)
        except Exception,e:
            print "Remove container"+containerid+"error:"+str(e)
            sys.exit()

 

1111

标签:

原文地址:http://www.cnblogs.com/zxpgo/p/4332842.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!