/** * No-parameters constructor. * */ private Builder() { floatingIP = new FloatingIP(); }
@Override public boolean apply(@Nullable org.jclouds.openstack.neutron.v2.domain.FloatingIP input) { return input.getPortId() == null && input.getAvailabilityZone().equals(availabilityZone); } });
public void testGetFloatingIP() throws IOException, InterruptedException, URISyntaxException { MockWebServer server = mockOpenStackServer(); server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); server.enqueue(addCommonHeaders( new MockResponse().setResponseCode(201).setBody(stringFromResource("/floatingip_get_response.json")))); try { NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); FloatingIPApi api = neutronApi.getFloatingIPApi("RegionOne"); FloatingIP floatingIP = api.get("12345"); /* * Check request */ assertEquals(server.getRequestCount(), 2); assertAuthentication(server); assertRequest(server.takeRequest(), "GET", uriApiVersion + "/floatingips/12345"); /* * Check response */ assertNotNull(floatingIP); assertEquals(floatingIP.getId(), "2f245a7b-796b-4f26-9cf9-9e82d248fda7"); assertEquals(floatingIP.getPortId(), "ce705c24-c1ef-408a-bda3-7bbd946164ab"); assertEquals(floatingIP.getFloatingIpAddress(), "172.24.4.228"); assertEquals(floatingIP.getFixedIpAddress(), "10.0.0.3"); assertEquals(floatingIP.getFloatingNetworkId(), "376da547-b977-4cfe-9cba-275c80debf57"); assertEquals(floatingIP.getRouterId(), "d23abc8d-2991-4a55-ba98-2aaea84cc72f"); assertEquals(floatingIP.getTenantId(), "4969c491a3c74ee4af974e6d800c62de"); } finally { server.shutdown(); } }
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 testUpdateFloatingIPDissociate() throws IOException, InterruptedException, URISyntaxException { MockWebServer server = mockOpenStackServer(); server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); server.enqueue(addCommonHeaders( new MockResponse().setResponseCode(201).setBody(stringFromResource("/floatingip_update_dissociate_response.json")))); try { NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); FloatingIPApi api = neutronApi.getFloatingIPApi("RegionOne"); FloatingIP.UpdateFloatingIP updateFloatingIP = FloatingIP.updateBuilder().build(); FloatingIP floatingIP = api.update("12345", updateFloatingIP); /* * Check request */ assertEquals(server.getRequestCount(), 2); assertAuthentication(server); assertRequest(server.takeRequest(), "PUT", uriApiVersion + "/floatingips/12345", "/floatingip_update_dissociate_request.json"); /* * Check response */ assertNotNull(floatingIP); assertNull(floatingIP.getPortId()); } finally { server.shutdown(); } }
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())); } } }
public void testListSpecificPageFloatingIP() throws IOException, InterruptedException, URISyntaxException { MockWebServer server = mockOpenStackServer(); server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/floatingip_list_response_paged1.json")))); try { NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); FloatingIPApi api = neutronApi.getFloatingIPApi("RegionOne"); FloatingIPs floatingIPs = api.list(PaginationOptions.Builder.limit(2).marker("abcdefg")); /* * Check request */ assertEquals(server.getRequestCount(), 2); assertAuthentication(server); assertRequest(server.takeRequest(), "GET", uriApiVersion + "/floatingips?limit=2&marker=abcdefg"); /* * Check response */ assertNotNull(floatingIPs); assertEquals(floatingIPs.size(), 2); assertEquals(floatingIPs.first().get().getId(), "2f245a7b-796b-4f26-9cf9-9e82d248fda7"); assertEquals(floatingIPs.get(1).getId(), "61cea855-49cb-4846-997d-801b70c71bdd"); } finally { server.shutdown(); } }
FloatingIPApi api = neutronApi.getFloatingIPApi("RegionOne"); FloatingIP.CreateFloatingIP createFip = FloatingIP.createBuilder("376da547-b977-4cfe-9cba-275c80debf57") .portId("ce705c24-c1ef-408a-bda3-7bbd946164ab") .build(); assertEquals(floatingIP.getRouterId(), "d23abc8d-2991-4a55-ba98-2aaea84cc72f"); assertEquals(floatingIP.getTenantId(), "4969c491a3c74ee4af974e6d800c62de"); assertEquals(floatingIP.getFloatingNetworkId(), "376da547-b977-4cfe-9cba-275c80debf57"); assertEquals(floatingIP.getFixedIpAddress(), "10.0.0.3"); assertEquals(floatingIP.getFloatingIpAddress(), "172.24.4.228"); assertEquals(floatingIP.getPortId(), "ce705c24-c1ef-408a-bda3-7bbd946164ab"); assertEquals(floatingIP.getId(), "2f245a7b-796b-4f26-9cf9-9e82d248fda7");
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 testUpdateFloatingIP() throws IOException, InterruptedException, URISyntaxException { MockWebServer server = mockOpenStackServer(); server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); server.enqueue(addCommonHeaders( new MockResponse().setResponseCode(201).setBody(stringFromResource("/floatingip_update_response.json")))); try { NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); FloatingIPApi api = neutronApi.getFloatingIPApi("RegionOne"); FloatingIP.UpdateFloatingIP updateFloatingIP = FloatingIP.updateBuilder() .portId("fc861431-0e6c-4842-a0ed-e2363f9bc3a8") .build(); FloatingIP floatingIP = api.update("12345", updateFloatingIP); /* * Check request */ assertEquals(server.getRequestCount(), 2); assertAuthentication(server); assertRequest(server.takeRequest(), "PUT", uriApiVersion + "/floatingips/12345", "/floatingip_update_request.json"); /* * Check response */ assertNotNull(floatingIP); assertEquals(floatingIP.getPortId(), "fc861431-0e6c-4842-a0ed-e2363f9bc3a8"); } finally { server.shutdown(); } }
public void testListPagedFloatingIP() throws IOException, InterruptedException, URISyntaxException { MockWebServer server = mockOpenStackServer(); server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/floatingip_list_response_paged1.json")))); server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/floatingip_list_response_paged2.json")))); try { NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); FloatingIPApi api = neutronApi.getFloatingIPApi("RegionOne"); // Note: Lazy! Have to actually look at the collection. List<FloatingIP> floatingIPs = api.list().concat().toList(); /* * Check request */ assertEquals(server.getRequestCount(), 3); assertAuthentication(server); assertRequest(server.takeRequest(), "GET", uriApiVersion + "/floatingips"); assertRequest(server.takeRequest(), "GET", uriApiVersion + "/floatingips?marker=71c1e68c-171a-4aa2-aca5-50ea153a3718"); /* * Check response */ assertNotNull(floatingIPs); assertEquals(floatingIPs.size(), 4); assertEquals(floatingIPs.get(0).getId(), "2f245a7b-796b-4f26-9cf9-9e82d248fda7"); assertEquals(floatingIPs.get(3).getId(), "61cea855-49cb-4846-997d-801b70c71bdd2"); } finally { server.shutdown(); } }
org.jclouds.openstack.neutron.v2.domain.FloatingIP ip = neutronFloatingApi.update(floatingIP.getId(), org.jclouds.openstack.neutron.v2.domain.FloatingIP.UpdateFloatingIP .updateBuilder() .build()); input.get().getNodeMetadata().set(NodeMetadataBuilder.fromNodeMetadata(node).publicAddresses(ImmutableSet.of(ip.getFloatingIpAddress())).build()); } else { logger.error("Node %s doesn't have a port to attach a floating IP", node);
@Override public boolean apply(@Nullable org.jclouds.openstack.neutron.v2.domain.FloatingIP input) { return input.getPortId() == null && input.getAvailabilityZone().equals(availabilityZone); } });
public void testListPagedFirewall() throws IOException, InterruptedException, URISyntaxException { MockWebServer server = mockOpenStackServer(); server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/floatingip_list_response_paged1.json")))); server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/floatingip_list_response_paged2.json")))); try { NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); FloatingIPApi api = neutronApi.getFloatingIPApi("RegionOne"); // Note: Lazy! Have to actually look at the collection. List<FloatingIP> floatingIPs = api.list().concat().toList(); /* * Check request */ assertEquals(server.getRequestCount(), 3); assertAuthentication(server); assertRequest(server.takeRequest(), "GET", uriApiVersion + "/floatingips"); assertRequest(server.takeRequest(), "GET", uriApiVersion + "/floatingips?marker=71c1e68c-171a-4aa2-aca5-50ea153a3718"); /* * Check response */ assertNotNull(floatingIPs); assertEquals(floatingIPs.size(), 4); assertEquals(floatingIPs.get(0).getId(), "2f245a7b-796b-4f26-9cf9-9e82d248fda7"); assertEquals(floatingIPs.get(3).getId(), "61cea855-49cb-4846-997d-801b70c71bdd2"); } finally { server.shutdown(); } }
/** * No-parameters constructor. * */ private Builder() { floatingIP = new FloatingIP(); }
org.jclouds.openstack.neutron.v2.domain.FloatingIP ip = neutronFloatingApi.update(floatingIP.getId(), org.jclouds.openstack.neutron.v2.domain.FloatingIP.UpdateFloatingIP .updateBuilder() .build()); input.get().getNodeMetadata().set(NodeMetadataBuilder.fromNodeMetadata(node).publicAddresses(ImmutableSet.of(ip.getFloatingIpAddress())).build()); } else { logger.error("Node %s doesn't have a port to attach a floating IP", node);