public static Maybe<String> findSubnetHostname(Iterable<? extends Location> ll) { Maybe<MachineLocation> l = findUniqueMachineLocation(ll); if (!l.isPresent()) { return Maybe.absent(); // throw new IllegalStateException("Cannot find hostname for among "+ll); } return Machines.getSubnetHostname(l.get()); }
@Test public void testSetPrivateIpToPublicIp() throws Exception { JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.of()); assertEquals(publicAddresses, machine.getPublicAddresses()); assertEquals(machine.getPublicAddresses().size(), 1); String publicAddress = machine.getPublicAddresses().iterator().next(); assertEquals(machine.getPrivateAddress().get(), publicAddress); assertEquals(machine.getSubnetHostname(), machine.getHostname()); assertEquals(machine.getSubnetIp(), publicAddress); assertEquals(Machines.getSubnetHostname(machine).get(), machine.getHostname()); assertEquals(Machines.getSubnetIp(machine).get(), publicAddress); assertEquals(machine.getPrivateAddresses().size(), 1); assertEquals(machine.getPrivateAddresses().iterator().next(), publicAddress); } }
@Test public void testConfigurePrivateAddresses() throws Exception { SshMachineLocation host2 = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .configure("address", Networking.getReachableLocalHost()) .configure(SshMachineLocation.PRIVATE_ADDRESSES, ImmutableList.of("1.2.3.4")) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)); assertEquals(host2.getPrivateAddresses(), ImmutableSet.of("1.2.3.4")); assertEquals(Machines.getSubnetIp(host2).get(), "1.2.3.4"); assertEquals(Machines.getSubnetHostname(host2).get(), "1.2.3.4"); }
Maybe<String> lh = Machines.getSubnetHostname(machine); Maybe<String> la = Machines.getSubnetIp(machine); if (lh.isPresent() && entity().sensors().get(Attributes.SUBNET_HOSTNAME) == null) {