public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonEC2Config config = new AmazonEC2Config();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonEC2Client client = new AmazonEC2Client(creds, config);

            DescribeConversionTasksResponse resp = new DescribeConversionTasksResponse();
            DescribeConversionTasksRequest  req  = new DescribeConversionTasksRequest
            {
            };

            resp = client.DescribeConversionTasks(req);
            CheckError(resp.HttpStatusCode, "200");

            foreach (var obj in resp.ConversionTasks)
            {
                AddObject(obj);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Deletes the image file artifacts associated with the specified conversion task.
        /// If the task is still active, ignoreActiveTask must be set true to enable artifact
        /// deletion, which will cause the task to fail. Use this option at your own risk.
        /// </summary>
        /// <param name="ec2Client">
        /// Amazon EC2 client to use in the process. This should have been instantiated
        /// with credentials that have access to the conversion task and the region in
        /// which the import was performed.
        /// </param>
        /// <param name="s3Client">
        /// Amazon S3 client to use use in the process. This should have been instantiated
        /// with credentials that have access to the bucket containing the image file artifacts
        /// and the region in which the bucket exists.
        /// </param>
        /// <param name="conversionTaskId">
        /// The ID of the conversion task that used the image file
        /// </param>
        /// <param name="ignoreActiveTask">
        /// If true the artifacts are deleted even if the conversion task is still in progress
        /// </param>
        /// <param name="progressCallback">Optional progress callback</param>
        public static void DeleteImageArtifacts(IAmazonEC2 ec2Client,
                                                IAmazonS3 s3Client,
                                                string conversionTaskId,
                                                bool ignoreActiveTask,
                                                CleanupProgressCallback progressCallback)
        {
            if (string.IsNullOrEmpty(conversionTaskId))
            {
                throw new ArgumentException("Missing conversion task id", "conversionTaskId");
            }

            SendProgressNotification(progressCallback, "Inspecting conversion task", null);

            var request = new DescribeConversionTasksRequest();

            request.ConversionTaskIds.Add(conversionTaskId);
            try
            {
                var response = ec2Client.DescribeConversionTasks(request);
                if (response.ConversionTasks.Count == 0)
                {
                    throw new ArgumentException("Invalid conversion task id", "conversionTaskId");
                }

                var conversionTask = response.ConversionTasks[0];

                if (!ignoreActiveTask && conversionTask.State.Equals(ConversionTaskState.Active))
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                                      "Import task '{0}' is still active.",
                                                                      conversionTaskId));
                }

                string manifestUrl = null;
                try
                {
                    // At this time only one disk image per task
                    if (conversionTask.IsSetImportInstance())
                    {
                        manifestUrl = conversionTask.ImportInstance.Volumes[0].Image.ImportManifestUrl;
                    }
                    else if (conversionTask.IsSetImportVolume())
                    {
                        manifestUrl = conversionTask.ImportVolume.Image.ImportManifestUrl;
                    }
                }
                finally
                {
                    if (string.IsNullOrEmpty(manifestUrl))
                    {
                        throw new ArgumentException("Unable to obtain import manifest url from conversion task instance.");
                    }
                }

                DeleteImageArtifacts(s3Client, manifestUrl, progressCallback);
            }
            catch (AmazonEC2Exception e)
            {
                throw new ArgumentException("Expected the id of a valid conversion task", "conversionTaskId", e);
            }
        }