def is_start(url, username, cid, token=None):
    """创建容器

    :param str url: Fuerte api address
    :param str username: Fuvism user name
    :param str cid: The container uuid
    :param str or None token: Fuerte auth token
    """

    data = {
        "action": "Container:IsStart",
        "params": {"username": username, "cid": cid}
    }
    kwargs = {"url": url, "data": json.dumps(data), "token": token}
    return pack_requests(**kwargs)
def create(url, username, image, cid=None, token=None):
    """创建容器

    :param str url: Fuerte api address
    :param str username: Fuvism user name
    :param str image: Image name for container
    :param str cid: The container uuid
    :param str or None token: Fuerte auth token
    """

    data = {
        "action": "Container:Create",
        "params": {"username": username, "image": image, "cid": cid}
    }
    kwargs = {"url": url, "data": json.dumps(data), "token": token}
    return pack_requests(**kwargs)
Example #3
0
def fd_check(url, cid, fds, token=None):
    """在容器所在 Docker 主机上检测文件、目录是否创建

    :param str url: Fuerte api address
    :param str cid: The container uuid
    :param list fds: 要检测的数据结构
        e.g.: [
            {"type": "dir", "name": "/some/dirname"},
            {"type": "file", "name": "/some/filename"}
        ]
    :param str or None token: Fuerte auth token
    """

    data = {"action": "Host:FdCheck", "params": {"cid": cid, "fds": fds}}
    kwargs = {"url": url, "data": json.dumps(data), "token": token}
    return pack_requests(**kwargs)
Example #4
0
def read_files(url, files, cid=None, token=None):
    """在 Docker 主机或容器中读取文件内容

    :param str url: Fuerte api address
    :param dict files:
        e.g.: {"/etc/hosts": "",
               "/tmp/test.txt": "the test.txt default content."}
    :param str or None cid: The container uuid
        cid is str: 读取容器里的文件内容
        cid is None: 读取主机里的文件内容
    :param str or None token: Fuerte auth token
    """

    data = {"action": "Host:ReadFiles", "params": {"files": files, "cid": cid}}
    kwargs = {"url": url, "data": json.dumps(data), "token": token}
    return pack_requests(**kwargs)
def delete(url, username, cid, reset=False, token=None):
    """删除容器

    :param str url: Fuerte api address
    :param str username: Fuvism user name
    :param str cid: The container uuid
    :param bool reset:
        reset is True, clear container data in ceph rbd
    :param str or None token: Fuerte auth token
    """

    data = {
        "action": "Container:Delete",
        "params": {"username": username, "cid": cid, "reset": reset}
    }
    kwargs = {"url": url, "data": json.dumps(data), "token": token}
    return pack_requests(**kwargs)
def execute(url, cid, cmds, wait=False, token=None):
    """在容器中执行命令

    :param str url: Fuerte api address
    :param str cid: The container uuid
    :param list cmds: List of commands to execute
    :param bool wait:
        wait is True  命令将在前台执行,会等待命令执行完成
        wait is False 命令将在后台执行,不等待命令执行完成
    :param str or None token: Fuerte auth token
    """

    data = {
        "action": "Container:Exec",
        "params": {"cid": cid, "cmds": cmds, "wait": wait}
    }
    kwargs = {"url": url, "data": json.dumps(data), "token": token}
    return pack_requests(**kwargs)
def console(url, username, cid, cmds=None, token=None):
    """在容器中打入 Console 进程

    :param str url: Fuerte api address
    :param str username: Fuvism user name
    :param str cid: The container uuid
    :param list or None cmds:
        str: Console command(e.g., `ipython`, `python manager.py runserver`)
        None: Bash console
    :param str or None token: Fuerte auth token
    """

    data = {
        "action": "Container:Console",
        "params": {"username": username, "cid": cid, "cmds": cmds}
    }
    kwargs = {"url": url, "data": json.dumps(data), "token": token}
    return pack_requests(**kwargs)
Example #8
0
def execute(url, cid, username, cmds, token=None):
    """在容器所在 Docker 主机上执行命令

    :param str url: Fuerte api address
    :param str cid: The container uuid
    :param list cmds: List of commands to execute
    :param str or None token: Fuerte auth token
    """

    data = {
        "action": "Host:Exec",
        "params": {
            "cid": cid,
            "cmds": cmds,
            "username": username
        }
    }
    kwargs = {"url": url, "data": json.dumps(data), "token": token}
    return pack_requests(**kwargs)
Example #9
0
def write_files(url, files, username, cid=None, token=None):
    """为 Docker 主机或容器里写入文件内容

    :param str url: Fuerte api address
    :param dict files:
        e.g.: {"/etc/hosts": "",
               "/tmp/test.txt": "the test.txt default content."}
    :param str or None cid: The container uuid
        cid is str: 为容器里的文件写入内容
        cid is None: 为当前主机的文件写入内容
    :param str or None token: Fuerte auth token
    """

    data = {
        "action": "Host:WriteFiles",
        "params": {
            "files": files,
            "cid": cid,
            "username": username
        }
    }
    kwargs = {"url": url, "data": json.dumps(data), "token": token}
    return pack_requests(**kwargs)