/** * The list locations command returns all the valid locations for nodes. A location has a scope, * which is typically region or zone. A region is a general area, like eu-west, where a zone is * similar to a datacenter. If a location has a parent, that implies it is within that location. * For example a location can be a rack, whose parent is likely to be a zone. */ @Override public Set<? extends Location> listAssignableLocations() { return computeService.listAssignableLocations(); }
/** * The list locations command returns all the valid locations for nodes. A location has a scope, * which is typically region or zone. A region is a general area, like eu-west, where a zone is * similar to a datacenter. If a location has a parent, that implies it is within that location. * For example a location can be a rack, whose parent is likely to be a zone. */ @Override public Set<? extends Location> listAssignableLocations() { return computeService.listAssignableLocations(); }
public void showLocations() { Set<? extends Location> locations = computeService.listAssignableLocations(); for (Location location : locations) { System.out.println(location); } }
@Override public Set<? extends Location> listAssignableLocations() { return delegate.listAssignableLocations(); }
@Override public void updateOnAdded(ComputeService computeService) { if (computeService != null) { Set<? extends Location> locations = computeService.listAssignableLocations(); if (locations != null) { for (Location location : locations) { for (String cacheKey : ServiceHelper.findCacheKeysForService(computeService)) { cache.put(cacheKey, location.getId()); } } } } } }
protected Set<? extends Location> getAllLocations(ComputeService computeService) { Set<Location> all = new HashSet<Location>(); for (Location loc : computeService.listAssignableLocations()) { for (Location p = loc; p != null; p = p.getParent()) { all.add(p); for (String cacheKey : ServiceHelper.findCacheKeysForService(computeService)) { cacheProvider.getProviderCacheForType(Constants.LOCATION_CACHE).put(cacheKey, p.getId()); } } } return all; }
protected void logAvailableTemplates(ConfigBag config) { LOG.info("Loading available images at "+this+" for reference..."); ConfigBag m1 = ConfigBag.newInstanceCopying(config); if (m1.containsKey(IMAGE_ID)) { // if caller specified an image ID, remove that, but don't apply default filters m1.remove(IMAGE_ID); // TODO use key m1.putStringKey("anyOwner", true); } ComputeService computeServiceLessRestrictive = JcloudsUtil.findComputeService(m1); Set<? extends Image> imgs = computeServiceLessRestrictive.listImages(); LOG.info(""+imgs.size()+" available images at "+this); for (Image img: imgs) { LOG.info(" Image: "+img); } Set<? extends Hardware> profiles = computeServiceLessRestrictive.listHardwareProfiles(); LOG.info(""+profiles.size()+" available profiles at "+this); for (Hardware profile: profiles) { LOG.info(" Profile: "+profile); } Set<? extends org.jclouds.domain.Location> assignableLocations = computeServiceLessRestrictive.listAssignableLocations(); LOG.info(""+assignableLocations.size()+" available locations at "+this); for (org.jclouds.domain.Location assignableLocation: assignableLocations) { LOG.info(" Location: "+assignableLocation); } }
public ListBoxModel doFillLocationIdItems( @RelativePath("..") @QueryParameter String providerName, @RelativePath("..") @QueryParameter String cloudCredentialsId, @RelativePath("..") @QueryParameter String endPointUrl, @RelativePath("..") @QueryParameter String zones) { ListBoxModel m = new ListBoxModel(); if (prepareListBoxModel(providerName, cloudCredentialsId, m)) { return m; } try (ComputeServiceContext ctx = getCtx(providerName, cloudCredentialsId, endPointUrl, zones)) { LocationHelper.fillLocations(m, ctx.getComputeService().listAssignableLocations()); } catch (Exception ex) { LOGGER.log(Level.SEVERE, ex.getMessage(), ex); } return m; }
@Test public void testAndExperiment() { ComputeServiceContext context = null; try { context = computeContextForKnownArgumentsAndConstantPassword(); assertEquals(context.getComputeService().listAssignableLocations().size(), 4); } finally { if (context != null) context.close(); } }
private void listLocations(ComputeService computeService) { log("list locations"); for (Location location : computeService.listAssignableLocations()) {// TODO log(String.format(" location id=%s, scope=%s, description=%s, parent=%s", location.getId(), location .getScope(), location.getDescription(), location.getParent())); } }
public void testListLocationsWhenResponseIs2xx() throws Exception { Map<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder() .put(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess) .put(extensionsOfNovaRequest, extensionsOfNovaResponse).put(listDetail, listDetailResponse) .put(listServers, listServersResponse).put(listFlavorsDetail, listFlavorsDetailResponse).build(); ComputeService apiWhenServersExist = requestsSendResponses(requestResponseMap); Set<? extends Location> locations = apiWhenServersExist.listAssignableLocations(); assertNotNull(locations); assertEquals(locations.size(), 1); assertEquals(locations.iterator().next().getId(), "az-1.region-a.geo-1"); assertNotNull(apiWhenServersExist.listNodes()); assertEquals(apiWhenServersExist.listNodes().size(), 1); assertEquals(apiWhenServersExist.listNodes().iterator().next().getId(), "az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f000004d2"); assertEquals(apiWhenServersExist.listNodes().iterator().next().getName(), "sample-server"); }
@Test public void testAndExperiment() { ComputeServiceContext context = null; try { context = computeContextForKnownArgumentsAndConstantPassword(); assertEquals(context.getComputeService().listAssignableLocations().size(), 4); } finally { if (context != null) context.close(); } }
public void testListLocationsWhenResponseIs2xx() throws Exception { Map<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder() .put(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess) .put(extensionsOfNovaRequest, extensionsOfNovaResponse).put(listDetail, listDetailResponse) .put(listServers, listServersResponse).put(listFlavorsDetail, listFlavorsDetailResponse).build(); ComputeService apiWhenServersExist = requestsSendResponses(requestResponseMap); Set<? extends Location> locations = apiWhenServersExist.listAssignableLocations(); assertNotNull(locations); assertEquals(locations.size(), 1); assertEquals(locations.iterator().next().getId(), "az-1.region-a.geo-1"); assertNotNull(apiWhenServersExist.listNodes()); assertEquals(apiWhenServersExist.listNodes().size(), 1); assertEquals(apiWhenServersExist.listNodes().iterator().next().getId(), "az-1.region-a.geo-1/71752"); assertEquals(apiWhenServersExist.listNodes().iterator().next().getName(), "sample-server"); }
private void assertNodesParse(String endpoint, ComputeServiceContext context) { try { Location providerLocation = expectedProviderLocationFromResource(endpoint); Supplier<LoadingCache<String, Node>> supplier = supplier(context); assertEquals(supplier.get().size(), context.getComputeService().listNodes().size()); assertEquals(supplier.get().asMap(), ImmutableMap.<String, Node> of(NodesFromYamlTest.TEST1.getId(), NodesFromYamlTest.TEST1)); assertEquals(context.getComputeService().listNodes().toString(), ImmutableSet.of(expectedNodeMetadataFromResource(endpoint)).toString()); assertEquals(context.getComputeService().listAssignableLocations(), ImmutableSet.of(providerLocation)); } finally { if (context != null) context.close(); } }
@Test public void testAndExperiment() { ComputeServiceContext context = null; try { context = ContextBuilder .newBuilder(new GleSYSProviderMetadata()) .overrides(setupProperties()) .modules(setupModules()).build(ComputeServiceContext.class); assertEquals(context.getComputeService().listAssignableLocations().size(), 4); } finally { Closeables.closeQuietly(context); } }
public void listAssignableLocations() throws Exception { server.enqueue(singleRegionSingleZoneResponse()); ComputeService computeService = computeService(); Set<? extends Location> locations = computeService.listAssignableLocations(); assertNotNull(locations); assertEquals(locations.size(), 1); Location firstZone = locations.iterator().next(); assertEquals(firstZone.getId(), "us-central1-a"); assertEquals(firstZone.getDescription(), url("/projects/party/zones/us-central1-a")); assertEquals(firstZone.getScope(), LocationScope.ZONE); assertEquals(firstZone.getParent().getId(), "us-central1"); assertEquals(firstZone.getParent().getDescription(), url("/projects/party/regions/us-central1")); assertEquals(firstZone.getParent().getScope(), LocationScope.REGION); // Google intentionally does not document locations! assertTrue(firstZone.getIso3166Codes().isEmpty()); assertTrue(firstZone.getParent().getIso3166Codes().isEmpty()); assertSent(server, "GET", "/projects/party/regions"); }
@Test(enabled = true, dependsOnMethods = "testCreateTwoNodesWithRunScript") public void testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired() throws Exception { initializeContext(); Location existingLocation = Iterables.get(this.nodes, 0).getLocation(); boolean existingLocationIsAssignable = Iterables.any(client.listAssignableLocations(), Predicates.equalTo(existingLocation)); if (existingLocationIsAssignable) { getAnonymousLogger().info("creating another node based on existing nodes' location: " + existingLocation); template = addRunScriptToTemplate(client.templateBuilder().fromTemplate(template) .locationId(existingLocation.getId()).build()); } else { refreshTemplate(); getAnonymousLogger().info( format("%s is not assignable; using template's location %s as ", existingLocation, template.getLocation())); } Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, template); assertEquals(nodes.size(), 1); checkNodes(nodes, group, "bootstrap"); NodeMetadata node = Iterables.getOnlyElement(nodes); if (existingLocationIsAssignable) assertEquals(node.getLocation(), existingLocation); else this.assertLocationSameOrChild(checkNotNull(node.getLocation(), "location of %s", node), template.getLocation()); checkOsMatchesTemplate(node); this.nodes.add(node); }
@Test public void testAndExperiment() { ComputeServiceContext context = null; try { context = ContextBuilder .newBuilder(new GleSYSProviderMetadata()) .overrides(setupProperties()) .modules(setupModules()).build(ComputeServiceContext.class); assertEquals(context.getComputeService().listAssignableLocations().size(), 4); } finally { Closeables2.closeQuietly(context); } }
@Override public void provisionNetwork(VirtualNetwork network) { String name = network.config().get(VirtualNetwork.NETWORK_ID); SecurityGroupExtension extension = location.getComputeService().getSecurityGroupExtension().get(); Set<SecurityGroup> groups = extension.listSecurityGroups(); String id = null; // Look for existing security group with the desired name for (SecurityGroup each : groups) { if (each.getName().equalsIgnoreCase(name)) { id = each.getId(); break; } } // If not found then create a new group if (id == null) { Location region = location.getComputeService().listAssignableLocations().iterator().next(); SecurityGroup added = extension.createSecurityGroup(name, region); id = added.getId(); IpPermission rules = IpPermission.builder() .cidrBlock(network.config().get(VirtualNetwork.NETWORK_CIDR).toString()) .ipProtocol(IpProtocol.TCP) .fromPort(1) .toPort(65535) .build(); extension.addIpPermission(rules, added); LOG.info("Added new security group {} with ID {}: {}", new Object[] { added.getName(), id, rules.toString() }); } // Use the OpenStack UUID as the virtual network id network.sensors().set(VirtualNetwork.NETWORK_ID, id); }
@Test(groups = { "integration", "live" }) public void testGetAssignableLocations() throws Exception { for (Location location : client.listAssignableLocations()) { getAnonymousLogger().warning("location " + location); assert location.getId() != null : location;