@Override public ZoneAndId apply(ZoneAndId id) { FloatingIPApi floatingIpApi = novaApi.getFloatingIPExtensionForZone(id.getZone()).get(); for (FloatingIP ip : floatingIpCache.getUnchecked(id)) { logger.debug(">> removing floatingIp(%s) from node(%s)", ip, id); floatingIpApi.removeFromServer(ip.getIp(), id.getId()); logger.debug(">> deallocating floatingIp(%s)", ip); floatingIpApi.delete(ip.getId()); } floatingIpCache.invalidate(id); return id; }
@Override public ZoneAndId apply(ZoneAndId id) { FloatingIPApi floatingIpApi = novaApi.getFloatingIPExtensionForZone(id.getZone()).get(); for (FloatingIP ip : floatingIpCache.getUnchecked(id)) { logger.debug(">> removing floatingIp(%s) from node(%s)", ip, id); floatingIpApi.removeFromServer(ip.getIp(), id.getId()); logger.debug(">> deallocating floatingIp(%s)", ip); floatingIpApi.delete(ip.getId()); } floatingIpCache.invalidate(id); return id; }
@Override public ZoneAndId apply(ZoneAndId id) { FloatingIPApi floatingIpApi = novaApi.getFloatingIPExtensionForZone(id.getZone()).get(); for (FloatingIP ip : floatingIpCache.getUnchecked(id)) { logger.debug(">> removing floatingIp(%s) from node(%s)", ip, id); floatingIpApi.removeFromServer(ip.getIp(), id.getId()); logger.debug(">> deallocating floatingIp(%s)", ip); floatingIpApi.delete(ip.getId()); } floatingIpCache.invalidate(id); return id; }
@Override public RegionAndId apply(RegionAndId id) { FloatingIPApi floatingIpApi = novaApi.getFloatingIPApi(id.getRegion()).get(); for (FloatingIP ip : floatingIpCache.getUnchecked(id)) { logger.debug(">> removing floatingIp(%s) from node(%s)", ip, id); floatingIpApi.removeFromServer(ip.getIp(), id.getId()); logger.debug(">> deallocating floatingIp(%s)", ip); floatingIpApi.delete(ip.getId()); } floatingIpCache.invalidate(id); return id; }
@Override public RegionAndId apply(RegionAndId id) { if (isNeutronLinked()) { for (FloatingIpForServer floatingIpForServer : floatingIpCache.getUnchecked(id)) { logger.debug(">> deallocating floatingIp(%s)", floatingIpForServer); getFloatingIPApi(id.getRegion()).delete(floatingIpForServer.floatingIpId()); } } else { // try nova FloatingIPApi floatingIpApi = novaApi.getFloatingIPApi(id.getRegion()).get(); for (FloatingIpForServer floatingIpForServer : floatingIpCache.getUnchecked(id)) { logger.debug(">> removing floatingIp(%s) from node(%s)", floatingIpForServer, id); floatingIpApi.removeFromServer(floatingIpForServer.ip(), id.getId()); logger.debug(">> deallocating floatingIp(%s)", floatingIpForServer); floatingIpApi.delete(floatingIpForServer.floatingIpId()); } } floatingIpCache.invalidate(id); return id; }
@Override public RegionAndId apply(RegionAndId id) { if (isNeutronLinked()) { for (FloatingIpForServer floatingIpForServer : floatingIpCache.getUnchecked(id)) { logger.debug(">> deallocating floatingIp(%s)", floatingIpForServer); getFloatingIPApi(id.getRegion()).delete(floatingIpForServer.floatingIpId()); } } else { // try nova FloatingIPApi floatingIpApi = novaApi.getFloatingIPApi(id.getRegion()).get(); for (FloatingIpForServer floatingIpForServer : floatingIpCache.getUnchecked(id)) { logger.debug(">> removing floatingIp(%s) from node(%s)", floatingIpForServer, id); floatingIpApi.removeFromServer(floatingIpForServer.ip(), id.getId()); logger.debug(">> deallocating floatingIp(%s)", floatingIpForServer); floatingIpApi.delete(floatingIpForServer.floatingIpId()); } } floatingIpCache.invalidate(id); return id; }
@Test public void testAddAndRemoveFloatingIp() throws Exception { for (String zoneId : api.getConfiguredZones()) { Optional<? extends FloatingIPApi> apiOption = api.getFloatingIPExtensionForZone(zoneId); if (!apiOption.isPresent()) continue; FloatingIPApi api = apiOption.get(); ServerApi serverApi = this.api.getServerApiForZone(zoneId); Server server = createServerInZone(zoneId); FloatingIP floatingIP = api.create(); assertNotNull(floatingIP); try { api.addToServer(floatingIP.getIp(), server.getId()); assertEventually(new ServerHasFloatingIP(serverApi, server.getId(), floatingIP.getIp())); } finally { api.removeFromServer(floatingIP.getIp(), server.getId()); serverApi.delete(server.getId()); } } }
@Test public void testAddAndRemoveFloatingIp() throws Exception { for (String regionId : api.getConfiguredRegions()) { Optional<? extends FloatingIPApi> apiOption = api.getFloatingIPApi(regionId); if (!apiOption.isPresent()) continue; FloatingIPApi api = apiOption.get(); ServerApi serverApi = this.api.getServerApi(regionId); Server server = createServerInRegion(regionId); FloatingIP floatingIP = api.create(); assertNotNull(floatingIP); try { api.addToServer(floatingIP.getIp(), server.getId()); assertEventually(new ServerHasFloatingIP(serverApi, server.getId(), floatingIP.getIp())); } finally { api.removeFromServer(floatingIP.getIp(), server.getId()); serverApi.delete(server.getId()); } } }