protected override void ProcessRecord()
 {
     AmazonEC2 client = base.GetClient();
     Amazon.EC2.Model.CreateVolumeRequest request = new Amazon.EC2.Model.CreateVolumeRequest();
     request.Size = this._Size;
     request.SnapshotId = this._SnapshotId;
     request.AvailabilityZone = this._AvailabilityZone;
     Amazon.EC2.Model.CreateVolumeResponse response = client.CreateVolume(request);
     base.WriteObject(response.CreateVolumeResult.Volume, true);
 }
示例#2
0
        /// <summary>
        /// Initiates the asynchronous execution of the CreateVolume operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the CreateVolume operation on AmazonEC2Client.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        /// 
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndCreateVolume
        ///         operation.</returns>
        public IAsyncResult BeginCreateVolume(CreateVolumeRequest request, AsyncCallback callback, object state)
        {
            var marshaller = new CreateVolumeRequestMarshaller();
            var unmarshaller = CreateVolumeResponseUnmarshaller.Instance;

            return BeginInvoke<CreateVolumeRequest>(request, marshaller, unmarshaller,
                callback, state);
        }
示例#3
0
 IAsyncResult invokeCreateVolume(CreateVolumeRequest createVolumeRequest, AsyncCallback callback, object state, bool synchronized)
 {
     IRequest irequest = new CreateVolumeRequestMarshaller().Marshall(createVolumeRequest);
     var unmarshaller = CreateVolumeResponseUnmarshaller.GetInstance();
     AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller);
     Invoke(result);
     return result;
 }
示例#4
0
 /// <summary>
 /// Initiates the asynchronous execution of the CreateVolume operation.
 /// <seealso cref="Amazon.EC2.IAmazonEC2.CreateVolume"/>
 /// </summary>
 /// 
 /// <param name="createVolumeRequest">Container for the necessary parameters to execute the CreateVolume operation on AmazonEC2.</param>
 /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 /// 
 /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndCreateVolume
 ///         operation.</returns>
 public IAsyncResult BeginCreateVolume(CreateVolumeRequest createVolumeRequest, AsyncCallback callback, object state)
 {
     return invokeCreateVolume(createVolumeRequest, callback, state, false);
 }
示例#5
0
 /// <summary>
 /// <para>Creates an Amazon EBS volume that can be attached to any instance in the same Availability Zone.</para> <para>Any AWS Marketplace
 /// product codes from the snapshot are propagated to the volume.</para> <para>For more information, see <a
 /// href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-creating-volume.html" >Creating or Restoring an Amazon EBS Volume</a> in the
 /// <i>Amazon Elastic Compute Cloud User Guide</i> .</para>
 /// </summary>
 /// 
 /// <param name="createVolumeRequest">Container for the necessary parameters to execute the CreateVolume service method on AmazonEC2.</param>
 /// 
 /// <returns>The response from the CreateVolume service method, as returned by AmazonEC2.</returns>
 /// 
 public CreateVolumeResponse CreateVolume(CreateVolumeRequest createVolumeRequest)
 {
     IAsyncResult asyncResult = invokeCreateVolume(createVolumeRequest, null, null, true);
     return EndCreateVolume(asyncResult);
 }
 private Amazon.EC2.Model.CreateVolumeResponse CallAWSServiceOperation(IAmazonEC2 client, Amazon.EC2.Model.CreateVolumeRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Elastic Compute Cloud (EC2)", "CreateVolume");
     try
     {
         #if DESKTOP
         return(client.CreateVolume(request));
         #elif CORECLR
         return(client.CreateVolumeAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
        public object Execute(ExecutorContext context)
        {
            var cmdletContext = context as CmdletContext;
            // create request
            var request = new Amazon.EC2.Model.CreateVolumeRequest();

            if (cmdletContext.AvailabilityZone != null)
            {
                request.AvailabilityZone = cmdletContext.AvailabilityZone;
            }
            if (cmdletContext.Encrypted != null)
            {
                request.Encrypted = cmdletContext.Encrypted.Value;
            }
            if (cmdletContext.Iops != null)
            {
                request.Iops = cmdletContext.Iops.Value;
            }
            if (cmdletContext.KmsKeyId != null)
            {
                request.KmsKeyId = cmdletContext.KmsKeyId;
            }
            if (cmdletContext.MultiAttachEnabled != null)
            {
                request.MultiAttachEnabled = cmdletContext.MultiAttachEnabled.Value;
            }
            if (cmdletContext.OutpostArn != null)
            {
                request.OutpostArn = cmdletContext.OutpostArn;
            }
            if (cmdletContext.Size != null)
            {
                request.Size = cmdletContext.Size.Value;
            }
            if (cmdletContext.SnapshotId != null)
            {
                request.SnapshotId = cmdletContext.SnapshotId;
            }
            if (cmdletContext.TagSpecification != null)
            {
                request.TagSpecifications = cmdletContext.TagSpecification;
            }
            if (cmdletContext.VolumeType != null)
            {
                request.VolumeType = cmdletContext.VolumeType;
            }

            CmdletOutput output;

            // issue call
            var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);

            try
            {
                var    response       = CallAWSServiceOperation(client, request);
                object pipelineOutput = null;
                pipelineOutput = cmdletContext.Select(response, this);
                output         = new CmdletOutput
                {
                    PipelineOutput  = pipelineOutput,
                    ServiceResponse = response
                };
            }
            catch (Exception e)
            {
                output = new CmdletOutput {
                    ErrorResponse = e
                };
            }

            return(output);
        }
示例#8
0
        /// <param name="snapshotId">If null, create from scratch</param>
        private async Task<string> CreateVolumeAsync(string snapshotId = null, int? size = null, CancellationToken? cancellationToken = null)
        {
            CancellationToken token = cancellationToken.HasValue ? cancellationToken.Value : new CancellationToken();

            if (string.IsNullOrEmpty(snapshotId))
                this.Logger.Log("Starting device mount process, with a new volume");
            else
                this.Logger.Log("Starting device mount process. Snapshot ID: {0}", snapshotId);

            var request = new CreateVolumeRequest()
            {
                SnapshotId = string.IsNullOrEmpty(snapshotId) ? null : snapshotId,    // Null is the default value here
                VolumeType = "standard",
                AvailabilityZone = this.Instance.Specification.AvailabilityZone,
            };
            if (size != null)
                request.Size = size.Value;

            var createVolumeResponse = await this.Client.CreateVolumeAsync(request);
            var volumeId = createVolumeResponse.Volume.VolumeId;
            this.Logger.Log("Volume ID {0} created", volumeId);

            this.Logger.Log("Tagging volume, so we know we can remove it later");
            var name = this.Name == null ? "Unnamed" : this.Instance.Name + " - " + this.Name;

            var tags = new List<Tag>()
                {
                    new Tag() { Key = "CreatedByEc2Manager", Value = "true" },
                    new Tag() { Key = "Name", Value = name },
                    new Tag() { Key = "VolumeName", Value = this.Name },
                };

            await this.Client.CreateTagsAsync(new CreateTagsRequest()
            {
                Resources = new List<string>() { volumeId },
                Tags = tags,
            });

            this.Logger.Log("Waiting for volume to reach the 'available' state");
            await this.UntilVolumeStateAsync(volumeId, "available", token);

            return volumeId;
        }
示例#9
0
		internal CreateVolumeResponse CreateVolume(CreateVolumeRequest request)
        {
            var task = CreateVolumeAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
示例#10
0
        /// <summary>
        /// Initiates the asynchronous execution of the CreateVolume operation.
        /// <seealso cref="Amazon.EC2.IAmazonEC2.CreateVolume"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the CreateVolume operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
		public async Task<CreateVolumeResponse> CreateVolumeAsync(CreateVolumeRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new CreateVolumeRequestMarshaller();
            var unmarshaller = CreateVolumeResponseUnmarshaller.GetInstance();
            var response = await Invoke<IRequest, CreateVolumeRequest, CreateVolumeResponse>(request, marshaller, unmarshaller, signer, cancellationToken)
                .ConfigureAwait(continueOnCapturedContext: false);
            return response;
        }
示例#11
0
        /// <summary>
        /// <para> Initializes an empty volume of a given size. </para>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the CreateVolume service method on AmazonEC2.</param>
        /// 
        /// <returns>The response from the CreateVolume service method, as returned by AmazonEC2.</returns>
		public CreateVolumeResponse CreateVolume(CreateVolumeRequest request)
        {
            var task = CreateVolumeAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                throw e.InnerException;
            }
        }
示例#12
0
        /// <summary>
        /// Initializes an empty volume of a given size
        /// 
        /// </summary>
        /// <param name="service">Instance of AmazonEC2 service</param>
        /// <param name="request">CreateVolumeRequest request</param>
        public static void InvokeCreateVolume(AmazonEC2 service, CreateVolumeRequest request)
        {
            try 
            {
                CreateVolumeResponse response = service.CreateVolume(request);
                
                
                Console.WriteLine ("Service Response");
                Console.WriteLine ("=============================================================================");
                Console.WriteLine ();

                Console.WriteLine("        CreateVolumeResponse");
                if (response.IsSetCreateVolumeResult())
                {
                    Console.WriteLine("            CreateVolumeResult");
                    CreateVolumeResult  createVolumeResult = response.CreateVolumeResult;
                    if (createVolumeResult.IsSetVolume())
                    {
                        Console.WriteLine("                Volume");
                        Volume  volume = createVolumeResult.Volume;
                        if (volume.IsSetVolumeId())
                        {
                            Console.WriteLine("                    VolumeId");
                            Console.WriteLine("                        {0}", volume.VolumeId);
                        }
                        if (volume.IsSetSize())
                        {
                            Console.WriteLine("                    Size");
                            Console.WriteLine("                        {0}", volume.Size);
                        }
                        if (volume.IsSetSnapshotId())
                        {
                            Console.WriteLine("                    SnapshotId");
                            Console.WriteLine("                        {0}", volume.SnapshotId);
                        }
                        if (volume.IsSetAvailabilityZone())
                        {
                            Console.WriteLine("                    AvailabilityZone");
                            Console.WriteLine("                        {0}", volume.AvailabilityZone);
                        }
                        if (volume.IsSetStatus())
                        {
                            Console.WriteLine("                    Status");
                            Console.WriteLine("                        {0}", volume.Status);
                        }
                        if (volume.IsSetCreateTime())
                        {
                            Console.WriteLine("                    CreateTime");
                            Console.WriteLine("                        {0}", volume.CreateTime);
                        }
                        List<Attachment> attachmentList = volume.Attachment;
                        foreach (Attachment attachment in attachmentList)
                        {
                            Console.WriteLine("                    Attachment");
                            if (attachment.IsSetVolumeId())
                            {
                                Console.WriteLine("                        VolumeId");
                                Console.WriteLine("                            {0}", attachment.VolumeId);
                            }
                            if (attachment.IsSetInstanceId())
                            {
                                Console.WriteLine("                        InstanceId");
                                Console.WriteLine("                            {0}", attachment.InstanceId);
                            }
                            if (attachment.IsSetDevice())
                            {
                                Console.WriteLine("                        Device");
                                Console.WriteLine("                            {0}", attachment.Device);
                            }
                            if (attachment.IsSetStatus())
                            {
                                Console.WriteLine("                        Status");
                                Console.WriteLine("                            {0}", attachment.Status);
                            }
                            if (attachment.IsSetAttachTime())
                            {
                                Console.WriteLine("                        AttachTime");
                                Console.WriteLine("                            {0}", attachment.AttachTime);
                            }
                        }
                    }
                }
                if (response.IsSetResponseMetadata())
                {
                    Console.WriteLine("            ResponseMetadata");
                    ResponseMetadata  responseMetadata = response.ResponseMetadata;
                    if (responseMetadata.IsSetRequestId())
                    {
                        Console.WriteLine("                RequestId");
                        Console.WriteLine("                    {0}", responseMetadata.RequestId);
                    }
                }

            } 
            catch (AmazonEC2Exception ex) 
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
                Console.WriteLine("XML: " + ex.XML);
            }
        }
        /// <summary>
        /// Creates a new volume
        /// </summary>
        /// <param name="avilabilityZone">The Availability zone to create the volume in</param>
        /// <param name="size"></param>
        /// <returns>Returns the VolumeId of the newly created volume</returns>
        public string CreateNewVolume(string availabilityZone, string size)
        {
            var request = new CreateVolumeRequest { AvailabilityZone = availabilityZone, Size = size };

            CreateVolumeResponse response = Client.CreateVolume(request);

            return response.CreateVolumeResult.Volume.VolumeId;
        }
        /// <summary>
        /// Create a volume from a snapshot
        /// </summary>
        /// <param name="avilabilityZone">The Availability zone to create the volume in</param>
        /// <param name="snapshotId">The SnapShot to create the volume from</param>
        /// <returns>Returns the VolumeId of the newly created volume</returns>
        public string CreateVolumeFromSnapshot(string avilabilityZone, string snapshotId)
        {
            CreateVolumeRequest request = new CreateVolumeRequest();
            request.AvailabilityZone = avilabilityZone;
            request.SnapshotId = snapshotId;

            CreateVolumeResponse response = Client.CreateVolume(request);

            return response.CreateVolumeResult.Volume.VolumeId;
        }
        /// <summary>
        /// Creates an EBS volume that can be attached to an instance in the same Availability
        /// Zone. The volume is created in the regional endpoint that you send the HTTP request
        /// to. For more information see <a href="http://docs.aws.amazon.com/general/latest/gr/rande.html">Regions
        /// and Endpoints</a>.
        /// 
        ///  
        /// <para>
        /// You can create a new empty volume or restore a volume from an EBS snapshot. Any AWS
        /// Marketplace product codes from the snapshot are propagated to the volume.
        /// </para>
        ///  
        /// <para>
        /// You can create encrypted volumes with the <code>Encrypted</code> parameter. Encrypted
        /// volumes may only be attached to instances that support Amazon EBS encryption. Volumes
        /// that are created from encrypted snapshots are also automatically encrypted. For more
        /// information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html">Amazon
        /// EBS Encryption</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>.
        /// </para>
        ///  
        /// <para>
        /// For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-creating-volume.html">Creating
        /// or Restoring an Amazon EBS Volume</a> in the <i>Amazon Elastic Compute Cloud User
        /// Guide</i>.
        /// </para>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the CreateVolume service method.</param>
        /// 
        /// <returns>The response from the CreateVolume service method, as returned by EC2.</returns>
        public CreateVolumeResponse CreateVolume(CreateVolumeRequest request)
        {
            var marshaller = new CreateVolumeRequestMarshaller();
            var unmarshaller = CreateVolumeResponseUnmarshaller.Instance;

            return Invoke<CreateVolumeRequest,CreateVolumeResponse>(request, marshaller, unmarshaller);
        }
        /// <summary>
        /// Initiates the asynchronous execution of the CreateVolume operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the CreateVolume operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task<CreateVolumeResponse> CreateVolumeAsync(CreateVolumeRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new CreateVolumeRequestMarshaller();
            var unmarshaller = CreateVolumeResponseUnmarshaller.Instance;

            return InvokeAsync<CreateVolumeRequest,CreateVolumeResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
示例#17
0
        /// <summary>
        /// <para>Creates an Amazon EBS volume that can be attached to any instance in the same Availability Zone.</para> <para>Any AWS Marketplace
        /// product codes from the snapshot are propagated to the volume.</para> <para>For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-creating-volume.html">Creating or Restoring an Amazon EBS Volume</a> in the
        /// <i>Amazon Elastic Compute Cloud User Guide</i> .</para>
        /// </summary>
        /// 
        /// <param name="createVolumeRequest">Container for the necessary parameters to execute the CreateVolume service method on AmazonEC2.</param>
        /// 
        /// <returns>The response from the CreateVolume service method, as returned by AmazonEC2.</returns>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
		public Task<CreateVolumeResponse> CreateVolumeAsync(CreateVolumeRequest createVolumeRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new CreateVolumeRequestMarshaller();
            var unmarshaller = CreateVolumeResponseUnmarshaller.GetInstance();
            return Invoke<IRequest, CreateVolumeRequest, CreateVolumeResponse>(createVolumeRequest, marshaller, unmarshaller, signer, cancellationToken);
        }