mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Add implementation of DescribeInstanceStatus.
This commit is contained in:
parent
6a4eecac5a
commit
0ce523b110
4 changed files with 125 additions and 1 deletions
|
@ -57,6 +57,7 @@ module Fog
|
|||
request :describe_images
|
||||
request :describe_instances
|
||||
request :describe_reserved_instances
|
||||
request :describe_instance_status
|
||||
request :describe_key_pairs
|
||||
request :describe_placement_groups
|
||||
request :describe_regions
|
||||
|
@ -313,7 +314,7 @@ module Fog
|
|||
:host => @host,
|
||||
:path => @path,
|
||||
:port => @port,
|
||||
:version => '2011-05-15'
|
||||
:version => '2011-11-01'
|
||||
}
|
||||
)
|
||||
|
||||
|
|
64
lib/fog/aws/parsers/compute/describe_instance_status.rb
Normal file
64
lib/fog/aws/parsers/compute/describe_instance_status.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Compute
|
||||
module AWS
|
||||
class DescribeInstanceStatus < Fog::Parsers::Base
|
||||
|
||||
def new_instance
|
||||
@instance = { 'eventsSet' => [], 'instanceState' => {} }
|
||||
end
|
||||
|
||||
def new_event
|
||||
@event = {}
|
||||
end
|
||||
|
||||
def reset
|
||||
@instance_status = {}
|
||||
@response = { 'instanceStatusSet' => [] }
|
||||
@in_events_set = false
|
||||
new_event
|
||||
new_instance
|
||||
end
|
||||
|
||||
def start_element(name, attrs=[])
|
||||
super
|
||||
case name
|
||||
when 'eventsSet'
|
||||
@in_events_set = true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def end_element(name)
|
||||
if @in_events_set
|
||||
case name
|
||||
when 'code', 'description'
|
||||
@event[name] = value
|
||||
when 'notAfter', 'notBefore'
|
||||
@event[name] = Time.parse(value)
|
||||
when 'item'
|
||||
@instance['eventsSet'] << @event
|
||||
new_event
|
||||
when 'eventsSet'
|
||||
@in_events_set = false
|
||||
end
|
||||
else
|
||||
case name
|
||||
when 'instanceId', 'availabilityZone'
|
||||
@instance[name] = value
|
||||
when 'name', 'code'
|
||||
@instance['instanceState'][name] = value
|
||||
when 'item'
|
||||
@response['instanceStatusSet'] << @instance
|
||||
new_instance
|
||||
when 'requestId'
|
||||
@response[name] = value
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
36
lib/fog/aws/requests/compute/describe_instance_status.rb
Normal file
36
lib/fog/aws/requests/compute/describe_instance_status.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class AWS
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/compute/describe_instance_status'
|
||||
|
||||
def describe_instance_status(filters = {})
|
||||
raise ArgumentError.new("Filters must be a hash, but is a #{filters.class}.") unless filters.is_a?(Hash)
|
||||
|
||||
params = Fog::AWS.indexed_filters(filters)
|
||||
request({
|
||||
'Action' => 'DescribeInstanceStatus',
|
||||
:idempotent => true,
|
||||
:parser => Fog::Parsers::Compute::AWS::DescribeInstanceStatus.new
|
||||
}.merge!(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def describe_instance_status(filters = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
response.body = {
|
||||
'instanceStatusSet' => [],
|
||||
'requestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
|
||||
response
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -122,6 +122,25 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
|
|||
'requestId' => String
|
||||
}
|
||||
|
||||
@describe_instance_status_format = {
|
||||
'requestId' => String,
|
||||
'instanceStatusSet' => [{
|
||||
'instanceId' => String,
|
||||
'availabilityZone' => String,
|
||||
'instanceState' => {
|
||||
'code' => Integer,
|
||||
'name' => String
|
||||
},
|
||||
'eventsSet' => [{
|
||||
'code' => String,
|
||||
'description' => String,
|
||||
'notBefore' => Time,
|
||||
'notAfter' => Time
|
||||
}]
|
||||
}]
|
||||
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
@instance_id = nil
|
||||
|
@ -214,6 +233,10 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
|
|||
@reserved_instances
|
||||
end
|
||||
|
||||
tests('#describe_instance_status').formats(@describe_instance_status_format) do
|
||||
Fog::Compute[:aws].describe_instance_status.body
|
||||
end
|
||||
|
||||
if Fog.mocking?
|
||||
@reserved_instance_offering_id = @reserved_instances["reservedInstancesOfferingsSet"].first["reservedInstancesOfferingId"]
|
||||
tests("#purchase_reserved_instances_offering('#{@reserved_instance_offering_id}')").formats(@purchase_reserved_instances_offering_format) do
|
||||
|
|
Loading…
Reference in a new issue