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

[AWS|VPC] ability to describe classic link status

This commit is contained in:
Frederick Cheung 2015-01-11 15:50:28 +00:00
parent dd30ec7972
commit 3ac107e3ee
4 changed files with 139 additions and 0 deletions

View file

@ -121,6 +121,7 @@ module Fog
request :describe_volume_status
request :describe_vpcs
request :describe_vpc_attribute
request :describe_vpc_classic_link
request :detach_network_interface
request :detach_internet_gateway
request :detach_volume

View file

@ -0,0 +1,47 @@
module Fog
module Parsers
module Compute
module AWS
class DescribeVpcClassicLink < Fog::Parsers::Base
def reset
@vpc = { 'tagSet' => {} }
@response = { 'vpcSet' => [] }
@tag = {}
end
def start_element(name, attrs = [])
super
case name
when 'tagSet'
@in_tag_set = true
end
end
def end_element(name)
if @in_tag_set
case name
when 'item'
@vpc['tagSet'][@tag['key']] = @tag['value']
@tag = {}
when 'key', 'value'
@tag[name] = value
when 'tagSet'
@in_tag_set = false
end
else
case name
when 'vpcId', 'classicLinkEnabled'
@vpc[name] = value
when 'item'
@response['vpcSet'] << @vpc
@vpc = { 'tagSet' => {} }
when 'requestId'
@response[name] = value
end
end
end
end
end
end
end
end

View file

@ -0,0 +1,63 @@
module Fog
module Compute
class AWS
class Real
require 'fog/aws/parsers/compute/describe_vpc_classic_link'
# Describes the ClassicLink status of one or more VPCs.
#
# ==== Parameters
# * options<~Hash>
# * vpc_ids<~Array> - An array of vpc ids to restruct the results to
# * filters<~Hash> - Filters to restrict the results to. Recognises is-classic-link-enabled in addition
# to tag-key, tag-value and tag:key
# === Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'vpcSet'<~Array> - array of VpcClassicLink
# * 'vpcId'<~String>
# * 'classicLinkEnabled'<~Boolean>
# * 'tagSet'<~Hash>
#
# (Amazon API Reference)[http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcClassicLink.html
def describe_vpc_classic_link(options={})
params = {}
params.merge!(Fog::AWS.indexed_param('VpcId', options[:vpc_ids])) if options[:vpc_ids]
params.merge!(Fog::AWS.indexed_filters(options[:filters])) if options[:filters]
request({
'Action' => 'DescribeVpcClassicLink',
:parser => Fog::Parsers::Compute::AWS::DescribeVpcClassicLink.new
}.merge(params))
end
end
class Mock
def describe_vpc_classic_link(options={})
response = Excon::Response.new
vpcs = self.data[:vpcs]
if vpc_ids = options[:vpc_ids]
vpcs = vpc_ids.collect do |vpc_id|
vpc = vpcs.find{ |v| v['vpcId'] == vpc_id }
raise Fog::Compute::AWS::NotFound.new("The VPC '#{vpc_id}' does not exist") unless vpc
vpc
end
end
vpcs = apply_tag_filters(vpcs, options[:filters], 'vpcId') if options[:filters]
response.status = 200
vpc_data = vpcs.collect do |vpc|
{
'vpcId' => vpc['vpcId'],
'classicLinkEnabled' => vpc['classicLinkEnabled'],
'tagSet' => self.data[:tag_sets][vpc['vpcId']] || {}
}
end
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'vpcSet' => vpc_data
}
end
end
end
end
end

View file

@ -11,6 +11,16 @@ Shindo.tests('Fog::Compute[:aws] | vpc requests', ['aws']) do
'requestId' => String
}
@describe_vpcs_classic_link_format = {
'vpcSet' => [{
'vpcId' => String,
'tagSet' => Hash,
'classicLinkEnabled' => Fog::Boolean
}],
'requestId' => String
}
@describe_vpcs_format = {
'vpcSet' => [{
'vpcId' => String,
@ -99,6 +109,24 @@ Shindo.tests('Fog::Compute[:aws] | vpc requests', ['aws']) do
body
end
tests("describe_vpc_classic_link(:filters => {'tag-key' => 'foo'}").formats(@describe_vpcs_classic_link_format) do
body = Fog::Compute[:aws].describe_vpc_classic_link(:filters => {'tag-key' => 'foo'})
tests("returns 1 vpc").returns(1) { body['vpcSet'].size }
body
end
tests("enable_vpc_classic_link").returns(true) do
Fog::Compute[:aws].enable_vpc_classic_link @vpc_id
body = Fog::Compute[:aws].describe_vpc_classic_link(:vpc_ids => [@vpc_id])
body['vpcSet'].first['classicLinkEnabled']
end
tests("disable_vpc_classic_link").returns(false) do
Fog::Compute[:aws].disable_vpc_classic_link @vpc_id
body = Fog::Compute[:aws].describe_vpc_classic_link(:vpc_ids => [@vpc_id])
body['vpcSet'].first['classicLinkEnabled']
end
tests("#delete_vpc('#{@vpc_id}')").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].delete_vpc(@vpc_id).body
end