mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2152 from TheWeatherChannel/master
Add ability to associate public ip with VPC instance on creation
This commit is contained in:
commit
94e7a322e0
7 changed files with 58 additions and 2 deletions
|
@ -372,7 +372,7 @@ module Fog
|
|||
@region = options[:region] ||= 'us-east-1'
|
||||
@instrumentor = options[:instrumentor]
|
||||
@instrumentor_name = options[:instrumentor_name] || 'fog.aws.compute'
|
||||
@version = options[:version] || '2012-12-01'
|
||||
@version = options[:version] || '2013-08-15'
|
||||
|
||||
if @endpoint = options[:endpoint]
|
||||
endpoint = URI.parse(@endpoint)
|
||||
|
|
|
@ -12,6 +12,7 @@ module Fog
|
|||
|
||||
attr_accessor :architecture
|
||||
attribute :ami_launch_index, :aliases => 'amiLaunchIndex'
|
||||
attribute :associate_public_ip, :aliases => 'associatePublicIP'
|
||||
attribute :availability_zone, :aliases => 'availabilityZone'
|
||||
attribute :block_device_mapping, :aliases => 'blockDeviceMapping'
|
||||
attribute :network_interfaces, :aliases => 'networkInterfaces'
|
||||
|
@ -172,6 +173,20 @@ module Fog
|
|||
# use of Security Group Ids when working in a VPC.
|
||||
if subnet_id
|
||||
options.delete('SecurityGroup')
|
||||
if associate_public_ip
|
||||
options['NetworkInterface.0.DeviceIndex'] = 0
|
||||
options['NetworkInterface.0.AssociatePublicIpAddress'] = associate_public_ip
|
||||
options['NetworkInterface.0.SubnetId'] = options['SubnetId']
|
||||
options.delete('SubnetId')
|
||||
if options['SecurityGroupId'].kind_of?(Array)
|
||||
options['SecurityGroupId'].each {|id|
|
||||
options["NetworkInterface.0.SecurityGroupId.#{options['SecurityGroupId'].index(id)}"] = id
|
||||
}
|
||||
else
|
||||
options["NetworkInterface.0.SecurityGroupId.0"] = options['SecurityGroupId']
|
||||
end
|
||||
options.delete('SecurityGroupId')
|
||||
end
|
||||
else
|
||||
options.delete('SubnetId')
|
||||
end
|
||||
|
|
|
@ -74,6 +74,8 @@ module Fog
|
|||
@response[name] = value
|
||||
when 'ebsOptimized'
|
||||
@instance['ebsOptimized'] = (value == 'true')
|
||||
when 'associatePublicIP'
|
||||
@instance['associatePublicIP'] = (value == 'true')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -141,6 +141,7 @@ module Fog
|
|||
instance_id = Fog::AWS::Mock.instance_id
|
||||
instance = {
|
||||
'amiLaunchIndex' => i,
|
||||
'associatePublicIP' => options['associatePublicIP'] || false,
|
||||
'architecture' => 'i386',
|
||||
'blockDeviceMapping' => [],
|
||||
'clientToken' => options['clientToken'],
|
||||
|
|
|
@ -2,7 +2,7 @@ Shindo.tests("Fog::Compute[:aws] | monitor", ['aws']) do
|
|||
|
||||
@instance = Fog::Compute[:aws].servers.new
|
||||
|
||||
[:addresses, :flavor, :key_pair, :key_pair=, :volumes].each do |association|
|
||||
[:addresses, :flavor, :key_pair, :key_pair=, :volumes, :associate_public_ip].each do |association|
|
||||
responds_to(association)
|
||||
end
|
||||
|
||||
|
@ -18,6 +18,16 @@ Shindo.tests("Fog::Compute[:aws] | monitor", ['aws']) do
|
|||
@instance.attributes[:monitoring] == false
|
||||
end
|
||||
|
||||
test('#associate_public_ip = true') do
|
||||
@instance.associate_public_ip = true
|
||||
@instance.attributes[:associate_public_ip] == true
|
||||
end
|
||||
|
||||
test('#associate_public_ip = false') do
|
||||
@instance.associate_public_ip = false
|
||||
@instance.associate_public_ip == false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('existing instance') do
|
||||
|
@ -40,6 +50,16 @@ Shindo.tests("Fog::Compute[:aws] | monitor", ['aws']) do
|
|||
@instance.monitoring == false
|
||||
end
|
||||
|
||||
test('#associate_public_ip = true') do
|
||||
@instance.associate_public_ip = true
|
||||
@instance.attributes[:associate_public_ip] == true
|
||||
end
|
||||
|
||||
test('#associate_public_ip = false') do
|
||||
@instance.associate_public_ip = false
|
||||
@instance.associate_public_ip == false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@instance.destroy
|
||||
|
|
|
@ -3,6 +3,7 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
|
|||
@instance_format = {
|
||||
'architecture' => String,
|
||||
'amiLaunchIndex' => Integer,
|
||||
'associatePublicIP' => Fog::Nullable::Boolean,
|
||||
'attachmentId' => Fog::Nullable::String,
|
||||
'blockDeviceMapping' => [Fog::Nullable::Hash],
|
||||
'clientToken' => Fog::Nullable::String,
|
||||
|
|
|
@ -161,6 +161,23 @@ Shindo.tests('Fog::Compute[:aws] | network interface requests', ['aws']) do
|
|||
Fog::Compute[:aws].delete_network_interface(@nic_id).body
|
||||
end
|
||||
|
||||
@server.destroy
|
||||
if !Fog.mocking?
|
||||
@server.wait_for { state == 'terminated' }
|
||||
# despite the fact that the state goes to 'terminated' we need a little delay for aws to do its thing
|
||||
sleep 5
|
||||
end
|
||||
|
||||
# Bring up another server to test vpc public IP association
|
||||
@server = Fog::Compute[:aws].servers.create(:flavor_id => 'm1.small', :subnet_id => @subnet_id, :associate_public_ip => true)
|
||||
@server.wait_for { ready? }
|
||||
@instance_id = @server.id
|
||||
|
||||
test("#associate_public_ip") do
|
||||
server = Fog::Compute[:aws].servers.get(@instance_id)
|
||||
server.public_ip_address.nil? == false
|
||||
end
|
||||
|
||||
# Clean up resources
|
||||
@server.destroy
|
||||
if !Fog.mocking?
|
||||
|
|
Loading…
Add table
Reference in a new issue