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

first pass at getting all of run/terminate instances requests/parsers/specs going

This commit is contained in:
Wesley Beary 2009-07-17 00:36:42 -07:00
parent 8b270bbea7
commit 694c8b65d7
8 changed files with 191 additions and 9 deletions

View file

@ -22,6 +22,8 @@ require "#{parsers_directory}/describe_key_pairs"
require "#{parsers_directory}/describe_security_groups"
require "#{parsers_directory}/describe_snapshots"
require "#{parsers_directory}/describe_volumes"
require "#{parsers_directory}/run_instances"
require "#{parsers_directory}/terminate_instances"
requests_directory = "#{current_directory}/requests/ec2"
require "#{requests_directory}/allocate_address"
@ -43,6 +45,8 @@ require "#{requests_directory}/describe_snapshots"
require "#{requests_directory}/describe_volumes"
require "#{requests_directory}/release_address"
require "#{requests_directory}/run_instances"
require "#{requests_directory}/terminate_instances"
module Fog
module AWS

View file

@ -15,14 +15,12 @@ module Fog
end
def start_element(name, attrs = [])
if name == 'ipPermissions'
@in_ip_permissions = true
end
if name == 'groups'
@in_groups = true
end
if name == 'ip_ranges'
if name == 'ipRanges'
@in_ip_ranges = true
elsif name == 'ipPermissions'
@in_ip_permissions = true
elsif name == 'groups'
@in_groups = true
end
@value = ''
end

View file

@ -0,0 +1,87 @@
module Fog
module Parsers
module AWS
module EC2
class RunInstances < Fog::Parsers::Base
def reset
@instance = { :monitoring => {}, :placement => {}, :product_codes => [] }
@response = { :group_set => [], :instance_set => [] }
end
def start_element(name, attrs = [])
if name == 'groupSet'
@in_group_set = true
elsif name == 'productCodes'
@in_product_codes = true
end
@value = ''
end
def end_element(name)
case name
when 'amiLaunchIndex'
@instance[:ami_launch_index] = @value
when 'availabilityZone'
@instance[:placement][:availability_zone] = @value
when 'dnsName'
@instance[:dns_name] = @value
when 'enabled'
if @value == 'true'
@instance[:monitoring][:enabled] = true
else
@instance[:monitoring][:enabled] = false
end
when 'groupId'
@response[:group_set] << @value
when 'groupSet'
@in_group_set = false
when 'keyName'
@instance[:key_name] = @value
when 'imageId'
@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 => [] }
end
when 'kernelId'
@instance[:kernel_id] = @value
when 'launchTime'
@instance[:launch_time] = Time.parse(@value)
when 'ownerId'
@response[:owner_id] = @value
when 'platform'
@instance[:platform] = @value
when 'privateDnsName'
@instance[:private_dns_name] = @value
when 'product_code'
@instance[:product_codes] << @value
when 'productCodes'
@in_product_codes = false
when 'ramdiskId'
@instance[:ramdisk_id] = @value
when 'reason'
@instance[:reason] = @value
when 'requestId'
@response[:request_id] = @value
when 'requestorId'
@instance[:requestor_id] = @value
when 'reservationId'
@response[:reservation_id] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,53 @@
module Fog
module Parsers
module AWS
module EC2
class TerminateInstances < Fog::Parsers::Base
def reset
@instance = { :previous_state => {}, :shutdown_state => {} }
@response = { :instance_set => [] }
end
def start_element(name, attrs = [])
if name == 'previousState'
@in_previous_state = true
elsif name == 'shutdownState'
@in_shutdown_state = true
end
@value = ''
end
def end_element(name)
case name
when 'item'
@response[:instance_set] << @instance
@instance = { :previous_state => {}, :shutdown_state => {} }
when 'code'
if @in_previous_state
@instance[:previous_state][:code] = @value
elsif @in_shutdown_state
@instance[:shutdown_state][:code] = @value
end
when 'name'
if @in_previous_state
@instance[:previous_state][:name] = @value
elsif @in_shutdown_state
@instance[:shutdown_state][:name] = @value
end
when 'previousState'
@in_previous_state = false
when 'requestId'
@response[:request_id] = @value
when 'shutdownState'
@in_shutdown_state = false
end
end
end
end
end
end
end

View file

@ -33,6 +33,7 @@ module Fog
# * :virtual_name<~String> - ?
#
# ==== Returns
# FIXME: docs
def run_instances(image_id, min_count, max_count, options = {})
request({
'Action' => 'RunInstances',
@ -51,7 +52,7 @@ module Fog
'RamdiskId' => options[:ramdisk_id],
'Version' => options[:version],
'VirtualName' => options[:virtual_name]
}, Fog::Parsers::AWS::EC2::Basic.new)
}, Fog::Parsers::AWS::EC2::RunInstances.new)
end
end

View file

@ -0,0 +1,21 @@
module Fog
module AWS
class EC2
# Launch specified instances
#
# ==== Parameters
# * instance_id<~Array> - Ids of instances to terminates
#
# ==== Returns
# FIXME: docs
def terminate_instances(instance_id = [])
params = indexed_params('InstanceId', instance_id)
request({
'Action' => 'TerminateInstances'
}.merge!(params), Fog::Parsers::AWS::EC2::TerminateInstances.new)
end
end
end
end

View file

@ -2,9 +2,13 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe 'EC2.run_instances' do
after(:all) do
p ec2.terminate_instances([@instance_id])
end
it "should return proper attributes" do
pending
actual = ec2.run_instances('ami-5ee70037', 1, 1)
@instance_id = actual.body[:instance_set].first[:instance_id]
p actual
end

View file

@ -0,0 +1,14 @@
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]
end
it "should return proper attributes" do
actual = ec2.terminate_instances([@instance_id])
p actual
end
end