From 43b23e91479ced058ba336c7b2debe11cefc61a4 Mon Sep 17 00:00:00 2001 From: Wesley Beary Date: Tue, 21 Jul 2009 10:56:38 -0700 Subject: [PATCH] fixe describe instances spec/docs and some missed stuff on run instances --- lib/fog/aws/parsers/ec2/describe_instances.rb | 2 +- lib/fog/aws/parsers/ec2/run_instances.rb | 4 +- .../aws/requests/ec2/describe_instances.rb | 26 +++++++- lib/fog/aws/requests/ec2/run_instances.rb | 5 +- spec/aws/ec2/describe_instances_spec.rb | 61 +++++++++++++++++-- spec/aws/ec2/run_instances_spec.rb | 4 +- 6 files changed, 93 insertions(+), 9 deletions(-) diff --git a/lib/fog/aws/parsers/ec2/describe_instances.rb b/lib/fog/aws/parsers/ec2/describe_instances.rb index 1c7423109..4adeb8f97 100644 --- a/lib/fog/aws/parsers/ec2/describe_instances.rb +++ b/lib/fog/aws/parsers/ec2/describe_instances.rb @@ -23,7 +23,7 @@ module Fog def end_element(name) case name when 'amiLaunchIndex' - @instance[:ami_launch_index] = @value + @instance[:ami_launch_index] = @value.to_i when 'availabilityZone' @instance[:placement] << @value when 'code' diff --git a/lib/fog/aws/parsers/ec2/run_instances.rb b/lib/fog/aws/parsers/ec2/run_instances.rb index 4c08612bc..a64435e3a 100644 --- a/lib/fog/aws/parsers/ec2/run_instances.rb +++ b/lib/fog/aws/parsers/ec2/run_instances.rb @@ -22,7 +22,7 @@ module Fog def end_element(name) case name when 'amiLaunchIndex' - @instance[:ami_launch_index] = @value + @instance[:ami_launch_index] = @value.to_i when 'availabilityZone' @instance[:placement][:availability_zone] = @value when 'code' @@ -33,6 +33,8 @@ module Fog @response[:group_set] << @value when 'groupSet' @in_group_set = false + when 'kernelId' + @instance[:kernel_id] = @value when 'keyName' @instance[:key_name] = @value when 'imageId' diff --git a/lib/fog/aws/requests/ec2/describe_instances.rb b/lib/fog/aws/requests/ec2/describe_instances.rb index 68ee65599..3d76a4257 100644 --- a/lib/fog/aws/requests/ec2/describe_instances.rb +++ b/lib/fog/aws/requests/ec2/describe_instances.rb @@ -11,7 +11,31 @@ module Fog # * response<~Fog::AWS::Response>: # * body<~Hash>: # * :request_id<~String> - Id of request - # FIXME: docs + # * :reservation_set<~Array>: + # * :group_set<~Array> - Group names for reservation + # * :owner_id<~String> - AWS Access Key ID of reservation owner + # * :reservation_id<~String> - Id of the reservation + # * :instances_set<~Array>: + # * instance<~Hash>: + # * :ami_launch_index<~Integer> - reference to instance in launch group + # * :dns_name<~String> - public dns name, blank until instance is running + # * :image_id<~String> - image id of ami used to launch instance + # * :instance_id<~String> - id of the instance + # * :instance_state<~Hash>: + # * :code<~Integer> - current status code + # * :name<~String> - current status name + # * :instance_type<~String> - type of instance + # * :kernel_id<~String> - Id of kernel used to launch instance + # * :key_name<~String> - name of key used launch instances or blank + # * :launch_time<~Time> - time instance was launched + # * :monitoring<~Hash>: + # * :state<~Boolean - state of monitoring + # * :placement<~Hash>: + # * :availability_zone<~String> - Availability zone of the instance + # * :product_codes<~Array> - Product codes for the instance + # * :private_dns_name<~String> - private dns name, blank until instance is running + # * :ramdisk_id<~String> - Id of ramdisk used to launch instance + # * :reason<~String> - reason for most recent state transition, or blank def describe_instances(instance_id = []) params = indexed_params('InstanceId', instance_id) request({ diff --git a/lib/fog/aws/requests/ec2/run_instances.rb b/lib/fog/aws/requests/ec2/run_instances.rb index 3b916fb84..e143da1a6 100644 --- a/lib/fog/aws/requests/ec2/run_instances.rb +++ b/lib/fog/aws/requests/ec2/run_instances.rb @@ -39,7 +39,7 @@ module Fog # * group_name<~String> - Name of group # * :instances_set<~Array>: returned instances # * instance<~Hash>: - # * :ami_launch_index<~String> - reference to instance in launch group + # * :ami_launch_index<~Integer> - reference to instance in launch group # * :dns_name<~String> - public dns name, blank until instance is running # * :image_id<~String> - image id of ami used to launch instance # * :instance_id<~String> - id of the instance @@ -47,6 +47,7 @@ module Fog # * :code<~Integer> - current status code # * :name<~String> - current status name # * :instance_type<~String> - type of instance + # * :kernel_id<~String> - Id of kernel used to launch instance # * :key_name<~String> - name of key used launch instances or blank # * :launch_time<~Time> - time instance was launched # * :monitoring<~Hash>: @@ -54,6 +55,8 @@ module Fog # * :placement<~Hash>: # * :availability_zone<~String> - Availability zone of the instance # * :private_dns_name<~String> - private dns name, blank until instance is running + # * :product_codes<~Array> - Product codes for the instance + # * :ramdisk_id<~String> - Id of ramdisk used to launch instance # * :reason<~String> - reason for most recent state transition, or blank # * :owner_id<~String> - Id of owner # * :request_id<~String> - Id of request diff --git a/spec/aws/ec2/describe_instances_spec.rb b/spec/aws/ec2/describe_instances_spec.rb index 4fdb1a0cf..02ede8b6e 100644 --- a/spec/aws/ec2/describe_instances_spec.rb +++ b/spec/aws/ec2/describe_instances_spec.rb @@ -14,11 +14,64 @@ describe 'EC2.describe_instances' do it "should return proper attributes with no params" do actual = ec2.describe_instances - p actual - # reservation = actual.body[:reservation_set].select {|reservation| reservation[:reservation_id] == @reservation_id} - # instance = reservation[:instances_set].select {|instance| instance[:instance_id] == @instance_id} + reservation = actual.body[:reservation_set].select {|reservation| reservation[:reservation_id] == @reservation_id}.first + reservation[:group_set].should be_an(Array) + reservation[:group_set].first.should be_a(String) + reservation[:owner_id].should be_a(String) + reservation[:reservation_id].should be_a(String) + instance = reservation[:instances_set].select {|instance| instance[:instance_id] == @instance_id}.first + instance[:ami_launch_index].should be_an(Integer) + instance[:dns_name].should be_a(String) + instance[:image_id].should be_a(String) + instance[:instance_id].should be_a(String) + instance[:instance_state].should be_a(Hash) + state = instance[:instance_state] + state[:code].should be_a(String) + state[:name].should be_a(String) + instance[:instance_type].should be_a(String) + instance[:kernel_id].should be_a(String) + # instance[:key_name].should be_a(String) + instance[:launch_time].should be_a(Time) + instance[:monitoring].should be_a(Hash) + [true, false].should include(instance[:monitoring][:state]) + instance[:placement].should be_an(Array) + instance[:placement].first.should be_a(String) + instance[:private_dns_name].should be_a(String) + instance[:product_codes].should be_an(Array) + # instance[:product_codes].first.should be_a(String) + instance[:ramdisk_id].should be_a(String) + instance[:reason].should be_a(String) end - it "should return proper attributes with params" + it "should return proper attributes with params" do + actual = ec2.describe_instances(@instance_id) + reservation = actual.body[:reservation_set].select {|reservation| reservation[:reservation_id] == @reservation_id}.first + reservation[:group_set].should be_an(Array) + reservation[:group_set].first.should be_a(String) + reservation[:owner_id].should be_a(String) + reservation[:reservation_id].should be_a(String) + instance = reservation[:instances_set].select {|instance| instance[:instance_id] == @instance_id}.first + instance[:ami_launch_index].should be_an(Integer) + instance[:dns_name].should be_a(String) + instance[:image_id].should be_a(String) + instance[:instance_id].should be_a(String) + instance[:instance_state].should be_a(Hash) + state = instance[:instance_state] + state[:code].should be_a(String) + state[:name].should be_a(String) + instance[:instance_type].should be_a(String) + instance[:kernel_id].should be_a(String) + # instance[:key_name].should be_a(String) + instance[:launch_time].should be_a(Time) + instance[:monitoring].should be_a(Hash) + [true, false].should include(instance[:monitoring][:state]) + instance[:placement].should be_an(Array) + instance[:placement].first.should be_a(String) + instance[:private_dns_name].should be_a(String) + instance[:product_codes].should be_an(Array) + # instance[:product_codes].first.should be_a(String) + instance[:ramdisk_id].should be_a(String) + instance[:reason].should be_a(String) + end end diff --git a/spec/aws/ec2/run_instances_spec.rb b/spec/aws/ec2/run_instances_spec.rb index 76dd35c6d..47cb4660b 100644 --- a/spec/aws/ec2/run_instances_spec.rb +++ b/spec/aws/ec2/run_instances_spec.rb @@ -13,7 +13,7 @@ describe 'EC2.run_instances' do actual.body[:group_set].first.should be_a(String) actual.body[:instances_set].should be_an(Array) instance = actual.body[:instances_set].first - instance[:ami_launch_index].should be_a(String) + instance[:ami_launch_index].should be_a(Integer) instance[:dns_name].should be_a(String) instance[:image_id].should be_a(String) instance[:instance_id].should be_a(String) @@ -21,6 +21,7 @@ describe 'EC2.run_instances' do instance[:instance_state][:code].should be_an(Integer) instance[:instance_state][:name].should be_an(String) instance[:instance_type].should be_a(String) + instance[:kernel_id].should be_a(String) # instance[:key_name].should be_a(String) instance[:launch_time].should be_a(Time) instance[:monitoring].should be_a(Hash) @@ -28,6 +29,7 @@ describe 'EC2.run_instances' do instance[:placement].should be_a(Hash) instance[:placement][:availability_zone].should be_a(String) instance[:private_dns_name].should be_a(String) + instance[:ramdisk_id].should be_a(String) instance[:reason].should be_a(String) actual.body[:owner_id].should be_a(String) actual.body[:request_id].should be_a(String)