Examples of GoogleComputeEngineTemplateOptions


Examples of org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions

              .build();


      ComputeService computeService = orderedRequestsSendResponses(orderedRequests, orderedResponses);

      GoogleComputeEngineTemplateOptions options = computeService.templateOptions().as(GoogleComputeEngineTemplateOptions.class);

      getOnlyElement(computeService.createNodesInGroup("test", 1, options));
   }
View Full Code Here

Examples of org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions

   public NodeAndInitialCredentials<Instance> createNodeWithGroupEncodedIntoName(
           final String group, final String name, Template template) {

      checkNotNull(template, "template");

      GoogleComputeEngineTemplateOptions options = GoogleComputeEngineTemplateOptions.class.cast(template.getOptions()).clone();
      checkState(options.getNetwork().isPresent(), "network was not present in template options");
      Hardware hardware = checkNotNull(template.getHardware(), "hardware must be set");
      URI machineType = checkNotNull(hardware.getUri(), "hardware uri must be set");

      InstanceTemplate instanceTemplate = InstanceTemplate.builder()
              .forMachineType(machineType);

      if (options.isEnableNat()) {
         instanceTemplate.addNetworkInterface(options.getNetwork().get(), Type.ONE_TO_ONE_NAT);
      } else {
         instanceTemplate.addNetworkInterface(options.getNetwork().get());
      }

      LoginCredentials credentials = getFromImageAndOverrideIfRequired(template.getImage(), options);

      ImmutableMap.Builder<String, String> metadataBuilder = metatadaFromTemplateOptions.apply(options);
      instanceTemplate.metadata(metadataBuilder.build());
      instanceTemplate.tags(options.getTags());
      instanceTemplate.serviceAccounts(options.getServiceAccounts());
      instanceTemplate.image(checkNotNull(template.getImage().getUri(), "image URI is null"));

      Operation operation = api.getInstanceApiForProject(userProject.get())
              .createInZone(name, instanceTemplate, template.getLocation().getId());

      if (options.shouldBlockUntilRunning()) {
         waitOperationDone(operation);
      }

      // some times the newly created instances are not immediately returned
      AtomicReference<Instance> instance = new AtomicReference<Instance>();
View Full Code Here

Examples of org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions

                                                              Map<NodeMetadata, Exception> badNodes,
                                                              Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {

      String sharedResourceName = namingConvention.create().sharedNameForGroup(group);
      Template mutableTemplate = template.clone();
      GoogleComputeEngineTemplateOptions templateOptions = GoogleComputeEngineTemplateOptions.class.cast(mutableTemplate
              .getOptions());
      assert template.getOptions().equals(templateOptions) : "options didn't clone properly";

      // get or create the network and create a firewall with the users configuration
      Network network = getOrCreateNetwork(templateOptions, sharedResourceName);
      getOrCreateFirewall(templateOptions, network, sharedResourceName);
      templateOptions.network(network.getSelfLink());

      return super.execute(group, count, mutableTemplate, goodNodes, badNodes, customizationResponses);
   }
View Full Code Here

Examples of org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions

   public NodeAndInitialCredentials<InstanceInZone> createNodeWithGroupEncodedIntoName(
           final String group, final String name, final Template template) {

      checkNotNull(template, "template");

      GoogleComputeEngineTemplateOptions options = GoogleComputeEngineTemplateOptions.class.cast(template.getOptions()).clone();
      checkState(options.getNetwork().isPresent(), "network was not present in template options");
      Hardware hardware = checkNotNull(template.getHardware(), "hardware must be set");

      checkNotNull(hardware.getUri(), "hardware must have a URI");
      checkNotNull(template.getImage().getUri(), "image URI is null");

      // Note that the ordering is significant here - the first disk must be the boot disk.
      List<PersistentDisk> disks = Lists.newArrayList();

      if (!tryFind(options.getDisks(), isBootDisk()).isPresent()) {
         Disk bootDisk = createBootDisk(template, name);

         disks.add(new PersistentDisk(Mode.READ_WRITE,
                                      bootDisk.getSelfLink(),
                                      null,
                                      true,
                                      true));
      }

      disks.addAll(options.getDisks());

      InstanceTemplate instanceTemplate = InstanceTemplate.builder()
              .forMachineType(hardware.getUri());

      if (options.isEnableNat()) {
         instanceTemplate.addNetworkInterface(options.getNetwork().get(), Type.ONE_TO_ONE_NAT);
      } else {
         instanceTemplate.addNetworkInterface(options.getNetwork().get());
      }

      instanceTemplate.disks(disks);

      LoginCredentials credentials = getFromImageAndOverrideIfRequired(template.getImage(), options);

      ImmutableMap.Builder<String, String> metadataBuilder = metatadaFromTemplateOptions.apply(options);

      metadataBuilder.put(GCE_IMAGE_METADATA_KEY, template.getImage().getUri().toString());

      if (!options.shouldKeepBootDisk()) {
         metadataBuilder.put(GCE_DELETE_BOOT_DISK_METADATA_KEY, Boolean.TRUE.toString());
      }

      instanceTemplate.metadata(metadataBuilder.build());
      instanceTemplate.serviceAccounts(options.getServiceAccounts());

      final InstanceApi instanceApi = api.getInstanceApiForProject(userProject.get());
      final String zone = template.getLocation().getId();
      Operation operation = instanceApi.createInZone(name, zone, instanceTemplate);

      if (options.shouldBlockUntilRunning()) {
         waitOperationDone(operation);
      }

      // some times the newly created instances are not immediately returned
      AtomicReference<Instance> instance = Atomics.newReference();

      retry(new Predicate<AtomicReference<Instance>>() {
         @Override
         public boolean apply(AtomicReference<Instance> input) {
            input.set(instanceApi.getInZone(zone, name));
            return input.get() != null;
         }
      }, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(instance);

      if (!options.getTags().isEmpty()) {
         Operation tagsOperation = instanceApi.setTagsInZone(zone,
                 name, options.getTags(), instance.get().getTags().getFingerprint());

         waitOperationDone(tagsOperation);

         retry(new Predicate<AtomicReference<Instance>>() {
            @Override
            public boolean apply(AtomicReference<Instance> input) {
               input.set(instanceApi.getInZone(zone, name));
               return input.get() != null;
            }
         }, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(instance);
      }

      // Add tags for security groups
      final FirewallTagNamingConvention naming = firewallTagNamingConvention.get(group);
      Set<String> tags = FluentIterable.from(Ints.asList(options.getInboundPorts()))
              .transform(new Function<Integer, String>(){
                       @Override
                       public String apply(Integer input) {
                          return input != null
                                  ? naming.name(input)
View Full Code Here

Examples of org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions

   }

   private Disk createBootDisk(Template template, String instanceName) {
      URI imageUri = template.getImage().getUri();

      GoogleComputeEngineTemplateOptions options = GoogleComputeEngineTemplateOptions.class.cast(template.getOptions()).clone();

      int diskSize = options.getBootDiskSize().or(10l).intValue();

      String diskName = instanceName + "-" + GCE_BOOT_DISK_SUFFIX;

      Operation diskOperation = api.getDiskApiForProject(userProject.get())
                                   .createFromImageWithSizeInZone(imageUri.toString(),
View Full Code Here

Examples of org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions

              .build();


      ComputeService computeService = orderedRequestsSendResponses(orderedRequests, orderedResponses);

      GoogleComputeEngineTemplateOptions options = computeService.templateOptions().as(GoogleComputeEngineTemplateOptions.class);
      options.tags(ImmutableSet.of("aTag"));
      NodeMetadata node = getOnlyElement(computeService.createNodesInGroup("test", 1, options));
      assertEquals(node.getImageId(), "gcel-12-04-v20121106");
   }
View Full Code Here

Examples of org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions

                                                              Map<NodeMetadata, Exception> badNodes,
                                                              Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {

      String sharedResourceName = namingConvention.create().sharedNameForGroup(group);
      Template mutableTemplate = template.clone();
      GoogleComputeEngineTemplateOptions templateOptions = GoogleComputeEngineTemplateOptions.class.cast(mutableTemplate
              .getOptions());
      assert template.getOptions().equals(templateOptions) : "options didn't clone properly";

      // get or create the network and create a firewall with the users configuration
      Network network = getOrCreateNetwork(templateOptions, sharedResourceName);
      getOrCreateFirewalls(templateOptions, network, firewallTagNamingConvention.get(group));
      templateOptions.network(network.getSelfLink());
      templateOptions.userMetadata(ComputeServiceConstants.NODE_GROUP_KEY, group);

      return super.execute(group, count, mutableTemplate, goodNodes, badNodes, customizationResponses);
   }
View Full Code Here

Examples of org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions

              .build();


      ComputeService computeService = orderedRequestsSendResponses(orderedRequests, orderedResponses);

      GoogleComputeEngineTemplateOptions options = computeService.templateOptions().as(GoogleComputeEngineTemplateOptions.class);
      options.tags(ImmutableSet.of("aTag"));
      getOnlyElement(computeService.createNodesInGroup("test", 1, options));
   }
View Full Code Here

Examples of org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions

   public NodeAndInitialCredentials<InstanceInZone> createNodeWithGroupEncodedIntoName(
           final String group, final String name, final Template template) {

      checkNotNull(template, "template");

      GoogleComputeEngineTemplateOptions options = GoogleComputeEngineTemplateOptions.class.cast(template.getOptions()).clone();
      checkState(options.getNetwork().isPresent(), "network was not present in template options");
      Hardware hardware = checkNotNull(template.getHardware(), "hardware must be set");

      checkNotNull(hardware.getUri(), "hardware must have a URI");

      InstanceTemplate instanceTemplate = InstanceTemplate.builder()
              .forMachineType(hardware.getUri());

      if (options.isEnableNat()) {
         instanceTemplate.addNetworkInterface(options.getNetwork().get(), Type.ONE_TO_ONE_NAT);
      } else {
         instanceTemplate.addNetworkInterface(options.getNetwork().get());
      }

      LoginCredentials credentials = getFromImageAndOverrideIfRequired(template.getImage(), options);

      ImmutableMap.Builder<String, String> metadataBuilder = metatadaFromTemplateOptions.apply(options);
      instanceTemplate.metadata(metadataBuilder.build());
      instanceTemplate.serviceAccounts(options.getServiceAccounts());
      instanceTemplate.image(checkNotNull(template.getImage().getUri(), "image URI is null"));

      Operation operation = api.getInstanceApiForProject(userProject.get())
              .createInZone(name, template.getLocation().getId(), instanceTemplate);

      if (options.shouldBlockUntilRunning()) {
         waitOperationDone(operation);
      }

      // some times the newly created instances are not immediately returned
      AtomicReference<Instance> instance = new AtomicReference<Instance>();

      retry(new Predicate<AtomicReference<Instance>>() {
         @Override
         public boolean apply(AtomicReference<Instance> input) {
            input.set(api.getInstanceApiForProject(userProject.get()).getInZone(template.getLocation().getId(),
                    name));
            return input.get() != null;
         }
      }, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(instance);

      if (options.getTags().size() > 0) {
         Operation tagsOperation = api.getInstanceApiForProject(userProject.get()).setTagsInZone(template.getLocation().getId(),
                 name, options.getTags(), instance.get().getTags().getFingerprint());

         waitOperationDone(tagsOperation);

         retry(new Predicate<AtomicReference<Instance>>() {
            @Override
View Full Code Here

Examples of org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions

                                                              Map<NodeMetadata, Exception> badNodes,
                                                              Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {

      String sharedResourceName = namingConvention.create().sharedNameForGroup(group);
      Template mutableTemplate = template.clone();
      GoogleComputeEngineTemplateOptions templateOptions = GoogleComputeEngineTemplateOptions.class.cast(mutableTemplate
              .getOptions());
      assert template.getOptions().equals(templateOptions) : "options didn't clone properly";

      // get or create the network and create a firewall with the users configuration
      Network network = getOrCreateNetwork(templateOptions, sharedResourceName);
      getOrCreateFirewall(templateOptions, network, sharedResourceName);
      templateOptions.network(network.getSelfLink());

      return super.execute(group, count, mutableTemplate, goodNodes, badNodes, customizationResponses);
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.