mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
Merge pull request #355 from engineyard/classiclink-fixes
classic link enhancements
This commit is contained in:
commit
e37c1aa31e
13 changed files with 289 additions and 23 deletions
|
@ -125,14 +125,17 @@ module Fog
|
|||
request :describe_vpcs
|
||||
request :describe_vpc_attribute
|
||||
request :describe_vpc_classic_link
|
||||
request :describe_vpc_classic_link_dns_support
|
||||
request :detach_network_interface
|
||||
request :detach_internet_gateway
|
||||
request :detach_volume
|
||||
request :detach_classic_link_vpc
|
||||
request :disable_vpc_classic_link
|
||||
request :disable_vpc_classic_link_dns_support
|
||||
request :disassociate_address
|
||||
request :disassociate_route_table
|
||||
request :enable_vpc_classic_link
|
||||
request :enable_vpc_classic_link_dns_support
|
||||
request :get_console_output
|
||||
request :get_password_data
|
||||
request :import_key_pair
|
||||
|
|
|
@ -47,6 +47,40 @@ module Fog
|
|||
true
|
||||
end
|
||||
|
||||
def classic_link_enabled?
|
||||
requires :identity
|
||||
service.describe_vpc_classic_link(:vpc_ids => [self.identity]).body['vpcSet'].first['classicLinkEnabled']
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
|
||||
def enable_classic_link
|
||||
requires :identity
|
||||
service.enable_vpc_classic_link(self.identity).body['return']
|
||||
end
|
||||
|
||||
def disable_classic_link
|
||||
requires :identity
|
||||
service.disable_vpc_classic_link(self.identity).body['return']
|
||||
end
|
||||
|
||||
def classic_link_dns_enabled?
|
||||
requires :identity
|
||||
service.describe_vpc_classic_link_dns_support(:vpc_ids => [self.identity]).body['vpcs'].first['classicLinkDnsSupported']
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
|
||||
def enable_classic_link_dns
|
||||
requires :identity
|
||||
service.enable_vpc_classic_link_dns_support(self.identity).body['return']
|
||||
end
|
||||
|
||||
def disable_classic_link_dns
|
||||
requires :identity
|
||||
service.disable_vpc_classic_link_dns_support(self.identity).body['return']
|
||||
end
|
||||
|
||||
# Create a vpc
|
||||
#
|
||||
# >> g = AWS.vpcs.new(:cidr_block => "10.1.2.0/24")
|
||||
|
|
|
@ -30,8 +30,10 @@ module Fog
|
|||
end
|
||||
else
|
||||
case name
|
||||
when 'vpcId', 'classicLinkEnabled'
|
||||
when 'vpcId'
|
||||
@vpc[name] = value
|
||||
when 'classicLinkEnabled'
|
||||
@vpc[name] = value == 'true'
|
||||
when 'item'
|
||||
@response['vpcSet'] << @vpc
|
||||
@vpc = { 'tagSet' => {} }
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Compute
|
||||
module AWS
|
||||
class DescribeVpcClassicLinkDnsSupport < Fog::Parsers::Base
|
||||
def reset
|
||||
@vpc = {}
|
||||
@response = { 'vpcs' => [] }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'vpcId'
|
||||
@vpc[name] = value
|
||||
when 'classicLinkDnsSupported'
|
||||
@vpc[name] = value == 'true'
|
||||
when 'item'
|
||||
@response['vpcs'] << @vpc
|
||||
@vpc = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -51,7 +51,8 @@ module Fog
|
|||
'enableDnsSupport' => true,
|
||||
'enableDnsHostnames' => false,
|
||||
'mapPublicIpOnLaunch' => false,
|
||||
'classicLinkEnabled' => false
|
||||
'classicLinkEnabled' => false,
|
||||
'classicLinkDnsSupport' => false
|
||||
}
|
||||
self.data[:vpcs].push(vpc)
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ module Fog
|
|||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'vpcSet' => vpc_data
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class AWS
|
||||
class Real
|
||||
require 'fog/aws/parsers/compute/describe_vpc_classic_link_dns_support'
|
||||
|
||||
# escribes the ClassicLink DNS support status of one or more VPCs
|
||||
#
|
||||
# ==== Parameters
|
||||
# * options<~Hash>
|
||||
# * vpc_ids<~Array> - An array of vpc ids to restrict results to
|
||||
# * 'MaxResults' - Maximum number of items to return
|
||||
# * 'NextToken' - The token for the next set of items to return
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'requestId'<~String> - Id of the request
|
||||
# * 'vpcs'<~Array> - Information about the ClassicLink DNS support status of the VPCs
|
||||
# * 'vpcId'<~String>
|
||||
# * 'classicLinkDnsSupported'<~Boolean>
|
||||
#
|
||||
# http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcClassicLinkDnsSupport.html
|
||||
|
||||
def describe_vpc_classic_link_dns_support(options={})
|
||||
params = {}
|
||||
params.merge!(Fog::AWS.indexed_param('VpcIds', options[:vpc_ids])) if options[:vpc_ids]
|
||||
request({
|
||||
'Action' => 'DescribeVpcClassicLinkDnsSupport',
|
||||
'MaxResults' => options['MaxResults'],
|
||||
'NextToken' => options['NextToken'],
|
||||
:parser => Fog::Parsers::Compute::AWS::DescribeVpcClassicLinkDnsSupport.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def describe_vpc_classic_link_dns_support(options={})
|
||||
response = Excon::Response.new
|
||||
|
||||
vpcs = self.data[:vpcs]
|
||||
|
||||
if options[:vpc_ids]
|
||||
vpcs = vpcs.select { |v| options[:vpc_ids].include?(v['vpcId']) }
|
||||
end
|
||||
|
||||
response.body = {'vpcs' => vpcs.map { |v| {"vpcId" => v['vpcId'], "classicLinkDnsSupported" => v['classicLinkDnsSupport']} } }
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -26,7 +26,6 @@ module Fog
|
|||
'DryRun' => dry_run,
|
||||
:parser => Fog::Parsers::Compute::AWS::Basic.new
|
||||
)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -52,7 +51,6 @@ module Fog
|
|||
elsif !vpc
|
||||
raise Fog::Compute::AWS::NotFound.new("The VPC '#{vpc_id}' does not exist.")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class AWS
|
||||
class Real
|
||||
require 'fog/aws/parsers/compute/basic'
|
||||
|
||||
# Disables DNS hostname resolution for ClassicLink
|
||||
#
|
||||
# ==== Parameters
|
||||
# * vpc_id<~String> - The ID of the ClassicLink-enabled VPC.
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'requestId'<~String> - Id of the request
|
||||
# * 'return'<~Boolean> - Whether the request succeeded
|
||||
#
|
||||
# http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DisableVpcClassicLinkDnsSupport.html
|
||||
|
||||
def disable_vpc_classic_link_dns_support(vpc_id)
|
||||
request(
|
||||
'Action' => 'DisableVpcClassicLinkDnsSupport',
|
||||
'VpcId' => vpc_id,
|
||||
:parser => Fog::Parsers::Compute::AWS::Basic.new
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def disable_vpc_classic_link_dns_support(vpc_id)
|
||||
response = Excon::Response.new
|
||||
unless vpc = self.data[:vpcs].find { |v| v['vpcId'] == vpc_id }
|
||||
raise Fog::Compute::AWS::NotFound.new("The VPC '#{vpc_id}' does not exist")
|
||||
end
|
||||
vpc['classicLinkDnsSupport'] = false
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'return' => true
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,45 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class AWS
|
||||
class Real
|
||||
require 'fog/aws/parsers/compute/basic'
|
||||
|
||||
# Enables a VPC to support DNS hostname resolution for ClassicLink
|
||||
#
|
||||
# ==== Parameters
|
||||
# * vpc_id<~String> - The ID of the ClassicLink-enabled VPC.
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'requestId'<~String> - Id of the request
|
||||
# * 'return'<~Boolean> - Whether the request succeeded
|
||||
#
|
||||
# http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EnableVpcClassicLinkDnsSupport.html
|
||||
|
||||
def enable_vpc_classic_link_dns_support(vpc_id)
|
||||
request(
|
||||
'Action' => 'EnableVpcClassicLinkDnsSupport',
|
||||
'VpcId' => vpc_id,
|
||||
:parser => Fog::Parsers::Compute::AWS::Basic.new
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def enable_vpc_classic_link_dns_support(vpc_id)
|
||||
response = Excon::Response.new
|
||||
unless vpc = self.data[:vpcs].find { |v| v['vpcId'] == vpc_id }
|
||||
raise Fog::Compute::AWS::NotFound.new("The VPC '#{vpc_id}' does not exist")
|
||||
end
|
||||
vpc['classicLinkDnsSupport'] = true
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'return' => true
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,26 @@
|
|||
Shindo.tests("Fog::Compute[:aws] | vpc", ['aws']) do
|
||||
|
||||
model_tests(Fog::Compute[:aws].vpcs, {:cidr_block => '10.0.10.0/28'}, true)
|
||||
model_tests(Fog::Compute[:aws].vpcs, {:cidr_block => '10.0.10.0/28'}, true) do
|
||||
tests("#enable_classic_link") do
|
||||
returns(false) { @instance.classic_link_enabled? }
|
||||
returns(true) { @instance.enable_classic_link }
|
||||
returns(true) { @instance.classic_link_enabled? }
|
||||
end
|
||||
|
||||
tests("#disable_classic_link") do
|
||||
returns(true) { @instance.disable_classic_link }
|
||||
returns(false) { @instance.classic_link_enabled? }
|
||||
end
|
||||
|
||||
tests("#enable_classic_link_dns") do
|
||||
returns(false) { @instance.classic_link_dns_enabled? }
|
||||
returns(true) { @instance.enable_classic_link_dns }
|
||||
returns(true) { @instance.classic_link_dns_enabled? }
|
||||
end
|
||||
|
||||
tests("#disable_classic_link") do
|
||||
returns(true) { @instance.disable_classic_link_dns }
|
||||
returns(false) { @instance.classic_link_dns_enabled? }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,6 +42,13 @@ Shindo.tests('Fog::Compute[:aws] | vpc requests', ['aws']) do
|
|||
'requestId' => String
|
||||
}
|
||||
|
||||
@describe_vpc_classic_link_dns_support_format = {
|
||||
"vpcs" => [{
|
||||
"vpcId" => String,
|
||||
"classicLinkDnsSupported" => Fog::Boolean
|
||||
}]
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
@vpc_id = nil
|
||||
|
@ -126,14 +133,14 @@ Shindo.tests('Fog::Compute[:aws] | vpc requests', ['aws']) do
|
|||
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'})
|
||||
body = Fog::Compute[:aws].describe_vpc_classic_link(:filters => {'tag-key' => 'foo'}).body
|
||||
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 = Fog::Compute[:aws].describe_vpc_classic_link(:vpc_ids => [@vpc_id]).body
|
||||
body['vpcSet'].first['classicLinkEnabled']
|
||||
end
|
||||
|
||||
|
@ -143,7 +150,7 @@ Shindo.tests('Fog::Compute[:aws] | vpc requests', ['aws']) do
|
|||
@group = Fog::Compute[:aws].security_groups.create :name => 'test-group', :description => 'vpc security group'
|
||||
|
||||
tests("attach_classic_link_vpc") do
|
||||
Fog::Compute[:aws].attach_classic_link_vpc(@server.id, @vpc_id, [@group])
|
||||
Fog::Compute[:aws].attach_classic_link_vpc(@server.id, @vpc_id, [@group.group_id])
|
||||
end
|
||||
|
||||
tests('describe_classic_link_instances').formats(@describe_classic_link_instances) do
|
||||
|
@ -155,6 +162,35 @@ Shindo.tests('Fog::Compute[:aws] | vpc requests', ['aws']) do
|
|||
Fog::Compute[:aws].describe_classic_link_instances().body['instancesSet']
|
||||
end
|
||||
|
||||
tests("enable_vpc_classic_link_dns_support('#{@vpc_id}')").formats(AWS::Compute::Formats::BASIC) do
|
||||
body = Fog::Compute[:aws].enable_vpc_classic_link_dns_support(@vpc_id).body
|
||||
body
|
||||
end
|
||||
|
||||
tests("#describe_vpc_classic_link_dns_support").formats(@describe_vpc_classic_link_dns_support_format) do
|
||||
Fog::Compute[:aws].describe_vpc_classic_link_dns_support.body
|
||||
end
|
||||
|
||||
tests("#describe_vpc_classic_link_dns_support(:vpc_ids => ['#{@vpc_id}'])").formats(@describe_vpc_classic_link_dns_support_format) do
|
||||
body = Fog::Compute[:aws].describe_vpc_classic_link_dns_support(:vpc_ids => [@vpc_id]).body
|
||||
returns(1) { body['vpcs'].count }
|
||||
returns(@vpc_id) { body['vpcs'].first['vpcId'] }
|
||||
returns(true) { body['vpcs'].first['classicLinkDnsSupported'] }
|
||||
body
|
||||
end
|
||||
|
||||
tests("disable_vpc_classic_link_dns_support('#{@vpc_id}')").formats(AWS::Compute::Formats::BASIC) do
|
||||
Fog::Compute[:aws].disable_vpc_classic_link_dns_support(@vpc_id).body
|
||||
end
|
||||
|
||||
tests("#describe_vpc_classic_link_dns_support(:vpc_ids => ['#{@vpc_id}'])").formats(@describe_vpc_classic_link_dns_support_format) do
|
||||
body = Fog::Compute[:aws].describe_vpc_classic_link_dns_support(:vpc_ids => [@vpc_id]).body
|
||||
returns(1) { body['vpcs'].count }
|
||||
returns(@vpc_id) { body['vpcs'].first['vpcId'] }
|
||||
returns(false) { body['vpcs'].first['classicLinkDnsSupported'] }
|
||||
body
|
||||
end
|
||||
|
||||
if !Fog.mocking?
|
||||
@server.destroy
|
||||
@server.wait_for {state == 'terminated'}
|
||||
|
@ -162,7 +198,7 @@ Shindo.tests('Fog::Compute[:aws] | vpc requests', ['aws']) do
|
|||
|
||||
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 = Fog::Compute[:aws].describe_vpc_classic_link(:vpc_ids => [@vpc_id]).body
|
||||
body['vpcSet'].first['classicLinkEnabled']
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue