• docker-api


    __author__ = 'zxp'
    import docker
    import sys
    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()
    
  • 相关阅读:
    HTTP、HTTP2
    1-1 用本地代码调试线上环境代码
    js判断触摸方向
    1-1 node 基础
    1-2 nodejs小节 文件读取
    c++ 递归斐波那契算法及时间复杂度
    十进制转换成二进制以 二进制转换成 8进制和16进制
    centos6.5 安装cmake 3.3.2
    回文字符串
    -Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable
  • 原文地址:https://www.cnblogs.com/zxpgo/p/4167808.html
Copyright © 2020-2023  润新知