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


Java AttachedNetwork类代码示例

本文整理汇总了Java中com.spotify.docker.client.messages.AttachedNetwork的典型用法代码示例。如果您正苦于以下问题:Java AttachedNetwork类的具体用法?Java AttachedNetwork怎么用?Java AttachedNetwork使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AttachedNetwork类属于com.spotify.docker.client.messages包,在下文中一共展示了AttachedNetwork类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isHostNet

import com.spotify.docker.client.messages.AttachedNetwork; //导入依赖的package包/类
/**
 * 容器网络模式是否为host模式
 * @param containerId
 * @return
 */
public static boolean isHostNet(String containerId){
    String cacheKey = "isHostNet" + containerId;
    Boolean v = (Boolean) getCache(cacheKey);
    if (v != null){
        return v;
    }
    Boolean value = false;
    try {
        ContainerInfo containerInfo = getContainerInfo(containerId);
        if (containerInfo != null) {
            ImmutableMap<String, AttachedNetwork> networks =  containerInfo.networkSettings().networks();
            if (networks != null && !networks.isEmpty()){
                value = networks.get("host") != null && StringUtils.isNotEmpty(networks.get("host").ipAddress());
                setCache(cacheKey,value);
            }else {
                log.warn("容器{}无Networks配置",containerInfo.name());
            }
        }
    } catch (Exception e) {
        log.error("",e);
    }
    return value;
}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:29,代码来源:DockerUtil.java

示例2: getContainerIp

import com.spotify.docker.client.messages.AttachedNetwork; //导入依赖的package包/类
/**
 * 获取容器IP地址
 * @param containerId
 * 容器ID
 * @return
 * 1、获取失败返回null
 * 2、host网络模式直接返回宿主机IP
 */
public static String getContainerIp(String containerId){
    String cacheKey = "containerIp" + containerId;
    String v = (String) getCache(cacheKey);
    if (StringUtils.isNotEmpty(v)) {
        return v;
    }
    try {
        if (isHostNet(containerId)){
            return HostUtil.getHostIp();
        }
        ContainerInfo containerInfo = getContainerInfo(containerId);
        if (containerInfo != null) {
            ImmutableMap<String, AttachedNetwork> networks =  containerInfo.networkSettings().networks();
            if (networks != null && !networks.isEmpty()){
                String ip = networks.get(networks.keySet().asList().get(0)).ipAddress();
                setCache(cacheKey,ip);
                return ip;
            }else {
                log.warn("容器{}无Networks配置",containerInfo.name());
            }
        }
    } catch (Exception e) {
        log.error("",e);
    }

    return null;
}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:36,代码来源:DockerUtil.java


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