From c5f355130c8c40a994cf66d77d0c0d0c8ccc241c Mon Sep 17 00:00:00 2001 From: Wesley Beary Date: Sun, 5 Jul 2009 12:43:35 -0700 Subject: [PATCH] create/delete for security groups --- lib/fog/aws/ec2.rb | 37 ++++++++++++++++++++-- spec/aws/ec2/create_security_group_spec.rb | 15 +++++++++ spec/aws/ec2/delete_security_group_spec.rb | 15 +++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 spec/aws/ec2/create_security_group_spec.rb create mode 100644 spec/aws/ec2/delete_security_group_spec.rb diff --git a/lib/fog/aws/ec2.rb b/lib/fog/aws/ec2.rb index f75bd5e19..1b9f3ef6c 100644 --- a/lib/fog/aws/ec2.rb +++ b/lib/fog/aws/ec2.rb @@ -48,11 +48,28 @@ module Fog }, Fog::Parsers::AWS::EC2::AllocateAddress.new) end + # Create a new security group + # + # ==== Parameters + # :group_name<~String>:: Name of the security group. + # :group_description<~String>:: Description of group. + # + # ==== Returns + # response:: + # body<~Hash>:: + # :return<~Boolean>:: success? + def create_security_group(name, description) + request({ + 'Action' => 'CreateSecurityGroup', + 'GroupName' => name, + 'GroupDescription' => CGI.escape(description) + }, Fog::Parsers::AWS::EC2::Basic.new) + end + # Create an EBS volume # # ==== Parameters - # :availability_zone<~String>:: - # availability zone to create volume in + # :availability_zone<~String>:: availability zone to create volume in # :size<~Integer>:: Size in GiBs for volume. Must be between 1 and 1024. # :snapshot_id<~String>:: Optional, snapshot to create volume from # @@ -74,6 +91,22 @@ module Fog }, Fog::Parsers::AWS::EC2::CreateVolume.new) end + # Delete a security group that you own + # + # ==== Parameters + # :group_name<~String>:: Name of the security group. + # + # ==== Returns + # response:: + # body<~Hash>:: + # :return<~Boolean>:: success? + def delete_security_group(name) + request({ + 'Action' => 'DeleteSecurityGroup', + 'GroupName' => name + }, Fog::Parsers::AWS::EC2::Basic.new) + end + # Delete an EBS volume # # ==== Parameters diff --git a/spec/aws/ec2/create_security_group_spec.rb b/spec/aws/ec2/create_security_group_spec.rb new file mode 100644 index 000000000..15f997b06 --- /dev/null +++ b/spec/aws/ec2/create_security_group_spec.rb @@ -0,0 +1,15 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'EC2.create_security_group' do + + after(:all) do + ec2.delete_security_group('fog_security_group') + end + + it "should return proper attributes" do + actual = ec2.create_security_group('fog_security_group', 'a security group for testing fog') + actual.body[:request_id].should be_a(String) + [false, true].should include(actual.body[:return]) + end + +end diff --git a/spec/aws/ec2/delete_security_group_spec.rb b/spec/aws/ec2/delete_security_group_spec.rb new file mode 100644 index 000000000..d16a7e382 --- /dev/null +++ b/spec/aws/ec2/delete_security_group_spec.rb @@ -0,0 +1,15 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'EC2.delete_security_group' do + + before(:all) do + ec2.create_security_group('fog_security_group', 'a security group for testing fog') + end + + it "should return proper attributes" do + actual = ec2.delete_security_group('fog_security_group') + actual.body[:request_id].should be_a(String) + [false, true].should include(actual.body[:return]) + end + +end