diff --git a/lib/fog/aws/ec2.rb b/lib/fog/aws/ec2.rb index 06b2385cf..83428ea33 100644 --- a/lib/fog/aws/ec2.rb +++ b/lib/fog/aws/ec2.rb @@ -85,6 +85,20 @@ module Fog }, Fog::Parsers::AWS::EC2::Basic.new) end + # Create a snapshot of an EBS volume and store it in S3 + # + # ==== Parameters + # * volume_id<~String> - Id of EBS volume to snapshot + # + # ==== Returns + # FIXME: docs + def create_snapshot(volume_id) + request({ + 'Action' => 'CreateSnapshot', + 'VolumeId' => 'VolumeId' + }, Fog::Parsers::AWS::EC2::CreateSnapshot.new) + end + # Create an EBS volume # # ==== Parameters @@ -134,6 +148,7 @@ module Fog # ==== Returns # * response<~Fog::AWS::Response>: # * body<~Hash>: + # * :request_id<~String> - Id of request # * :return<~Boolean> - success? def delete_security_group(name) request({ @@ -142,6 +157,23 @@ module Fog }, Fog::Parsers::AWS::EC2::Basic.new) end + # Delete a snapshot of an EBS volume that you own + # + # ==== Parameters + # * snapshot_id<~String> - ID of snapshot to delete + # ==== Returns + # ==== Returns + # * response<~Fog::AWS::Response>: + # * body<~Hash>: + # * :request_id<~String> - Id of request + # * :return<~Boolean> - success? + def delete_snapshot(snapshot_id) + request({ + 'Action' => 'DeleteSnapshot', + 'SnapshotId' => snapshot_id + }, Fog::Parsers::AWS::EC2::Basic.new) + end + # Delete an EBS volume # # ==== Parameters @@ -150,6 +182,7 @@ module Fog # ==== Returns # * response<~Fog::AWS::Response>: # * body<~Hash>: + # * :request_id<~String> - Id of request # * :return<~Boolean> - success? def delete_volume(volume_id) request({ @@ -259,6 +292,20 @@ module Fog }.merge!(params), Fog::Parsers::AWS::EC2::DescribeSecurityGroups.new) end + # Describe all or specified snapshots + # + # ==== Parameters + # * snapshot_id<~Array> - List of snapshots to describe, defaults to all + # + # ==== Returns + # FIXME: docs + def describe_snapshots(snapshot_id = []) + params = indexed_params('SnapshotId', snapshot_id) + request({ + 'Action' => 'DescribeSnapshots' + }.merge!(params), Fog::Parsers::AWS::EC2::DescribeSnapshots.new) + end + # Describe all or specified volumes. # # ==== Parameters diff --git a/lib/fog/aws/ec2/parsers.rb b/lib/fog/aws/ec2/parsers.rb index dafff4340..8815d84db 100644 --- a/lib/fog/aws/ec2/parsers.rb +++ b/lib/fog/aws/ec2/parsers.rb @@ -52,6 +52,25 @@ module Fog end + class CreateSnapshot < Fog::Parsers::Base + + def end_element(name) + case name + when 'progress' + @response[:progress] = @value + when 'snapshotId' + @response[:snapshot_id] = @value + when 'startTime' + @response[:start_time] = Time.parse(@value) + when 'status' + @response[:status] = @value + when 'volumeId' + @response[:volume_id] = @value + end + end + + end + class CreateVolume < Fog::Parsers::Base def end_element(name) @@ -337,6 +356,33 @@ module Fog end + class DescribeSnapshots < Fog::Parsers::Base + + def reset + @response = { :snapshot_set => [] } + @snapshot = {} + end + + def end_element(name) + case name + when 'item' + @response[:snapshot_set] << @snapshot + @snapshot = {} + when 'progress' + @snapshot[:progress] = @value + when 'snapshotId' + @snapshot[:snapshot_id] = @value + when 'startTime' + @snapshot[:start_time] = Time.parse(@value) + when 'status' + @snapshot[:status] = @value + when 'volumeId' + @snapshot[:volume_id] = @value + end + end + + end + class DescribeVolumes < Fog::Parsers::Base def reset diff --git a/spec/aws/ec2/create_snapshot_spec.rb b/spec/aws/ec2/create_snapshot_spec.rb new file mode 100644 index 000000000..60b67997d --- /dev/null +++ b/spec/aws/ec2/create_snapshot_spec.rb @@ -0,0 +1,13 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'EC2.create_snapshot' do + + it "should return proper attributes with no params" do + pending + # actual = ec2.create_snapshot(volume_id) + # p actual + end + + it "should return proper attributes with params" + +end diff --git a/spec/aws/ec2/delete_snapshot_spec.rb b/spec/aws/ec2/delete_snapshot_spec.rb new file mode 100644 index 000000000..25b2f0f01 --- /dev/null +++ b/spec/aws/ec2/delete_snapshot_spec.rb @@ -0,0 +1,13 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'EC2.delete_snapshot' do + + it "should return proper attributes with no params" do + pending + # actual = ec2.delete_snapshot(snapshot_id) + # p actual + end + + it "should return proper attributes with params" + +end diff --git a/spec/aws/ec2/describe_snapshot_spec.rb b/spec/aws/ec2/describe_snapshot_spec.rb new file mode 100644 index 000000000..c924948b7 --- /dev/null +++ b/spec/aws/ec2/describe_snapshot_spec.rb @@ -0,0 +1,12 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'EC2.describe_snapshots' do + + it "should return proper attributes with no params" do + actual = ec2.describe_snapshots + p actual + end + + it "should return proper attributes with params" + +end