mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
first pass at describe instances
This commit is contained in:
parent
cdf01e9cd7
commit
1a7a98e78d
3 changed files with 106 additions and 0 deletions
|
@ -210,6 +210,22 @@ module Fog
|
|||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeImages.new)
|
||||
end
|
||||
|
||||
# Describe all or specified instances
|
||||
#
|
||||
# ==== Parameters
|
||||
# instance_id<~Array>:: List of instance ids to describe, defaults to all
|
||||
#
|
||||
# ==== Returns
|
||||
# response::
|
||||
# body<~Hash>::
|
||||
# :request_id<~String>:: Id of request
|
||||
def describe_instances(instance_id = [])
|
||||
params = indexed_params('InstanceId', instance_id)
|
||||
request({
|
||||
'Action' => 'DescribeInstances',
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeInstances.new)
|
||||
end
|
||||
|
||||
# Describe all or specified key pairs
|
||||
#
|
||||
# ==== Parameters
|
||||
|
|
|
@ -139,6 +139,84 @@ module Fog
|
|||
|
||||
end
|
||||
|
||||
class DescribeInstances < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@instance = { :instance_state => {}, :placement => [], :product_code_set => [] }
|
||||
@reservation = { :group_set => [], :instance_set => [] }
|
||||
@response = { :reservation_set => [] }
|
||||
end
|
||||
|
||||
def start_element(name, attrs = [])
|
||||
if name == 'groupSet'
|
||||
@in_subset = true
|
||||
end
|
||||
if name == 'productCodeSet'
|
||||
@in_subset = true
|
||||
end
|
||||
if name == 'instanceSet'
|
||||
@in_instance_set = true
|
||||
end
|
||||
@value = ''
|
||||
end
|
||||
|
||||
def end_element
|
||||
case name
|
||||
when 'amiLaunchIndex'
|
||||
@instance[:ami_launch_index] = @value
|
||||
when 'availabilityZone'
|
||||
@instance[:placement] << @value
|
||||
when 'code'
|
||||
@instance[:instance_state][:code] = @value
|
||||
when 'dnsNmae'
|
||||
@instance[:dns_name] = @value
|
||||
when 'groupId'
|
||||
@reservation[:group_set] << @value
|
||||
when 'groupSet'
|
||||
@in_subset = false
|
||||
when 'imageId'
|
||||
@instance[:image_id] = @value
|
||||
when 'instanceId'
|
||||
@instance[:instance_id] = @value
|
||||
when 'instanceSet'
|
||||
@in_instance_set = false
|
||||
when 'instanceType'
|
||||
@instance[:instance_type] = @value
|
||||
when 'item'
|
||||
if @in_instance_set
|
||||
@reservation[:instance_set] << @instance
|
||||
@instance = { :instance_state => {}, :placement => [], :product_code_set => [] }
|
||||
elsif !@in_subset
|
||||
@response[:reservation_set] << @reservation
|
||||
@reservation = { :group_set => [], :instance_set => [] }
|
||||
end
|
||||
when 'kernelId'
|
||||
@instance[:kernel_id] = @value
|
||||
when 'keyName'
|
||||
@instance[:key_name] = @value
|
||||
when 'launchTime'
|
||||
@instance[:launch_time] = Time.parse(@value)
|
||||
when 'name'
|
||||
@instance[:instance_state][:name] = @value
|
||||
when 'ownerId'
|
||||
@reservation[:owner_id] = @value
|
||||
when 'requestId'
|
||||
@response[:request_id] = @value
|
||||
when 'reservationId'
|
||||
@reservation[:reservation_id] = @value
|
||||
when 'privateDnsName'
|
||||
@instance[:private_dns_name] = @value
|
||||
when 'productCode'
|
||||
@instance[:product_code_set] << @value
|
||||
when 'productCodeSet'
|
||||
@in_subset = false
|
||||
when 'ramdiskId'
|
||||
@instance[:ramdisk_id] = @value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class DescribeKeyPairs < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
|
|
12
spec/aws/ec2/describe_instances_spec.rb
Normal file
12
spec/aws/ec2/describe_instances_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||
|
||||
describe 'EC2.instances' do
|
||||
|
||||
it "should return proper attributes with no params" do
|
||||
actual = ec2.describe_instances
|
||||
p actual
|
||||
end
|
||||
|
||||
it "should return proper attributes with params"
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue