Package org.jclouds.aws.ec2.options

Examples of org.jclouds.aws.ec2.options.AWSRunInstancesOptions


      this.createPlacementGroupIfNeeded = createPlacementGroupIfNeeded;
      this.importExistingKeyPair = importExistingKeyPair;
   }

   public AWSRunInstancesOptions execute(String region, String group, Template template) {
      AWSRunInstancesOptions instanceOptions = AWSRunInstancesOptions.class
            .cast(super.execute(region, group, template));

      String placementGroupName = template.getHardware().getId().startsWith("cc") ? createNewPlacementGroupUnlessUserSpecifiedOtherwise(
            region, group, template.getOptions()) : null;

      if (placementGroupName != null)
         instanceOptions.inPlacementGroup(placementGroupName);

      AWSEC2TemplateOptions awsTemplateOptions = AWSEC2TemplateOptions.class.cast(template.getOptions());
      if (awsTemplateOptions.isMonitoringEnabled())
         instanceOptions.enableMonitoring();
      if (awsTemplateOptions.getIAMInstanceProfileArn() != null)
         instanceOptions.withIAMInstanceProfileArn(awsTemplateOptions.getIAMInstanceProfileArn());
      if (awsTemplateOptions.getIAMInstanceProfileName() != null)
         instanceOptions.withIAMInstanceProfileName(awsTemplateOptions.getIAMInstanceProfileName());

      return instanceOptions;
   }


   }

   @Override
   protected void addSecurityGroups(String region, String group, Template template, RunInstancesOptions instanceOptions) {
      AWSEC2TemplateOptions awsTemplateOptions = AWSEC2TemplateOptions.class.cast(template.getOptions());
      AWSRunInstancesOptions awsInstanceOptions = AWSRunInstancesOptions.class.cast(instanceOptions);

      String subnetId = awsTemplateOptions.getSubnetId();
      boolean associatePublicIpAddress = awsTemplateOptions.isPublicIpAddressAssociated();
      if (subnetId != null) {
          if(associatePublicIpAddress){
              AWSRunInstancesOptions.class.cast(instanceOptions).associatePublicIpAddressAndSubnetId(subnetId);
              if (awsTemplateOptions.getGroupIds().size() > 0)
                 awsInstanceOptions.withSecurityGroupIdsForNetworkInterface(awsTemplateOptions.getGroupIds());
          }else{
              AWSRunInstancesOptions.class.cast(instanceOptions).withSubnetId(subnetId);
              if (awsTemplateOptions.getGroupIds().size() > 0)
                 awsInstanceOptions.withSecurityGroupIds(awsTemplateOptions.getGroupIds());
          }
      } else {
          if (awsTemplateOptions.getGroupIds().size() > 0)
             awsInstanceOptions.withSecurityGroupIds(awsTemplateOptions.getGroupIds());
         super.addSecurityGroups(region, group, template, instanceOptions);
      }
   }

      Builder<String, String> builder = ImmutableMap.builder();
      builder.put("LaunchSpecification.ImageId", checkNotNull(launchSpec.getImageId(), "imageId"));
      if (launchSpec.getAvailabilityZone() != null)
         builder.put("LaunchSpecification.Placement.AvailabilityZone", launchSpec.getAvailabilityZone());

      AWSRunInstancesOptions options = new AWSRunInstancesOptions();
      if (launchSpec.getBlockDeviceMappings().size() > 0)
         options.withBlockDeviceMappings(launchSpec.getBlockDeviceMappings());
      if (launchSpec.getSecurityGroupNames().size() > 0)
         options.withSecurityGroups(launchSpec.getSecurityGroupNames());
      if (launchSpec.getSecurityGroupIds().size() > 0)
         options.withSecurityGroupIds(launchSpec.getSecurityGroupIds());
      options.asType(checkNotNull(launchSpec.getInstanceType(), "instanceType"));
      if (launchSpec.getSubnetId() != null){
         if (Boolean.TRUE.equals(launchSpec.isPublicIpAddressAssociated()))  {
            options.associatePublicIpAddressAndSubnetId(launchSpec.getSubnetId());
            if (launchSpec.getSecurityGroupIds().size() > 0){
                options.withSecurityGroupIdsForNetworkInterface(launchSpec.getSecurityGroupIds());
            }
         }
         else{
             options.withSubnetId(launchSpec.getSubnetId());
         }
      }
      if (launchSpec.getKernelId() != null)
         options.withKernelId(launchSpec.getKernelId());
      if (launchSpec.getKeyName() != null)
         options.withKeyName(launchSpec.getKeyName());
      if (launchSpec.getRamdiskId() != null)
         options.withRamdisk(launchSpec.getRamdiskId());
      if (Boolean.TRUE.equals(launchSpec.isMonitoringEnabled()))
         options.enableMonitoring();
      if (launchSpec.getUserData() != null)
         options.withUserData(launchSpec.getUserData());
      if (launchSpec.getIAMInstanceProfile().isPresent()) {
         IAMInstanceProfileRequest profile = launchSpec.getIAMInstanceProfile().get();
         if (profile.getArn().isPresent())
            options.withIAMInstanceProfileArn(profile.getArn().get());
         if (profile.getName().isPresent())
            options.withIAMInstanceProfileName(profile.getName().get());
      }
      for (Entry<String, String> entry : options.buildFormParameters().entries()) {
         builder.put("LaunchSpecification." + entry.getKey(), entry.getValue());
      }
      return builder.build();
   }

      Builder<String, String> builder = ImmutableMap.builder();
      builder.put("LaunchSpecification.ImageId", checkNotNull(launchSpec.getImageId(), "imageId"));
      if (launchSpec.getAvailabilityZone() != null)
         builder.put("LaunchSpecification.Placement.AvailabilityZone", launchSpec.getAvailabilityZone());

      AWSRunInstancesOptions options = new AWSRunInstancesOptions();
      if (launchSpec.getBlockDeviceMappings().size() > 0)
         options.withBlockDeviceMappings(launchSpec.getBlockDeviceMappings());
      if (launchSpec.getSecurityGroupNames().size() > 0)
         options.withSecurityGroups(launchSpec.getSecurityGroupNames());
      if (launchSpec.getSecurityGroupIds().size() > 0)
         options.withSecurityGroupIds(launchSpec.getSecurityGroupIds());
      options.asType(checkNotNull(launchSpec.getInstanceType(), "instanceType"));
      if (launchSpec.getSubnetId() != null)
         options.withSubnetId(launchSpec.getSubnetId());
      if (launchSpec.getKernelId() != null)
         options.withKernelId(launchSpec.getKernelId());
      if (launchSpec.getKeyName() != null)
         options.withKeyName(launchSpec.getKeyName());
      if (launchSpec.getRamdiskId() != null)
         options.withRamdisk(launchSpec.getRamdiskId());
      if (Boolean.TRUE.equals(launchSpec.isMonitoringEnabled()))
         options.enableMonitoring();
      if (launchSpec.getUserData() != null)
         options.withUserData(launchSpec.getUserData());
      if (launchSpec.getIAMInstanceProfile().isPresent()) {
         IAMInstanceProfileRequest profile = launchSpec.getIAMInstanceProfile().get();
         if (profile.getArn().isPresent())
            options.withIAMInstanceProfileArn(profile.getArn().get());
         if (profile.getName().isPresent())
            options.withIAMInstanceProfileName(profile.getName().get());
      }
      for (Entry<String, String> entry : options.buildFormParameters().entries()) {
         builder.put("LaunchSpecification." + entry.getKey(), entry.getValue());
      }
      return builder.build();
   }

      this.createPlacementGroupIfNeeded = createPlacementGroupIfNeeded;
      this.importExistingKeyPair = importExistingKeyPair;
   }

   public AWSRunInstancesOptions execute(String region, String group, Template template) {
      AWSRunInstancesOptions instanceOptions = AWSRunInstancesOptions.class
            .cast(super.execute(region, group, template));

      String placementGroupName = template.getHardware().getId().startsWith("cc") ? createNewPlacementGroupUnlessUserSpecifiedOtherwise(
            region, group, template.getOptions()) : null;

      if (placementGroupName != null)
         instanceOptions.inPlacementGroup(placementGroupName);

      AWSEC2TemplateOptions awsTemplateOptions = AWSEC2TemplateOptions.class.cast(template.getOptions());
      if (awsTemplateOptions.isMonitoringEnabled())
         instanceOptions.enableMonitoring();
      if (awsTemplateOptions.getIAMInstanceProfileArn() != null)
         instanceOptions.withIAMInstanceProfileArn(awsTemplateOptions.getIAMInstanceProfileArn());
      if (awsTemplateOptions.getIAMInstanceProfileName() != null)
         instanceOptions.withIAMInstanceProfileName(awsTemplateOptions.getIAMInstanceProfileName());

      return instanceOptions;
   }

   }

   @Override
   protected void addSecurityGroups(String region, String group, Template template, RunInstancesOptions instanceOptions) {
      AWSEC2TemplateOptions awsTemplateOptions = AWSEC2TemplateOptions.class.cast(template.getOptions());
      AWSRunInstancesOptions awsInstanceOptions = AWSRunInstancesOptions.class.cast(instanceOptions);
      if (awsTemplateOptions.getGroupIds().size() > 0)
         awsInstanceOptions.withSecurityGroupIds(awsTemplateOptions.getGroupIds());
      String subnetId = awsTemplateOptions.getSubnetId();
      if (subnetId != null) {
         AWSRunInstancesOptions.class.cast(instanceOptions).withSubnetId(subnetId);
      } else {
         super.addSecurityGroups(region, group, template, instanceOptions);

            Lists.<Object> newArrayList("us-east-1",
            "us-east-1a",
            "ami-voo",
            1,
            5,
            new AWSRunInstancesOptions().withKernelId("kernelId").enableMonitoring()
                  .withSecurityGroups("group1", "group2")));

      assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
      assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
      assertPayloadEquals(

      Builder<String, String> builder = ImmutableMap.builder();
      builder.put("LaunchSpecification.ImageId", checkNotNull(launchSpec.getImageId(), "imageId"));
      if (launchSpec.getAvailabilityZone() != null)
         builder.put("LaunchSpecification.Placement.AvailabilityZone", launchSpec.getAvailabilityZone());

      AWSRunInstancesOptions options = new AWSRunInstancesOptions();
      if (launchSpec.getBlockDeviceMappings().size() > 0)
         options.withBlockDeviceMappings(launchSpec.getBlockDeviceMappings());
      if (launchSpec.getSecurityGroupNames().size() > 0)
         options.withSecurityGroups(launchSpec.getSecurityGroupNames());
      if (launchSpec.getSecurityGroupIds().size() > 0)
         options.withSecurityGroupIds(launchSpec.getSecurityGroupIds());
      options.asType(checkNotNull(launchSpec.getInstanceType(), "instanceType"));
      if (launchSpec.getSubnetId() != null)
         options.withSubnetId(launchSpec.getSubnetId());
      if (launchSpec.getKernelId() != null)
         options.withKernelId(launchSpec.getKernelId());
      if (launchSpec.getKeyName() != null)
         options.withKeyName(launchSpec.getKeyName());
      if (launchSpec.getRamdiskId() != null)
         options.withRamdisk(launchSpec.getRamdiskId());
      if (Boolean.TRUE.equals(launchSpec.isMonitoringEnabled()))
         options.enableMonitoring();
      if (launchSpec.getUserData() != null)
         options.withUserData(launchSpec.getUserData());
      if (launchSpec.getIAMInstanceProfile().isPresent()) {
         IAMInstanceProfileRequest profile = launchSpec.getIAMInstanceProfile().get();
         if (profile.getArn().isPresent())
            options.withIAMInstanceProfileArn(profile.getArn().get());
         if (profile.getName().isPresent())
            options.withIAMInstanceProfileName(profile.getName().get());
      }
      for (Entry<String, String> entry : options.buildFormParameters().entries()) {
         builder.put("LaunchSpecification." + entry.getKey(), entry.getValue());
      }
      return builder.build();
   }

      this.createPlacementGroupIfNeeded = createPlacementGroupIfNeeded;
      this.importExistingKeyPair = importExistingKeyPair;
   }

   public AWSRunInstancesOptions execute(String region, String group, Template template) {
      AWSRunInstancesOptions instanceOptions = AWSRunInstancesOptions.class
            .cast(super.execute(region, group, template));

      String placementGroupName = template.getHardware().getId().startsWith("cc") ? createNewPlacementGroupUnlessUserSpecifiedOtherwise(
            region, group, template.getOptions()) : null;

      if (placementGroupName != null)
         instanceOptions.inPlacementGroup(placementGroupName);

      AWSEC2TemplateOptions awsTemplateOptions = AWSEC2TemplateOptions.class.cast(template.getOptions());
      if (awsTemplateOptions.isMonitoringEnabled())
         instanceOptions.enableMonitoring();
      if (awsTemplateOptions.getIAMInstanceProfileArn() != null)
         instanceOptions.withIAMInstanceProfileArn(awsTemplateOptions.getIAMInstanceProfileArn());
      if (awsTemplateOptions.getIAMInstanceProfileName() != null)
         instanceOptions.withIAMInstanceProfileName(awsTemplateOptions.getIAMInstanceProfileName());

      return instanceOptions;
   }

   }

   @Override
   protected void addSecurityGroups(String region, String group, Template template, RunInstancesOptions instanceOptions) {
      AWSEC2TemplateOptions awsTemplateOptions = AWSEC2TemplateOptions.class.cast(template.getOptions());
      AWSRunInstancesOptions awsInstanceOptions = AWSRunInstancesOptions.class.cast(instanceOptions);
      if (awsTemplateOptions.getGroupIds().size() > 0)
         awsInstanceOptions.withSecurityGroupIds(awsTemplateOptions.getGroupIds());
      String subnetId = awsTemplateOptions.getSubnetId();
      if (subnetId != null) {
         AWSRunInstancesOptions.class.cast(instanceOptions).withSubnetId(subnetId);
      } else {
         super.addSecurityGroups(region, group, template, instanceOptions);

TOP

Related Classes of org.jclouds.aws.ec2.options.AWSRunInstancesOptions

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.