1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

fixing up run/terminate instances docs/specs/etc

This commit is contained in:
Wesley Beary 2009-07-19 16:50:19 -07:00
parent b21946f475
commit b9af7b26f0
6 changed files with 87 additions and 18 deletions

View file

@ -6,8 +6,8 @@ module Fog
class RunInstances < Fog::Parsers::Base
def reset
@instance = { :monitoring => {}, :placement => {}, :product_codes => [] }
@response = { :group_set => [], :instance_set => [] }
@instance = { :instance_state => {}, :monitoring => {}, :placement => {}, :product_codes => [] }
@response = { :group_set => [], :instances_set => [] }
end
def start_element(name, attrs = [])
@ -25,6 +25,8 @@ module Fog
@instance[:ami_launch_index] = @value
when 'availabilityZone'
@instance[:placement][:availability_zone] = @value
when 'code'
@instance[:instance_state][:code] = @value.to_i
when 'dnsName'
@instance[:dns_name] = @value
when 'groupId'
@ -37,19 +39,19 @@ module Fog
@instance[:image_id] = @value
when 'instanceId'
@instance[:instance_id] = @value
when 'instanceState'
@instance[:instance_state] = @value
when 'instanceType'
@instance[:instance_type] = @value
when 'item'
unless @in_group_set || @in_product_codes
@response[:instance_set] << @instance
@instance = { :monitoring => {}, :placement => {}, :product_codes => [] }
@response[:instances_set] << @instance
@instance = { :instance_state => {}, :monitoring => {}, :placement => {}, :product_codes => [] }
end
when 'kernelId'
@instance[:kernel_id] = @value
when 'launchTime'
@instance[:launch_time] = Time.parse(@value)
when 'name'
@instance[:instance_state][:name] = @value
when 'ownerId'
@response[:owner_id] = @value
when 'platform'

View file

@ -7,7 +7,7 @@ module Fog
def reset
@instance = { :previous_state => {}, :shutdown_state => {} }
@response = { :instance_set => [] }
@response = { :instances_set => [] }
end
def start_element(name, attrs = [])
@ -21,14 +21,16 @@ module Fog
def end_element(name)
case name
when 'instanceId'
@instance[:instance_id] = @value
when 'item'
@response[:instance_set] << @instance
@response[:instances_set] << @instance
@instance = { :previous_state => {}, :shutdown_state => {} }
when 'code'
if @in_previous_state
@instance[:previous_state][:code] = @value
@instance[:previous_state][:code] = @value.to_i
elsif @in_shutdown_state
@instance[:shutdown_state][:code] = @value
@instance[:shutdown_state][:code] = @value.to_i
end
when 'name'
if @in_previous_state

View file

@ -33,7 +33,30 @@ module Fog
# * :virtual_name<~String> - ?
#
# ==== Returns
# FIXME: docs
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :group_set<~Array>: groups the instances are members in
# * group_name<~String> - Name of group
# * :instances_set<~Array>: returned instances
# * instance<~Hash>:
# * :ami_launch_index<~String> - 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
# * :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
# * :private_dns_name<~String> - private dns name, blank until instance is running
# * :reason<~String> - reason for most recent state transition, or blank
# * :owner_id<~String> - Id of owner
# * :request_id<~String> - Id of request
def run_instances(image_id, min_count, max_count, options = {})
request({
'Action' => 'RunInstances',

View file

@ -2,13 +2,23 @@ module Fog
module AWS
class EC2
# Launch specified instances
# Terminate specified instances
#
# ==== Parameters
# * instance_id<~Array> - Ids of instances to terminates
#
# ==== Returns
# FIXME: docs
# # * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :request_id<~String> - Id of request
# * :instances_set<~Array>:
# * :instance_id<~String> - id of the terminated instance
# * :previous_state<~Hash>: previous state of instance
# * :code<~Integer> - previous status code
# * :name<~String> - name of previous state
# * :shutdown_state<~Hash>: shutdown state of instance
# * :code<~Integer> - current status code
# * :name<~String> - name of current state
def terminate_instances(instance_id = [])
params = indexed_params('InstanceId', instance_id)
request({

View file

@ -3,13 +3,35 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe 'EC2.run_instances' do
after(:all) do
p ec2.terminate_instances([@instance_id])
ec2.terminate_instances([@instance_id])
end
it "should return proper attributes" do
actual = ec2.run_instances('ami-5ee70037', 1, 1)
@instance_id = actual.body[:instance_set].first[:instance_id]
p actual
@instance_id = actual.body[:instances_set].first[:instance_id]
actual.body[:group_set].should be_an(Array)
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[: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_an(Hash)
instance[:instance_state][:code].should be_an(Integer)
instance[:instance_state][:name].should be_an(String)
instance[:instance_type].should be_a(String)
# instance[:key_name].should be_a(String)
instance[:launch_time].should be_a(Time)
instance[:monitoring].should be_a(Hash)
[false, true].should include(instance[:monitoring][:state])
instance[:placement].should be_a(Hash)
instance[:placement][:availability_zone].should be_a(String)
instance[:private_dns_name].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)
actual.body[:reservation_id].should be_a(String)
end
end

View file

@ -3,12 +3,22 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe 'EC2.terminate_instances' do
before(:all) do
@instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body[:instance_set].first[:instance_id]
@instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body[:instances_set].first[:instance_id]
end
it "should return proper attributes" do
actual = ec2.terminate_instances([@instance_id])
p actual
actual.body[:request_id].should be_a(String)
actual.body[:instances_set].should be_an(Array)
instance = actual.body[:instances_set].select {|instance| instance[:instance_id] == @instance_id}.first
instance[:previous_state].should be_a(Hash)
previous_state = instance[:previous_state]
previous_state[:code].should be_a(Integer)
previous_state[:name].should be_a(String)
instance[:shutdown_state].should be_a(Hash)
shutdown_state = instance[:shutdown_state]
shutdown_state[:code].should be_a(Integer)
shutdown_state[:name].should be_a(String)
end
end