mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
first pass at run_instances
This commit is contained in:
parent
5a7b8a32a4
commit
d23a021594
5 changed files with 72 additions and 7 deletions
|
@ -300,6 +300,58 @@ module Fog
|
|||
}, Fog::Parsers::AWS::EC2::Basic.new)
|
||||
end
|
||||
|
||||
# Launch specified instances
|
||||
#
|
||||
# ==== Parameters
|
||||
# * image_id<~String> - Id of machine image to load on instances
|
||||
# * min_count<~Integer> - Minimum number of instances to launch. If this
|
||||
# exceeds the count of available instances, no instances will be
|
||||
# launched. Must be between 1 and maximum allowed for your account
|
||||
# (by default the maximum for an account is 20)
|
||||
# * max_count<~Integer> - Maximum number of instances to launch. If this
|
||||
# exceeds the number of available instances, the largest possible
|
||||
# number of instances above min_count will be launched instead. Must
|
||||
# be between 1 and maximum allowed for you account
|
||||
# (by default the maximum for an account is 20)
|
||||
# * options<~Hash>:
|
||||
# * :availability_zone<~String> - Placement constraint for instances
|
||||
# * :data<~String> - Additional data to provide to booting instances
|
||||
# * :device_name<~String> - ?
|
||||
# * :encoding<~String> - ?
|
||||
# * :group_id<~String> - Name of security group for instances
|
||||
# * :instance_type<~String> - Type of instance to boot. Valid options
|
||||
# in ['m1.small', 'm1.large', 'm1.xlarge', 'c1.medium', 'c1.xlarge']
|
||||
# default is 'm1.small'
|
||||
# * :kernel_id<~String> - Id of kernel with which to launch
|
||||
# * :key_name<~String> - Name of a keypair to add to booting instances
|
||||
# * :monitoring_enabled<~Boolean> - Enables monitoring, defaults to
|
||||
# disabled
|
||||
# * :ramdisk_id<~String> - Id of ramdisk with which to launch
|
||||
# * :version<~String> - ?
|
||||
# * :virtual_name<~String> - ?
|
||||
#
|
||||
# ==== Returns
|
||||
def run_instances(image_id, min_count, max_count, options = {})
|
||||
request({
|
||||
'Action' => 'RunInstances',
|
||||
'ImageId' => image_id,
|
||||
'MinCount' => min_count,
|
||||
'MaxCount' => max_count,
|
||||
'AvailabilityZone' => options[:availability_zone],
|
||||
'Data' => options[:data],
|
||||
'DeviceName' => options[:device_name],
|
||||
'Encoding' => options[:encoding],
|
||||
'GroupId' => options[:group_id],
|
||||
'InstanceType' => options[:instance_type],
|
||||
'KernelId' => options[:kernel_id],
|
||||
'KeyName' => options[:key_name],
|
||||
'Monitoring.Enabled' => options[:monitoring_enabled].nil? ? nil : "#{options[:monitoring_enabled]}",
|
||||
'RamdiskId' => options[:ramdisk_id],
|
||||
'Version' => options[:version],
|
||||
'VirtualName' => options[:virtual_name]
|
||||
}, Fog::Parsers::AWS::EC2::Basic.new)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def indexed_params(name, params)
|
||||
|
@ -338,6 +390,8 @@ module Fog
|
|||
:method => 'POST'
|
||||
})
|
||||
|
||||
p response
|
||||
|
||||
if parser && !response.body.empty?
|
||||
Nokogiri::XML::SAX::Parser.new(parser).parse(response.body.split(/<\?xml.*\?>/)[1])
|
||||
response.body = parser.response
|
||||
|
|
|
@ -143,7 +143,7 @@ module Fog
|
|||
|
||||
def reset
|
||||
@instance = { :instance_state => {}, :placement => [], :product_code_set => [] }
|
||||
@reservation = { :group_set => [], :instance_set => [] }
|
||||
@reservation = { :group_set => [], :instances_set => [] }
|
||||
@response = { :reservation_set => [] }
|
||||
end
|
||||
|
||||
|
@ -155,7 +155,7 @@ module Fog
|
|||
@in_subset = true
|
||||
end
|
||||
if name == 'instanceSet'
|
||||
@in_instance_set = true
|
||||
@in_instances_set = true
|
||||
end
|
||||
@value = ''
|
||||
end
|
||||
|
@ -178,13 +178,13 @@ module Fog
|
|||
@instance[:image_id] = @value
|
||||
when 'instanceId'
|
||||
@instance[:instance_id] = @value
|
||||
when 'instanceSet'
|
||||
@in_instance_set = false
|
||||
when 'instancesSet'
|
||||
@in_instances_set = false
|
||||
when 'instanceType'
|
||||
@instance[:instance_type] = @value
|
||||
when 'item'
|
||||
if @in_instance_set
|
||||
@reservation[:instance_set] << @instance
|
||||
if @in_instances_set
|
||||
@reservation[:instances_set] << @instance
|
||||
@instance = { :instance_state => {}, :placement => [], :product_code_set => [] }
|
||||
elsif !@in_subset
|
||||
@response[:reservation_set] << @reservation
|
||||
|
|
|
@ -13,6 +13,7 @@ describe 'EC2.describe_images' do
|
|||
image[:image_state].should be_a(String)
|
||||
image[:image_type].should be_a(String)
|
||||
[false, true].should include(image[:is_public])
|
||||
p actual
|
||||
end
|
||||
|
||||
it "should return proper attributes with params"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||
|
||||
describe 'EC2.instances' do
|
||||
describe 'EC2.describe_instances' do
|
||||
|
||||
it "should return proper attributes with no params" do
|
||||
actual = ec2.describe_instances
|
||||
|
|
10
spec/aws/ec2/run_instances_spec.rb
Normal file
10
spec/aws/ec2/run_instances_spec.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||
|
||||
describe 'EC2.run_instances' do
|
||||
|
||||
it "should return proper attributes" do
|
||||
actual = ec2.run_instances('ami-5ee70037', 1, 1)
|
||||
p actual
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue