Пример #1
0
        /// <summary>
        /// Constructs the object hierarchy that will be serialized to a single manifest
        /// file describing the import.
        /// </summary>
        /// <param name="fileFormat">
        /// The file format of the image file. If not specified, it will be inferred from the image 
        /// file extension. Valid values: VMDK | RAW | VHD. 
        /// </param>
        /// <param name="volumeSize">
        /// The requested size, in GiB, of the resulting volume in EC2. If not specified a suitable
        /// value will be used based on the size of the supplied image file.
        /// </param>
        /// <returns>Import manifest ready for serialization and upload.</returns>
        ImportManifestRoot CreateImportManifest(string fileFormat,
                                                long? volumeSize)
        {
            try
            {
                var urlExpiration = DateTime.UtcNow.AddDays(UrlExpiryPeriod);
                ConstructManifestArtifactKey(ImageFilePath);

                var format = fileFormat;
                if (string.IsNullOrEmpty(format))
                {
                    var ext = AWSSDKUtils.GetExtension(ImageFilePath);
                    if (string.IsNullOrEmpty(ext))
                        throw new ArgumentException("The image filename does not have an exception, so file format cannot be inferred.");

                    format = ext.TrimStart('.');
                }

                var manifest = new ImportManifestRoot
                {
                    Version = ManifestFileVersion,
                    FileFormat = format.ToUpper(CultureInfo.InvariantCulture), 
                    ImporterField = new ImporterInfo
                    {
                        Name = ManifestFileImporterName,
                        Version = ManifestFileImporterVersion,
                        Release = ManifestFileImporterRelease
                    },

                    SelfDestructUrl = S3Client.GetPreSignedURL(new GetPreSignedUrlRequest
                    {
                        BucketName = BucketName,
                        Key = ManifestFileKey,
                        Expires = urlExpiration,
                        Verb = HttpVerb.DELETE
                    }),

                    ImportData = ConstructImportPartsList(volumeSize, urlExpiration)
                };

                return manifest;
            }
            catch (Exception e)
            {
                throw new DiskImageImporterException(DiskImportErrorStage.GeneratingManifest, e);
            }
        }