当前位置: 首页>>代码示例>>Python>>正文


Python APIClient.networks方法代码示例

本文整理汇总了Python中docker.APIClient.networks方法的典型用法代码示例。如果您正苦于以下问题:Python APIClient.networks方法的具体用法?Python APIClient.networks怎么用?Python APIClient.networks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在docker.APIClient的用法示例。


在下文中一共展示了APIClient.networks方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cleanup_host

# 需要导入模块: from docker import APIClient [as 别名]
# 或者: from docker.APIClient import networks [as 别名]
def cleanup_host(worker_api, timeout=5):
    """
    Cleanup a container host when use removes the host

    Maybe we will remove the networks?

    :param worker_api: Docker daemon url
    :param timeout: timeout to wait
    :return:
    """
    if not worker_api or not worker_api.startswith("tcp://"):
        logger.error("Invalid worker_api={}".format(worker_api))
        return False
    try:
        client = Client(base_url=worker_api, version="auto", timeout=timeout)
        net_names = [x["Name"] for x in client.networks()]
        for cs_type in CONSENSUS_PLUGINS_FABRIC_V1:
            net_name = CLUSTER_NETWORK + "_{}".format(cs_type)
            if net_name in net_names:
                logger.debug("Remove network {}".format(net_name))
                client.remove_network(net_name)
            else:
                logger.warning("Network {} not exists!".format(net_name))
    except Exception as e:
        logger.error("Exception happens!")
        logger.error(e)
        return False
    return True
开发者ID:arindbha,项目名称:cello,代码行数:30,代码来源:docker_swarm.py

示例2: _clean_network

# 需要导入模块: from docker import APIClient [as 别名]
# 或者: from docker.APIClient import networks [as 别名]
 def _clean_network(self):
     client = Client(base_url=self._docker_host, version="auto", timeout=10)
     networks = client.networks(names=["%s_default" % self._project_name])
     id_removes = [e["Id"] for e in networks]
     for network_id in id_removes:
         client.remove_network(network_id)
         LOG.debug("Remove network id {}".format(network_id))
开发者ID:arindbha,项目名称:cello,代码行数:9,代码来源:__init__.py

示例3: _clean_project_networks

# 需要导入模块: from docker import APIClient [as 别名]
# 或者: from docker.APIClient import networks [as 别名]
def _clean_project_networks(worker_api, name_prefix, timeout=5):
    """
    Clean cluster node networks

    All containers with the name prefix will be removed.

    :param worker_api: Docker daemon url
    :param name_prefix: image name prefix
    :param timeout: Time to wait for the response
    :return: None
    """
    logger.debug("Clean project networks, worker_api={}, prefix={}".format(
        worker_api, name_prefix))
    client = Client(base_url=worker_api, version="auto", timeout=timeout)
    networks = client.networks(names=["%s_default" % name_prefix])
    id_removes = [e['Id'] for e in networks]
    for network_id in id_removes:
        client.remove_network(network_id)
        logger.debug("Remove network id {}".format(network_id))
开发者ID:arindbha,项目名称:cello,代码行数:21,代码来源:docker_swarm.py

示例4: setup_container_host

# 需要导入模块: from docker import APIClient [as 别名]
# 或者: from docker.APIClient import networks [as 别名]
def setup_container_host(host_type, worker_api, timeout=5):
    """
    Setup a container host for deploying cluster on it

    :param host_type: Docker host type
    :param worker_api: Docker daemon url
    :param timeout: timeout to wait
    :return: True or False
    """
    if not worker_api or not worker_api.startswith("tcp://"):
        logger.error("Invalid worker_api={}".format(worker_api))
        return False
    if host_type not in WORKER_TYPES:
        logger.error("Invalid host_type={}".format(host_type))
        return False
    try:
        client = Client(base_url=worker_api, version="auto", timeout=timeout)
        net_names = [x["Name"] for x in client.networks()]
        for cs_type in CONSENSUS_PLUGINS_FABRIC_V1:
            net_name = CLUSTER_NETWORK + "_{}".format(cs_type)
            if net_name in net_names:
                logger.warning("Network {} already exists, use it!".format(
                    net_name))
            else:
                if host_type == WORKER_TYPES[0]:  # single
                    client.create_network(net_name, driver='bridge')
                elif host_type == WORKER_TYPES[1]:  # swarm
                    client.create_network(net_name, driver='overlay')
                else:
                    logger.error("No-supported host_type={}".format(host_type))
                    return False
    except Exception as e:
        logger.error("Exception happens!")
        logger.error(e)
        return False
    return True
开发者ID:arindbha,项目名称:cello,代码行数:38,代码来源:docker_swarm.py


注:本文中的docker.APIClient.networks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。