private org.jclouds.openstack.neutron.v2.domain.FloatingIP createFloatingIpUsingNeutron(org.jclouds.openstack.neutron.v2.features.FloatingIPApi neutronFloatingApi, NodeMetadata node, Optional<Set<String>> poolNames, final String availabilityZone) { String regionId = node.getLocation().getParent().getId(); List<Network> networks = getSuitableNetworks(regionId, availabilityZone, poolNames.or(Sets.<String>newHashSet())); org.jclouds.openstack.neutron.v2.domain.FloatingIP floatingIP = null; for (Network network : networks) { try { logger.debug(">> allocating floating IP from network %s for node(%s)", network, node); org.jclouds.openstack.neutron.v2.domain.FloatingIP createFloatingIP = org.jclouds.openstack.neutron.v2.domain.FloatingIP.CreateFloatingIP.createBuilder(network.getId()).availabilityZone(network.getAvailabilityZone()).build(); floatingIP = neutronFloatingApi.create((org.jclouds.openstack.neutron.v2.domain.FloatingIP.CreateFloatingIP) createFloatingIP); logger.debug(">> allocated floating IP(%s) from network(%s) for node(%s)", floatingIP, network, node); floatingIpCache.asMap().put(RegionAndId.fromSlashEncoded(node.getId()), ImmutableList.of(FloatingIpForServer.create(RegionAndId.fromSlashEncoded(node.getId()), floatingIP.getId(), floatingIP.getFloatingIpAddress()))); return floatingIP; } catch (Exception ex) { logger.trace("<< [%s] failed to allocate a floating IP from network %s for node(%s)", ex.getMessage(), network, node); } } throw new IllegalStateException("Failed to allocate a floating IP for node " + node + ".\n" + "Failed to find suitable external networks or to allocate from poolNames specified: " + Iterables.toString(poolNames.get())); }
private org.jclouds.openstack.neutron.v2.domain.FloatingIP createFloatingIpUsingNeutron(org.jclouds.openstack.neutron.v2.features.FloatingIPApi neutronFloatingApi, NodeMetadata node, Optional<Set<String>> poolNames, final String availabilityZone) { String regionId = node.getLocation().getParent().getId(); List<Network> networks = getSuitableNetworks(regionId, availabilityZone, poolNames.or(Sets.<String>newHashSet())); org.jclouds.openstack.neutron.v2.domain.FloatingIP floatingIP = null; for (Network network : networks) { try { logger.debug(">> allocating floating IP from network %s for node(%s)", network, node); org.jclouds.openstack.neutron.v2.domain.FloatingIP createFloatingIP = org.jclouds.openstack.neutron.v2.domain.FloatingIP.CreateFloatingIP.createBuilder(network.getId()).availabilityZone(network.getAvailabilityZone()).build(); floatingIP = neutronFloatingApi.create((org.jclouds.openstack.neutron.v2.domain.FloatingIP.CreateFloatingIP) createFloatingIP); logger.debug(">> allocated floating IP(%s) from network(%s) for node(%s)", floatingIP, network, node); floatingIpCache.asMap().put(RegionAndId.fromSlashEncoded(node.getId()), ImmutableList.of(FloatingIpForServer.create(RegionAndId.fromSlashEncoded(node.getId()), floatingIP.getId(), floatingIP.getFloatingIpAddress()))); return floatingIP; } catch (Exception ex) { logger.trace("<< [%s] failed to allocate a floating IP from network %s for node(%s)", ex.getMessage(), network, node); } } throw new IllegalStateException("Failed to allocate a floating IP for node " + node + ".\n" + "Failed to find suitable external networks or to allocate from poolNames specified: " + Iterables.toString(poolNames.get())); }
public void testCreateUpdateAndDeleteFloatingIP() { for (String region : api.getConfiguredRegions()) { FloatingIPApi floatingIPApi = api.getFloatingIPApi(region); NetworkApi networkApi = api.getNetworkApi(region); FloatingIP floatingIPGet = null; Network network; try { network = networkApi.list().concat().firstMatch(new Predicate<Network>() { @Override public boolean apply(Network input) { return input.getExternal(); } }).orNull(); if (network == null) Assert.fail("Cannot find a suitable external network. Please add it manually or contact your administrator"); FloatingIP floatingIP = floatingIPApi.create(FloatingIP.createBuilder(network.getId()).availabilityZone(network.getAvailabilityZone()).build()); /* List and Get test */ Set<FloatingIP> floatingIPs = floatingIPApi.list().concat().toSet(); floatingIPGet = floatingIPApi.get(floatingIP.getId()); assertNotNull(floatingIPGet); assertTrue(floatingIPs.contains(floatingIP)); } finally { assertTrue(floatingIPApi.delete(floatingIPGet.getId())); } } }