Settings configuring the EC2 instance launch phase after an image file has been uploaded.
Пример #1
0
        /// <summary>
        /// Initiates a conversion task to yield a new Amazon EC2 instance for a set of image file 
        /// artifacts uploaded previously to Amazon S3.
        /// </summary>
        /// <param name="launchConfiguration">Launch configuration settings for the imported instance</param>
        /// <returns>
        /// The service response containing a ConversionTask object that can be used to monitor the progress of the 
        /// requested conversion.
        /// </returns>
        public ImportInstanceResponse StartInstanceConversion(ImportLaunchConfiguration launchConfiguration)
        {
            if (string.IsNullOrEmpty(ManifestFileKey))
                throw new InvalidOperationException("No Amazon S3 object key available; have the image artifacts been uploaded?");

            var diskImage = PopulateDiskImage(ManifestFileKey, launchConfiguration.Description);
            var launchSpecification = PopulateLaunchSpecificationInstance(launchConfiguration);

            var request = new ImportInstanceRequest
            {
                Description = string.IsNullOrEmpty(launchConfiguration.Description) ? null : launchConfiguration.Description,
                LaunchSpecification = launchSpecification,
                Platform = string.IsNullOrEmpty(launchConfiguration.Platform) ? null : launchConfiguration.Platform
            };

            request.DiskImages.Add(diskImage);

            // allow any exception to propagate to the caller; this allows the calling tool to 
            // assist the user with re-executing the command by showing the appropriate command line
            // or remediation needed to avoid re-uploading the artifacts
            try
            {
                return EC2Client.ImportInstance(request);
            }
            catch (Exception e)
            {
                throw new DiskImageImporterException(DiskImportErrorStage.SendingImportRequest, e);
            }
        }
Пример #2
0
        /// <summary>
        /// Helper to populate an SDK ImportInstanceLaunchSpecification instance that 
        /// will be used in an ImportInstance API request.
        /// </summary>
        /// <param name="config">Settings for the new LaunchSpecificationInstance</param>
        /// <returns>Populated ImportInstanceLaunchSpecification instance.</returns>
        public static ImportInstanceLaunchSpecification PopulateLaunchSpecificationInstance(ImportLaunchConfiguration config)
        {
            var launchSpecification = new ImportInstanceLaunchSpecification
            {
                Architecture = config.Architecture,
                InstanceType = config.InstanceType,
                Monitoring = config.EnableMonitoring,
            };

            if (config.SecurityGroupNames != null)
                launchSpecification.GroupNames.AddRange(config.SecurityGroupNames);

            if (!string.IsNullOrEmpty(config.AvailabilityZone))
                launchSpecification.Placement = new Placement { AvailabilityZone = config.AvailabilityZone };

            if (!string.IsNullOrEmpty(config.SubnetId))
                launchSpecification.SubnetId = config.SubnetId;

            if (!string.IsNullOrEmpty(config.PrivateIpAddress))
                launchSpecification.PrivateIpAddress = config.PrivateIpAddress;

            if (config.InstanceInitiatedShutdownBehavior != null)
                launchSpecification.InstanceInitiatedShutdownBehavior = config.InstanceInitiatedShutdownBehavior;

            if (!string.IsNullOrEmpty(config.AdditionalInfo))
                launchSpecification.AdditionalInfo = config.AdditionalInfo;

            return launchSpecification;
        }
Пример #3
0
 /// <summary>
 /// Uploads and requests import conversion of a virtual machine image file
 /// to an Amazon EC2 instance.
 /// </summary>
 /// <param name="imageFilepath">The full path to the image file to be processed</param>
 /// <param name="fileFormat">
 /// The format of the image file (VMDK | RAW | VHD). If not specified, it will be inferred
 /// from the extension of the image file.
 /// </param>
 /// <param name="volumeSize">
 /// The requested size (in GiB) for the resulting image volume. If not specified a suitable 
 /// value based on the size of the image file is used. Note that the minimum required boot 
 /// volume size for EC2 is 8GB.
 /// </param>
 /// <param name="keyPrefix">
 /// Optional root-level key prefix that will be applied to the uploaded artifacts in S3.
 /// The artifacts will be placed beneath this (or the root if not set) in a key composed
 /// of a GUID.
 /// </param>
 /// <param name="launchConfiguration">Launch configuration settings for the imported instance</param>
 /// <param name="progressCallback">Optional callback delegate for upload progress reporting</param>
 /// <returns>
 /// The service response containing a ConversionTask object that can be used to monitor the progress of the 
 /// requested conversion.
 /// </returns>
 public ImportInstanceResponse ImportInstance(string imageFilepath,
                                              string fileFormat,
                                              long? volumeSize,
                                              string keyPrefix,
                                              ImportLaunchConfiguration launchConfiguration,
                                              ImportProgressCallback progressCallback)
 {
     Upload(imageFilepath, fileFormat, volumeSize, keyPrefix, progressCallback, false);
     return StartInstanceConversion(launchConfiguration);
 }