@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof AttachedNetwork) { AttachedNetwork that = (AttachedNetwork) o; return ((this.aliases == null) ? (that.aliases() == null) : this.aliases.equals(that.aliases())) && ((this.networkId == null) ? (that.networkId() == null) : this.networkId.equals(that.networkId())) && (this.endpointId.equals(that.endpointId())) && (this.gateway.equals(that.gateway())) && (this.ipAddress.equals(that.ipAddress())) && (this.ipPrefixLen.equals(that.ipPrefixLen())) && (this.ipv6Gateway.equals(that.ipv6Gateway())) && (this.globalIPv6Address.equals(that.globalIPv6Address())) && (this.globalIPv6PrefixLen.equals(that.globalIPv6PrefixLen())) && (this.macAddress.equals(that.macAddress())); } return false; }
@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; }
.anyMatch(network -> Objects.equals(network.ipAddress(), remoteUrl.getHost())); }) .findFirst().map(Container::id).orElse(null);
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof AttachedNetwork) { AttachedNetwork that = (AttachedNetwork) o; return ((this.aliases == null) ? (that.aliases() == null) : this.aliases.equals(that.aliases())) && ((this.networkId == null) ? (that.networkId() == null) : this.networkId.equals(that.networkId())) && (this.endpointId.equals(that.endpointId())) && (this.gateway.equals(that.gateway())) && (this.ipAddress.equals(that.ipAddress())) && (this.ipPrefixLen.equals(that.ipPrefixLen())) && (this.ipv6Gateway.equals(that.ipv6Gateway())) && (this.globalIPv6Address.equals(that.globalIPv6Address())) && (this.globalIPv6PrefixLen.equals(that.globalIPv6PrefixLen())) && (this.macAddress.equals(that.macAddress())); } return false; }
try { ContainerInfo server = docker.inspectContainer(neighbourServer.getName()); String neighbourIp = server.networkSettings().networks().values().asList().get(0).ipAddress();
/** * Deploy and start docker container, expose ports, connect to a network * * @return docker container id */ private String deployContainer() { ContainerConfig containerConfig = buildContainerConfig(); String id; try { ContainerCreation container = docker.createContainer(containerConfig, params.getName()); id = container.id(); dockerManager.addShutdownHook(params.getName()); docker.disconnectFromNetwork(id, "bridge"); docker.connectToNetwork(id, docker.inspectNetwork(universeParams.getNetworkName()).id()); docker.startContainer(id); String ipAddr = docker.inspectContainer(id) .networkSettings().networks() .values().asList().get(0) .ipAddress(); if (StringUtils.isEmpty(ipAddr)) { throw new NodeException("Empty Ip address for container: " + params.getName()); } ipAddress.set(ipAddr); } catch (InterruptedException | DockerException e) { throw new NodeException("Can't start a container", e); } return id; }