Builder(NetworkSettings source) { this.ipAddress = source.ipAddress(); this.ipPrefixLen = source.ipPrefixLen(); this.gateway = source.gateway(); this.bridge = source.bridge(); this.portMapping = source.portMapping(); this.ports = source.ports(); this.macAddress = source.macAddress(); this.networks = source.networks(); this.endpointId = source.endpointId(); this.sandboxId = source.sandboxId(); this.sandboxKey = source.sandboxKey(); this.hairpinMode = source.hairpinMode(); this.linkLocalIPv6Address = source.linkLocalIPv6Address(); this.linkLocalIPv6PrefixLen = source.linkLocalIPv6PrefixLen(); this.globalIPv6Address = source.globalIPv6Address(); this.globalIPv6PrefixLen = source.globalIPv6PrefixLen(); this.ipv6Gateway = source.ipv6Gateway(); } @Override
return builder() .ipAddress(ipAddress) .ipPrefixLen(ipPrefixLen)
@Override public String getContainerIp(String containerName) { String containerId = this.getContainerId(containerName); if (containerId == null) { return null; } try { ContainerInfo containerInfo = dockerClient.inspectContainer(containerId); if (containerInfo.networkSettings().ipAddress().trim().isEmpty()) { ImmutableMap<String, AttachedNetwork> networks = containerInfo.networkSettings().networks(); return networks.entrySet().stream().findFirst().get().getValue().ipAddress(); } return containerInfo.networkSettings().ipAddress(); } catch (DockerException | InterruptedException e) { logger.debug(nodeId + " Error while getting the container IP.", e); ga.trackException(e); } return null; }
syslogHost + ":" + containerInfo.networkSettings().ports().get(expose).get(0).hostPort();
private synchronized String getZaleniumNetwork(String zaleniumContainerName) { if (zaleniumNetwork != null) { return zaleniumNetwork; } String zaleniumContainerId = getContainerId(zaleniumContainerName); if (zaleniumContainerId == null) { logger.warn(String.format("Couldn't find selenium container with name or containing: %s, check that the env " + "variable ZALENIUM_CONTAINER_NAME has an appropriate value", zaleniumContainerName)); } try { ContainerInfo containerInfo = dockerClient.inspectContainer(zaleniumContainerId); ImmutableMap<String, AttachedNetwork> networks = containerInfo.networkSettings().networks(); for (Map.Entry<String, AttachedNetwork> networkEntry : networks.entrySet()) { if (!DEFAULT_DOCKER_NETWORK_NAME.equalsIgnoreCase(networkEntry.getKey())) { zaleniumNetwork = networkEntry.getKey(); return zaleniumNetwork; } } } catch (DockerException | InterruptedException | NullPointerException e) { logger.debug(nodeId + " Error while getting Zalenium network. Falling back to default.", e); ga.trackException(e); } zaleniumNetwork = DEFAULT_DOCKER_NETWORK_MODE; return zaleniumNetwork; }
public String internalIPAddress() { return containerInfo.networkSettings().ipAddress(); } }
protected String getBridgeAddress(String containerId) throws DockerException, InterruptedException { return dockerClient.inspectContainer(containerId).networkSettings().gateway(); } }
@Override protected void containerIsStarting(ContainerInfo containerInfo) { ports = containerInfo.networkSettings().ports(); seleniumPort = ports.get("4444/tcp").get(0).hostPort(); vncPort = ports.get("5900/tcp").get(0).hostPort(); }
return networkSettings.networks().values().stream() .anyMatch(network -> Objects.equals(network.ipAddress(), remoteUrl.getHost())); })
public String containerIp(String buildContainerId) { try { return dockerClient.inspectContainer(buildContainerId).networkSettings().ipAddress(); } catch (DockerException | InterruptedException e) { logger.error("", e); } return null; }
@Override public boolean check(final String containerId) throws InterruptedException, DockerException { final Integer port = taskConfig.ports().get(healthCheck.getPort()).getExternalPort(); InetSocketAddress address = new InetSocketAddress(dockerHost.address(), port); if (address.getAddress().isLoopbackAddress()) { // tcp connections to a container-mapped port on loopback always succeed, // regardless of if the container is listening or not. use the bridge address instead. final String bridge = docker.inspectContainer(containerId).networkSettings().gateway(); address = new InetSocketAddress(bridge, port); } try (final Socket s = new Socket()) { s.connect(address, CONNECT_TIMEOUT_MILLIS); } catch (Exception e) { return false; } return true; } }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof NetworkSettings) { NetworkSettings that = (NetworkSettings) o; return ((this.ipAddress == null) ? (that.ipAddress() == null) : this.ipAddress.equals(that.ipAddress())) && ((this.ipPrefixLen == null) ? (that.ipPrefixLen() == null) : this.ipPrefixLen.equals(that.ipPrefixLen())) && ((this.gateway == null) ? (that.gateway() == null) : this.gateway.equals(that.gateway())) && ((this.bridge == null) ? (that.bridge() == null) : this.bridge.equals(that.bridge())) && ((this.portMapping == null) ? (that.portMapping() == null) : this.portMapping.equals(that.portMapping())) && ((this.ports == null) ? (that.ports() == null) : this.ports.equals(that.ports())) && ((this.macAddress == null) ? (that.macAddress() == null) : this.macAddress.equals(that.macAddress())) && ((this.networks == null) ? (that.networks() == null) : this.networks.equals(that.networks())) && ((this.endpointId == null) ? (that.endpointId() == null) : this.endpointId.equals(that.endpointId())) && ((this.sandboxId == null) ? (that.sandboxId() == null) : this.sandboxId.equals(that.sandboxId())) && ((this.sandboxKey == null) ? (that.sandboxKey() == null) : this.sandboxKey.equals(that.sandboxKey())) && ((this.hairpinMode == null) ? (that.hairpinMode() == null) : this.hairpinMode.equals(that.hairpinMode())) && ((this.linkLocalIPv6Address == null) ? (that.linkLocalIPv6Address() == null) : this.linkLocalIPv6Address.equals(that.linkLocalIPv6Address())) && ((this.linkLocalIPv6PrefixLen == null) ? (that.linkLocalIPv6PrefixLen() == null) : this.linkLocalIPv6PrefixLen.equals(that.linkLocalIPv6PrefixLen())) && ((this.globalIPv6Address == null) ? (that.globalIPv6Address() == null) : this.globalIPv6Address.equals(that.globalIPv6Address())) && ((this.globalIPv6PrefixLen == null) ? (that.globalIPv6PrefixLen() == null) : this.globalIPv6PrefixLen.equals(that.globalIPv6PrefixLen())) && ((this.ipv6Gateway == null) ? (that.ipv6Gateway() == null) : this.ipv6Gateway.equals(that.ipv6Gateway())); } return false; }
@Override protected void containerIsStarting(ContainerInfo containerInfo) { ports = containerInfo.networkSettings().ports(); seleniumPort = ports.get("4444/tcp").get(0).hostPort(); vncPort = ports.get("5900/tcp").get(0).hostPort(); }
public String getHost(String containerId, String network) throws DockerException, InterruptedException { return IS_OS_LINUX ? dockerClient.inspectContainer(containerId).networkSettings() .networks().get(network).gateway() : dockerClient.getHost(); }
return builder() .ipAddress(ipAddress) .ipPrefixLen(ipPrefixLen)
Builder(NetworkSettings source) { this.ipAddress = source.ipAddress(); this.ipPrefixLen = source.ipPrefixLen(); this.gateway = source.gateway(); this.bridge = source.bridge(); this.portMapping = source.portMapping(); this.ports = source.ports(); this.macAddress = source.macAddress(); this.networks = source.networks(); this.endpointId = source.endpointId(); this.sandboxId = source.sandboxId(); this.sandboxKey = source.sandboxKey(); this.hairpinMode = source.hairpinMode(); this.linkLocalIPv6Address = source.linkLocalIPv6Address(); this.linkLocalIPv6PrefixLen = source.linkLocalIPv6PrefixLen(); this.globalIPv6Address = source.globalIPv6Address(); this.globalIPv6PrefixLen = source.globalIPv6PrefixLen(); this.ipv6Gateway = source.ipv6Gateway(); } @Override
public String getBindPort(String containerId, String exposed) throws DockerException, InterruptedException { ImmutableMap<String, List<PortBinding>> ports = dockerClient .inspectContainer(containerId).networkSettings().ports(); List<PortBinding> exposedPort = ports.get(exposed); log.trace("Port list {} -- Exposed port {} = {}", ports, exposed, exposedPort); if (ports.isEmpty() || exposedPort.isEmpty()) { String dockerImage = dockerClient.inspectContainer(containerId) .config().image(); throw new SeleniumJupiterException("Port " + exposed + " is not bindable in container " + dockerImage); } return exposedPort.get(0).hostPort(); }
try { ContainerInfo server = docker.inspectContainer(neighbourServer.getName()); String neighbourIp = server.networkSettings().networks().values().asList().get(0).ipAddress();