Package org.jclouds.openstack.nova.v2_0.domain

Examples of org.jclouds.openstack.nova.v2_0.domain.Server$Builder


   public void testNewServerWithoutHostIdSetsZoneAsLocation() {

      Set<Image> images = ImmutableSet.<Image> of();
      Set<Hardware> hardwares = ImmutableSet.<Hardware> of();

      Server serverToConvert = expectedServer();

      ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");

      ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
               NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
                        .<Set<? extends Image>> ofInstance(images), Suppliers
                        .<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);

      NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);

      assertEquals(serverInZoneToConvert.slashEncode(), convertedNodeMetadata.getId());
      assertEquals(serverToConvert.getId(), convertedNodeMetadata.getProviderId());

      assertEquals(convertedNodeMetadata.getLocation(), zone);

      URI expectedURI = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/servers/71752");
      assertEquals(convertedNodeMetadata.getUri(), expectedURI);
View Full Code Here


      String imageId = template.getImage().getProviderId();
      String flavorId = template.getHardware().getProviderId();

      logger.debug(">> creating new server zone(%s) name(%s) image(%s) flavor(%s) options(%s)", zoneId, name, imageId, flavorId, options);
      ServerCreated lightweightServer = novaApi.getServerApiForZone(zoneId).create(name, imageId, flavorId, options);
      Server server = novaApi.getServerApiForZone(zoneId).get(lightweightServer.getId());

      logger.trace("<< server(%s)", server.getId());

      ServerInZone serverInZone = new ServerInZone(server, zoneId);
      if (!privateKey.isPresent() && lightweightServer.getAdminPass().isPresent())
         credentialsBuilder.password(lightweightServer.getAdminPass().get());
      return new NodeAndInitialCredentials<ServerInZone>(serverInZone, serverInZone.slashEncode(), credentialsBuilder
View Full Code Here

   }

   @Override
   public ServerInZone getNode(String id) {
      ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
      Server server = novaApi.getServerApiForZone(zoneAndId.getZone()).get(zoneAndId.getId());
      return server == null ? null : new ServerInZone(server, zoneAndId.getZone());
   }
View Full Code Here

   }

   @Override
   public ImageTemplate buildImageTemplateFromNode(String name, final String id) {
      ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
      Server server = novaApi.getServerApiForZone(zoneAndId.getZone()).get(zoneAndId.getId());
      if (server == null)
         throw new NoSuchElementException("Cannot find server with id: " + zoneAndId);
      CloneImageTemplate template = new ImageTemplateBuilder.CloneImageTemplateBuilder().nodeId(id).name(name).build();
      return template;
   }
View Full Code Here

   @Override
   public NodeMetadata apply(ServerInZone serverInZone) {
      Location zone = locationIndex.get().get(serverInZone.getZone());
      checkState(zone != null, "location %s not in locationIndex: %s", serverInZone.getZone(), locationIndex.get());
      Server from = serverInZone.getServer();

      NodeMetadataBuilder builder = new NodeMetadataBuilder();
      builder.id(serverInZone.slashEncode());
      builder.providerId(from.getId());
      builder.name(from.getName());
      builder.hostname(from.getName());
      builder.location(from.getHostId() != null ? new LocationBuilder().scope(LocationScope.HOST).id(from.getHostId())
            .description(from.getHostId()).parent(zone).build() : zone);
      builder.group(groupFromMapOrName(from.getMetadata(), from.getName(), nodeNamingConvention));
      addMetadataAndParseTagsFromCommaDelimitedValue(builder, from.getMetadata());
      builder.imageId(ZoneAndId.fromZoneAndId(serverInZone.getZone(), from.getImage().getId()).slashEncode());
      builder.operatingSystem(findOperatingSystemForServerOrNull(serverInZone));
      builder.hardware(findHardwareForServerOrNull(serverInZone));
      builder.status(toPortableNodeStatus.get(from.getStatus()));

      Set<Address> addresses = newHashSet(from.getAddresses().values());
      if (from.getAccessIPv4() != null) {
         addresses.add(createV4(from.getAccessIPv4()));
      }
      if (from.getAccessIPv6() != null) {
         addresses.add(createV6(from.getAccessIPv6()));
      }

      builder.publicAddresses(
            filter(
                  transform(
                        filter(addresses, not(isPrivateAddress)),
                        AddressToStringTransformationFunction.INSTANCE),
                  isInet4Address));

      builder.privateAddresses(
            filter(
                  transform(
                        filter(addresses, isPrivateAddress),
                        AddressToStringTransformationFunction.INSTANCE),
                  isInet4Address));

      for (Link link: from.getLinks()) {
         if (link.getRelation().equals(Link.Relation.SELF)) {
            builder.uri(link.getHref());
         }
      }
     
View Full Code Here

   @Singleton
   public static class ServerWithSecurityGroupsAdapter implements JsonDeserializer<ServerWithSecurityGroups> {
      @Override
      public ServerWithSecurityGroups deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
            throws JsonParseException {
         Server server = context.deserialize(jsonElement, Server.class);
         ServerWithSecurityGroups.Builder<?> result = ServerWithSecurityGroups.builder().fromServer(server);
         Set<String> names = Sets.newLinkedHashSet();
         if (jsonElement.getAsJsonObject().get("security_groups") != null) {
            JsonArray x = jsonElement.getAsJsonObject().get("security_groups").getAsJsonArray();
            for (JsonElement y : x) {
View Full Code Here

   @Singleton
   public static class ServerAdapter implements JsonDeserializer<Server> {
      @Override
      public Server deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
            throws JsonParseException {
         Server serverBase = apply((ServerInternal) context.deserialize(jsonElement, ServerInternal.class));
         Server.Builder<?> result = Server.builder().fromServer(serverBase);
         ServerExtendedStatus extendedStatus = context.deserialize(jsonElement, ServerExtendedStatus.class);
         if (!Objects.equal(extendedStatus, ServerExtendedStatus.builder().build())) {
            result.extendedStatus(extendedStatus);
         }
View Full Code Here

      NodeMetadata nodeMetadata = computeService.createNodesInGroup("jclouds-reverse-dns-test", 1, template).iterator().next();
      serverId = nodeMetadata.getId();
      serverURI = nodeMetadata.getUri();

      ServerApi serverApi = nova.getApi().getServerApiForZone(nodeMetadata.getLocation().getParent().getId());
      Server server = serverApi.get(nodeMetadata.getProviderId());
      serverIPv4 = server.getAccessIPv4();
      serverIPv6 = server.getAccessIPv6();
     
      System.out.println("serverURI = " + serverURI);
      System.out.println("serverIPv4 = " + serverIPv4);
      System.out.println("serverIPv6 = " + serverIPv6);
   }
View Full Code Here

      apiOption = api.getVirtualInterfaceExtensionForZone(zone);
   }

   public void testListVirtualInterfaces() {
      if (apiOption.isPresent()) {
         Server testServer = null;
         try {
            testServer = createServerInZone(zone);
            Set<? extends VirtualInterface> results = apiOption.get().listOnServer(testServer.getId()).toSet();
            for (VirtualInterface vif : results) {
               assertNotNull(vif.getId());
               assertNotNull(vif.getMacAddress());
            }
         } finally {
            if (testServer != null) {
               api.getServerApiForZone(zone).delete(testServer.getId());
            }
         }
   }
}
View Full Code Here

            assertEquals(serverWithGroups.getName(), server.getName());
            assertNotNull(serverWithGroups.getSecurityGroupNames());
         }

         // Create a new server to verify the groups work as expected
         Server testServer = null;
         try {
            testServer = createServerInZone(zone);
           
            ServerWithSecurityGroups results = apiOption.get().get(testServer.getId());
            assertEquals(results.getId(), testServer.getId());
            assertEquals(results.getSecurityGroupNames(), ImmutableSet.of("default"));
         } finally {
            if (testServer != null) {
               serverApi.delete(testServer.getId());
            }
         }
      }
   }
View Full Code Here

TOP

Related Classes of org.jclouds.openstack.nova.v2_0.domain.Server$Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.