public Builder toBuilder() { return builder().fromContainer(this); }
public Builder fromContainer(Container in) { return this.id(in.id()).name(in.name()).created(in.created()).path(in.path()).args(in.args()) .config(in.config()).state(in.state()).image(in.image()).networkSettings(in.networkSettings()) .sysInitPath(in.sysInitPath()).resolvConfPath(in.resolvConfPath()).driver(in.driver()) .execDriver(in.execDriver()).volumes(in.volumes()).hostConfig(in.hostConfig()).volumesRW(in.volumesRW()) .command(in.command()).status(in.status()).ports(in.ports()).hostnamePath(in.hostnamePath()) .hostsPath(in.hostsPath()).mountLabel(in.mountLabel()).processLabel(in.processLabel()).node(in.node().orNull()); } }
public Container build() { return Container.create(id, created, path, name, args, config, state, image, networkSettings, sysInitPath, resolvConfPath, volumes, hostConfig, driver, execDriver, volumesRW, command, status, ports, hostnamePath, hostsPath, mountLabel, processLabel, node); }
@Override public Optional<Integer> apply(Container container) { if (container.networkSettings() != null) { Map<String, List<Map<String, String>>> ports = container.networkSettings().ports(); if (ports != null && ports.containsKey(containerPort + "/tcp")) { return Optional.of(Integer.parseInt(getOnlyElement(ports.get(containerPort + "/tcp")).get("HostPort"))); } // this is needed in case the container list is coming from // listContainers } else if (container.ports() != null) { for (Port port : container.ports()) { if (port.privatePort() == containerPort) { return Optional.of(port.publicPort()); } } } return Optional.absent(); }
@Override public NodeMetadata apply(Container container) { String name = cleanUpName(container.name()); String group = nodeNamingConvention.extractGroup(name); NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(container.id()) .name(name) .group(group) .hostname(container.config().hostname()) // TODO Set up hardware .hardware(new HardwareBuilder() .id("") .ram(container.config().memory()) .processor(new Processor(container.config().cpuShares(), container.config().cpuShares())) .build()); builder.status(toPortableStatus.apply(container.state())); builder.loginPort(loginPortForContainer.apply(container).or(NO_LOGIN_PORT)); builder.publicAddresses(getPublicIpAddresses(container)); builder.privateAddresses(getPrivateIpAddresses(container)); builder.location(Iterables.getOnlyElement(locations.get())); String imageId = container.image(); builder.imageId(imageId); if (images.get().containsKey(imageId)) { Image image = images.get().get(imageId); builder.operatingSystem(image.getOperatingSystem()); } return builder.build(); }
@Test(dependsOnMethods = "testAttachContainerToNetwork") public void testDisconnectContainerFromNetwork() { api().disconnectContainerFromNetwork(network.id(), container.id()); container = api.getContainerApi().inspectContainer(container.id()); assertFalse(Iterables.any(container.networkSettings().networks().keySet(), Predicates.equalTo(network.name()))); }
private Iterable<String> getPrivateIpAddresses(Container container) { // A container can be attached to multiple networks. It can therefore have multiple private // IPs. The NetworkSettings.ipAddress might in fact be blank, with the only IP being on // network objects. if (container.networkSettings() == null) return ImmutableList.of(); ImmutableSet.Builder<String> builder = ImmutableSet.<String>builder(); NetworkSettings settings = container.networkSettings(); if (settings.ipAddress() != null && settings.ipAddress().length() > 0) { builder.add(settings.ipAddress()); } if (settings.networks() != null) { for (Map.Entry<String, NetworkSettings.Details> entry : settings.networks().entrySet()) { String ipAddress = entry.getValue().ipAddress(); if (ipAddress != null && ipAddress.length() > 0) { builder.add(ipAddress); } } } return builder.build(); }
@Override public boolean apply(String input) { return container.config().image().matches(input); } });
public void testVirtualMachineWithNetworksToNodeMetadata() { Container containerWithNetwork = container.toBuilder() .networkSettings(container.networkSettings().toBuilder() .networks(ImmutableMap.<String, NetworkSettings.Details>builder() .put("JCLOUDS_NETWORK", NetworkSettings.Details.builder()
@Override public NodeMetadata apply(Container container) { String name = cleanUpName(container.name()); String group = nodeNamingConvention.extractGroup(name); NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(container.id()) .name(name) .group(group) .hostname(container.config().hostname()) // TODO Set up hardware .hardware(new HardwareBuilder() .id("") .ram(container.config().memory()) .processor(new Processor(container.config().cpuShares(), container.config().cpuShares())) .build()); builder.status(toPortableStatus.apply(container.state())); builder.loginPort(loginPortForContainer.apply(container).or(NO_LOGIN_PORT)); builder.publicAddresses(getPublicIpAddresses(container)); builder.privateAddresses(getPrivateIpAddresses(container)); builder.location(Iterables.getOnlyElement(locations.get())); String imageId = container.image(); builder.imageId(imageId); if (images.get().containsKey(imageId)) { Image image = images.get().get(imageId); builder.operatingSystem(image.getOperatingSystem()); } return builder.build(); }
@Override public Optional<Integer> apply(Container container) { if (container.networkSettings() != null) { Map<String, List<Map<String, String>>> ports = container.networkSettings().ports(); if (ports != null && ports.containsKey(containerPort + "/tcp")) { return Optional.of(Integer.parseInt(getOnlyElement(ports.get(containerPort + "/tcp")).get("HostPort"))); } // this is needed in case the container list is coming from // listContainers } else if (container.ports() != null) { for (Port port : container.ports()) { if (port.privatePort() == containerPort) { return Optional.of(port.publicPort()); } } } return Optional.absent(); }
@Test(dependsOnMethods = "testGetNetwork") public void testAttachContainerToNetwork() { api().connectContainerToNetwork(network.id(), container.id()); container = api.getContainerApi().inspectContainer(container.id()); assertTrue(Iterables.any(container.networkSettings().networks().keySet(), Predicates.equalTo(network.name()))); }
private Iterable<String> getPrivateIpAddresses(Container container) { // A container can be attached to multiple networks. It can therefore have multiple private // IPs. The NetworkSettings.ipAddress might in fact be blank, with the only IP being on // network objects. if (container.networkSettings() == null) return ImmutableList.of(); ImmutableSet.Builder<String> builder = ImmutableSet.<String>builder(); NetworkSettings settings = container.networkSettings(); if (settings.ipAddress() != null && settings.ipAddress().length() > 0) { builder.add(settings.ipAddress()); } if (settings.networks() != null) { for (Map.Entry<String, NetworkSettings.Details> entry : settings.networks().entrySet()) { String ipAddress = entry.getValue().ipAddress(); if (ipAddress != null && ipAddress.length() > 0) { builder.add(ipAddress); } } } return builder.build(); }
@Override public boolean apply(String input) { return container.config().image().matches(input); } });