From b6f88cb5110c0dcb328a7451fad1cf58874a3244 Mon Sep 17 00:00:00 2001 From: Wesley Beary Date: Mon, 6 Jul 2009 09:21:21 -0700 Subject: [PATCH] first pass for create/delete key pairs --- lib/fog/aws/ec2.rb | 35 ++++++++++++++++++++++++++++ lib/fog/aws/ec2/parsers.rb | 17 ++++++++++++++ spec/aws/ec2/create_key_pair_spec.rb | 17 ++++++++++++++ spec/aws/ec2/delete_key_pair_spec.rb | 15 ++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 spec/aws/ec2/create_key_pair_spec.rb create mode 100644 spec/aws/ec2/delete_key_pair_spec.rb diff --git a/lib/fog/aws/ec2.rb b/lib/fog/aws/ec2.rb index f78697fa2..fa8e736f7 100644 --- a/lib/fog/aws/ec2.rb +++ b/lib/fog/aws/ec2.rb @@ -48,6 +48,25 @@ module Fog }, Fog::Parsers::AWS::EC2::AllocateAddress.new) end + # Create a new key pair + # + # ==== Parameters + # :key_name<~String>:: Unique name for key pair. + # + # ==== Returns + # response:: + # body<~Hash>:: + # :key_name<~String>:: Name of key + # :key_fingerprint<~String>:: SHA-1 digest of DER encoded private key + # :key_material<~String>:: Unencrypted encoded PEM private key + # :request_id<~String>:: Id of request + def create_key_pair(key_name) + request({ + 'Action' => 'CreateKeyPair', + 'KeyName' => key_name + }, Fog::Parsers::AWS::EC2::CreateKeyPair.new) + end + # Create a new security group # # ==== Parameters @@ -91,6 +110,22 @@ module Fog }, Fog::Parsers::AWS::EC2::CreateVolume.new) end + # Delete a key pair that you own + # + # ==== Parameters + # :key_name<~String>:: Name of the key pair. + # + # ==== Returns + # response:: + # body<~Hash>:: + # :return<~Boolean>:: success? + def delete_key_pair(key_name) + request({ + 'Action' => 'DeleteKeyPair', + 'KeyName' => key_name + }, Fog::Parsers::AWS::EC2::Basic.new) + end + # Delete a security group that you own # # ==== Parameters diff --git a/lib/fog/aws/ec2/parsers.rb b/lib/fog/aws/ec2/parsers.rb index a061dc2e2..f7260a4a9 100644 --- a/lib/fog/aws/ec2/parsers.rb +++ b/lib/fog/aws/ec2/parsers.rb @@ -35,6 +35,23 @@ module Fog end + class CreateKeyPair < Fog::Parsers::Base + + def end_element(name) + case name + when 'keyFingerprint' + @response[:key_fingerprint] = @value + when 'keyMaterial' + @response[:key_material] = @value + when 'keyName' + @response[:key_name] = @value + when 'requestId' + @response[:request_id] + end + end + + end + class CreateVolume < Fog::Parsers::Base def end_element(name) diff --git a/spec/aws/ec2/create_key_pair_spec.rb b/spec/aws/ec2/create_key_pair_spec.rb new file mode 100644 index 000000000..c27e96aa8 --- /dev/null +++ b/spec/aws/ec2/create_key_pair_spec.rb @@ -0,0 +1,17 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'EC2.create_key_pair' do + + after(:all) do + ec2.delete_key_pair('fog_key_pair') + end + + it "should return proper attributes" do + actual = ec2.create_key_pair('fog_key_pair') + actual.body[:key_fingerprint].should be_a(String) + actual.body[:key_material].should be_a(String) + actual.body[:key_name].should be_a(String) + actual.body[:request_id].should be_a(String) + end + +end diff --git a/spec/aws/ec2/delete_key_pair_spec.rb b/spec/aws/ec2/delete_key_pair_spec.rb new file mode 100644 index 000000000..93f45b52f --- /dev/null +++ b/spec/aws/ec2/delete_key_pair_spec.rb @@ -0,0 +1,15 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'EC2.delete_key_pair' do + + before(:all) do + ec2.create_key_pair('fog_key_pair') + end + + it "should return proper attributes" do + actual = ec2.delete_key_pair('fog_key_pair') + actual.body[:request_id].should be_a(String) + [false, true].should include(actual.body[:return]) + end + +end