mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
update run_instances for block device mapping and other newer attributes
This commit is contained in:
parent
62e2a603ac
commit
cbd3550d35
5 changed files with 65 additions and 11 deletions
|
@ -6,14 +6,18 @@ module Fog
|
|||
class RunInstances < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@instance = { 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
|
||||
@block_device_mapping = {}
|
||||
@instance = { 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
|
||||
@response = { 'groupSet' => [], 'instancesSet' => [] }
|
||||
end
|
||||
|
||||
def start_element(name, attrs = [])
|
||||
if name == 'groupSet'
|
||||
case name
|
||||
when 'blockDeviceMapping'
|
||||
@in_block_device_mapping = true
|
||||
when 'groupSet'
|
||||
@in_group_set = true
|
||||
elsif name == 'productCodes'
|
||||
when 'productCodes'
|
||||
@in_product_codes = true
|
||||
end
|
||||
@value = ''
|
||||
|
@ -23,20 +27,38 @@ module Fog
|
|||
case name
|
||||
when 'amiLaunchIndex'
|
||||
@instance[name] = @value.to_i
|
||||
when 'architecture', 'dnsName', 'imageId', 'instanceId',
|
||||
'instanceType', 'ipAddress', 'kernelId', 'keyName',
|
||||
'privateDnsName', 'privateIpAddress', 'ramdiskId', 'reason',
|
||||
'rootDeviceType'
|
||||
@instance[name] = @value
|
||||
when 'availabilityZone'
|
||||
@instance['placement'][name] = @value
|
||||
when 'attachTime'
|
||||
@block_device_mapping[name] = Time.parse(@value)
|
||||
when 'blockDeviceMapping'
|
||||
@in_block_device_mapping = false
|
||||
when 'code'
|
||||
@instance['instanceState'][name] = @value.to_i
|
||||
when 'dnsName', 'kernelId', 'keyName', 'imageId', 'instanceId', 'instanceType', 'platform', 'privateDnsName', 'ramdiskId', 'reason', 'requestorId'
|
||||
@instance[name] = @value
|
||||
when 'deleteOnTermination'
|
||||
if @value == 'true'
|
||||
@block_device_mapping[name] = true
|
||||
else
|
||||
@block_device_mapping[name] = false
|
||||
end
|
||||
when 'deviceName', 'status', 'volumeId'
|
||||
@block_device_mapping[name] = @value
|
||||
when 'groupId'
|
||||
@response['groupSet'] << @value
|
||||
when 'groupSet'
|
||||
@in_group_set = false
|
||||
when 'item'
|
||||
unless @in_group_set || @in_product_codes
|
||||
if @in_block_device_mapping
|
||||
@instance['blockDeviceMapping'] << @block_device_mapping
|
||||
@block_device_mapping = {}
|
||||
elsif !@in_group_set && !@in_product_codes
|
||||
@response['instancesSet'] << @instance
|
||||
@instance = { 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
|
||||
@instance = { 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
|
||||
end
|
||||
when 'launchTime'
|
||||
@instance[name] = Time.parse(@value)
|
||||
|
|
|
@ -19,9 +19,13 @@ unless Fog.mocking?
|
|||
# (by default the maximum for an account is 20)
|
||||
# * options<~Hash>:
|
||||
# * 'Placement.AvailabilityZone'<~String> - Placement constraint for instances
|
||||
# * 'DeviceName'<~String> - ?
|
||||
# * 'Encoding'<~String> - ?
|
||||
# * 'BlockDeviceMapping.n.DeviceName'<~String> - where the volume will be exposed to instance
|
||||
# * 'BlockDeviceMapping.n.VirtualName'<~String> - volume virtual device name
|
||||
# * 'BlockDeviceMapping.n.Ebs.SnapshotId'<~String> - id of snapshot to boot volume from
|
||||
# * 'BlockDeviceMapping.n.Ebs.VolumeSize'<~String> - size of volume in GiBs required unless snapshot is specified
|
||||
# * 'BlockDeviceMapping.n.Ebs.DeleteOnTermination'<~String> - specifies whether or not to delete the volume on instance termination
|
||||
# * 'SecurityGroup.n'<~String> - Indexed names of security groups for instances
|
||||
# * 'InstanceInitiatedShutdownBehaviour'<~String> - specifies whether volumes are stopped or terminated when instance is shutdown
|
||||
# * 'InstanceType'<~String> - Type of instance to boot. Valid options
|
||||
# in ['m1.small', 'm1.large', 'm1.xlarge', 'c1.medium', 'c1.xlarge', 'm2.2xlarge', 'm2.4xlarge']
|
||||
# default is 'm1.small'
|
||||
|
@ -31,8 +35,6 @@ unless Fog.mocking?
|
|||
# disabled
|
||||
# * 'RamdiskId'<~String> - Id of ramdisk with which to launch
|
||||
# * 'UserData'<~String> - Additional data to provide to booting instances
|
||||
# * 'Version'<~String> - ?
|
||||
# * 'VirtualName'<~String> - ?
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
|
@ -42,6 +44,13 @@ unless Fog.mocking?
|
|||
# * 'instancesSet'<~Array>: returned instances
|
||||
# * instance<~Hash>:
|
||||
# * 'amiLaunchIndex'<~Integer> - reference to instance in launch group
|
||||
# * 'architecture'<~String> - architecture of image in [i386, x86_64]
|
||||
# * 'blockDeviceMapping'<~Array>
|
||||
# * 'attachTime'<~Time> - time of volume attachment
|
||||
# * 'deleteOnTermination'<~Boolean> - whether or not to delete volume on termination
|
||||
# * 'deviceName'<~String> - specifies how volume is exposed to instance
|
||||
# * 'status'<~String> - status of attached volume
|
||||
# * 'volumeId'<~String> - Id of attached volume
|
||||
# * 'dnsName'<~String> - public dns name, blank until instance is running
|
||||
# * 'imageId'<~String> - image id of ami used to launch instance
|
||||
# * 'instanceId'<~String> - id of the instance
|
||||
|
@ -49,6 +58,7 @@ unless Fog.mocking?
|
|||
# * 'code'<~Integer> - current status code
|
||||
# * 'name'<~String> - current status name
|
||||
# * 'instanceType'<~String> - type of instance
|
||||
# * 'ipAddress'<~String> - public ip address assigned to instance
|
||||
# * 'kernelId'<~String> - Id of kernel used to launch instance
|
||||
# * 'keyName'<~String> - name of key used launch instances or blank
|
||||
# * 'launchTime'<~Time> - time instance was launched
|
||||
|
@ -57,9 +67,12 @@ unless Fog.mocking?
|
|||
# * 'placement'<~Hash>:
|
||||
# * 'availabilityZone'<~String> - Availability zone of the instance
|
||||
# * 'privateDnsName'<~String> - private dns name, blank until instance is running
|
||||
# * 'privateIpAddress'<~String> - private ip address assigned to instance
|
||||
# * 'productCodes'<~Array> - Product codes for the instance
|
||||
# * 'ramdiskId'<~String> - Id of ramdisk used to launch instance
|
||||
# * 'reason'<~String> - reason for most recent state transition, or blank
|
||||
# * 'rootDeviceName'<~String> - specifies how the root device is exposed to the instance
|
||||
# * 'rootDeviceType'<~String> - root device type used by AMI in [ebs, instance-store]
|
||||
# * 'ownerId'<~String> - Id of owner
|
||||
# * 'requestId'<~String> - Id of request
|
||||
# * 'reservationId'<~String> - Id of reservation
|
||||
|
|
|
@ -22,6 +22,8 @@ describe 'EC2.describe_instances' do
|
|||
reservation['reservationId'].should be_a(String)
|
||||
instance = reservation['instancesSet'].select {|instance| instance['instanceId'] == @instance_id}.first
|
||||
instance['amiLaunchIndex'].should be_an(Integer)
|
||||
# instance['architecture'].should be_a(String)
|
||||
instance['blockDeviceMapping'].should be_an(Array)
|
||||
instance['dnsName'].should be_a(String)
|
||||
instance['imageId'].should be_a(String)
|
||||
instance['instanceId'].should be_a(String)
|
||||
|
@ -29,6 +31,7 @@ describe 'EC2.describe_instances' do
|
|||
instance['instanceState']['code'].should be_a(Integer)
|
||||
instance['instanceState']['name'].should be_a(String)
|
||||
instance['instanceType'].should be_a(String)
|
||||
# instance['ipAddress'].should be_a(String)
|
||||
instance['kernelId'].should be_a(String)
|
||||
instance['keyName'].should be_a(String) if instance['keyName']
|
||||
instance['launchTime'].should be_a(Time)
|
||||
|
@ -37,10 +40,13 @@ describe 'EC2.describe_instances' do
|
|||
instance['placement'].should be_a(Hash)
|
||||
instance['placement']['availabilityZone'].should be_a(String)
|
||||
instance['privateDnsName'].should be_a(String)
|
||||
# instance['privateIpAddress'].should be_a(String)
|
||||
instance['productCodes'].should be_an(Array)
|
||||
instance['productCodes'].first.should be_a(String) if instance['productCodes'].first
|
||||
instance['ramdiskId'].should be_a(String)
|
||||
instance['reason'].should be_a(String)
|
||||
# instance['rootDeviceName'].should be_a(String)
|
||||
instance['rootDeviceType'].should be_a(String)
|
||||
end
|
||||
|
||||
it "should return proper attributes with params" do
|
||||
|
@ -52,6 +58,8 @@ describe 'EC2.describe_instances' do
|
|||
reservation['reservationId'].should be_a(String)
|
||||
instance = reservation['instancesSet'].select {|instance| instance['instanceId'] == @instance_id}.first
|
||||
instance['amiLaunchIndex'].should be_an(Integer)
|
||||
# instance['architecture'].should be_a(String)
|
||||
instance['blockDeviceMapping'].should be_an(Array)
|
||||
instance['dnsName'].should be_a(String)
|
||||
instance['imageId'].should be_a(String)
|
||||
instance['instanceId'].should be_a(String)
|
||||
|
@ -59,6 +67,7 @@ describe 'EC2.describe_instances' do
|
|||
instance['instanceState']['code'].should be_a(Integer)
|
||||
instance['instanceState']['name'].should be_a(String)
|
||||
instance['instanceType'].should be_a(String)
|
||||
# instance['ipAddress'].should be_a(String)
|
||||
instance['kernelId'].should be_a(String)
|
||||
instance['keyName'].should be_a(String) if instance['keyName']
|
||||
instance['launchTime'].should be_a(Time)
|
||||
|
@ -67,10 +76,13 @@ describe 'EC2.describe_instances' do
|
|||
instance['placement'].should be_a(Hash)
|
||||
instance['placement']['availabilityZone'].should be_a(String)
|
||||
instance['privateDnsName'].should be_a(String)
|
||||
# instance['privateIpAddress'].should be_a(String)
|
||||
instance['productCodes'].should be_an(Array)
|
||||
instance['productCodes'].first.should be_a(String) if instance['productCodes'].first
|
||||
instance['ramdiskId'].should be_a(String)
|
||||
instance['reason'].should be_a(String)
|
||||
# instance['rootDeviceName'].should be_a(String)
|
||||
instance['rootDeviceType'].should be_a(String)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -16,6 +16,8 @@ describe 'EC2.run_instances' do
|
|||
actual.body['instancesSet'].should be_an(Array)
|
||||
instance = actual.body['instancesSet'].first
|
||||
instance['amiLaunchIndex'].should be_a(Integer)
|
||||
# instance['architecture'].should be_a(String)
|
||||
instance['blockDeviceMapping'].should be_an(Array)
|
||||
instance['dnsName'].should be_a(String)
|
||||
instance['imageId'].should be_a(String)
|
||||
instance['instanceId'].should be_a(String)
|
||||
|
@ -23,6 +25,7 @@ describe 'EC2.run_instances' do
|
|||
instance['instanceState']['code'].should be_an(Integer)
|
||||
instance['instanceState']['name'].should be_an(String)
|
||||
instance['instanceType'].should be_a(String)
|
||||
# instance['ipAddress'].should be_a(String)
|
||||
instance['kernelId'].should be_a(String)
|
||||
instance['keyName'].should be_a(String) if instance['keyName']
|
||||
instance['launchTime'].should be_a(Time)
|
||||
|
@ -31,11 +34,14 @@ describe 'EC2.run_instances' do
|
|||
instance['placement'].should be_a(Hash)
|
||||
instance['placement']['availabilityZone'].should be_a(String)
|
||||
instance['privateDnsName'].should be_a(String)
|
||||
# instance['privateIpAddress'].should be_a(String)
|
||||
instance['ramdiskId'].should be_a(String)
|
||||
instance['reason'].should be_a(String)
|
||||
actual.body['ownerId'].should be_a(String)
|
||||
actual.body['requestId'].should be_a(String)
|
||||
actual.body['reservationId'].should be_a(String)
|
||||
# instance['rootDeviceName'].should be_a(String)
|
||||
instance['rootDeviceType'].should be_a(String)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ require 'open-uri'
|
|||
|
||||
current_directory = File.dirname(__FILE__)
|
||||
require "#{current_directory}/../lib/fog"
|
||||
require "#{current_directory}/../lib/fog/bin"
|
||||
# Fog.mock!
|
||||
|
||||
unless defined?(LOADED_SPEC_OPTS)
|
||||
|
|
Loading…
Add table
Reference in a new issue