mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2486 from jsmapr1/master
[AWS] Add Assign Private IPs
This commit is contained in:
commit
61cd05f695
4 changed files with 138 additions and 0 deletions
|
@ -47,6 +47,7 @@ module Fog
|
|||
|
||||
request_path 'fog/aws/requests/compute'
|
||||
request :allocate_address
|
||||
request :assign_private_ip_addresses
|
||||
request :associate_address
|
||||
request :associate_dhcp_options
|
||||
request :attach_network_interface
|
||||
|
|
25
lib/fog/aws/parsers/compute/assign_private_ip_addresses.rb
Normal file
25
lib/fog/aws/parsers/compute/assign_private_ip_addresses.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Compute
|
||||
module AWS
|
||||
|
||||
class AssignPrivateIpAddresses < Fog::Parsers::Base
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'requestId'
|
||||
@response[name] = value
|
||||
when 'return'
|
||||
if value == 'true'
|
||||
@response[name] = true
|
||||
else
|
||||
@response[name] = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
60
lib/fog/aws/requests/compute/assign_private_ip_addresses.rb
Normal file
60
lib/fog/aws/requests/compute/assign_private_ip_addresses.rb
Normal file
|
@ -0,0 +1,60 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class AWS
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/compute/assign_private_ip_addresses'
|
||||
|
||||
# Assigns one or more secondary private IP addresses to the specified network interface.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * NetworkInterfaceId<~String> - The ID of the network interface
|
||||
# * PrivateIpAddresses<~Array> - One or more IP addresses to be assigned as a secondary private IP address (conditional)
|
||||
# * SecondaryPrivateIpAddressCount<~String> - The number of secondary IP addresses to assign (conditional)
|
||||
# * AllowReassignment<~Boolean> - Whether to reassign an IP address
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'requestId'<~String> - The ID of the request.
|
||||
# * 'return'<~Boolean> - success?
|
||||
#
|
||||
# {Amazon API Reference}[http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-AssignPrivateIpAddresses.html]
|
||||
def assign_private_ip_addresses(network_interface_id, options={})
|
||||
|
||||
if options['PrivateIpAddresses'] && options['SecondaryPrivateIpAddressCount']
|
||||
raise Fog::Compute::AWS::Error.new("You may specify secondaryPrivateIpAddressCount or specific secondary private IP addresses, but not both.")
|
||||
end
|
||||
|
||||
if private_ip_addresses = options.delete('PrivateIpAddresses')
|
||||
options.merge!(Fog::AWS.indexed_param('PrivateIpAddress.%d', [*private_ip_addresses]))
|
||||
end
|
||||
|
||||
request({
|
||||
'Action' => 'AssignPrivateIpAddresses',
|
||||
'NetworkInterfaceId' => network_interface_id,
|
||||
:parser => Fog::Parsers::Compute::AWS::AssignPrivateIpAddresses.new
|
||||
}.merge(options))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def assign_private_ip_addresses(network_interface_id, options={})
|
||||
if options['PrivateIpAddresses'] && options['SecondaryPrivateIpAddressCount']
|
||||
raise Fog::Compute::AWS::Error.new("You may specify secondaryPrivateIpAddressCount or specific secondary private IP addresses, but not both.")
|
||||
end
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'return' => true
|
||||
}
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
52
tests/aws/requests/compute/assign_private_ip_tests.rb
Normal file
52
tests/aws/requests/compute/assign_private_ip_tests.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
Shindo.tests('Fog::Compute[:aws] | internet_gateway requests', ['aws']) do
|
||||
|
||||
tests('success') do
|
||||
|
||||
@vpc=Fog::Compute[:aws].vpcs.create('cidr_block' => '10.0.10.0/24')
|
||||
@vpc_id = @vpc.id
|
||||
|
||||
@subnet=Fog::Compute[:aws].subnets.create('vpc_id' => @vpc_id, 'cidr_block' => '10.0.10.0/24')
|
||||
@subnet_id = @subnet.subnet_id
|
||||
|
||||
@network_interface = Fog::Compute[:aws].network_interfaces.new(:subnet_id => @subnet_id)
|
||||
@network_interface.save
|
||||
@network_interface_id = @network_interface.network_interface_id
|
||||
|
||||
@ip_address = Fog::AWS::Mock.ip_address
|
||||
@second_ip_address = Fog::AWS::Mock.ip_address
|
||||
|
||||
tests("#assign_private_ip_addresses('#{@network_interface_id}', {'PrivateIpAddresses'=>['#{@ip_address}','#{@second_ip_address}']})").formats(AWS::Compute::Formats::BASIC) do
|
||||
Fog::Compute[:aws].assign_private_ip_addresses(@network_interface_id, { 'PrivateIpAddresses' =>[@ip_address, @second_ip_address]}).body
|
||||
end
|
||||
|
||||
tests("#assign_private_ip_addresses('#{@network_interface_id}', {'SecondaryPrivateIpAddressCount'=>4})").formats(AWS::Compute::Formats::BASIC) do
|
||||
Fog::Compute[:aws].assign_private_ip_addresses(@network_interface_id, {'SecondaryPrivateIpAddressCount'=>4}).body
|
||||
end
|
||||
|
||||
@network_interface.destroy
|
||||
@subnet.destroy
|
||||
@vpc.destroy
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
@vpc=Fog::Compute[:aws].vpcs.create('cidr_block' => '10.0.10.0/24')
|
||||
@vpc_id = @vpc.id
|
||||
|
||||
@subnet=Fog::Compute[:aws].subnets.create('vpc_id' => @vpc_id, 'cidr_block' => '10.0.10.0/24')
|
||||
@subnet_id = @subnet.subnet_id
|
||||
|
||||
@network_interface = Fog::Compute[:aws].network_interfaces.new(:subnet_id => @subnet_id)
|
||||
@network_interface.save
|
||||
@network_interface_id = @network_interface.network_interface_id
|
||||
|
||||
@ip_address = Fog::AWS::Mock.ip_address
|
||||
|
||||
tests("#assign_private_ip_addresses('#{@network_interface_id}', {'PrivateIpAddresses'=>['#{@ip_address}','#{@second_ip_address}'], 'SecondaryPrivateIpAddressCount'=>4 })").raises(Fog::Compute::AWS::Error) do
|
||||
Fog::Compute[:aws].assign_private_ip_addresses(@network_interface_id, { 'PrivateIpAddresses' =>[@ip_address, @second_ip_address], 'SecondaryPrivateIpAddressCount'=>4 }).body
|
||||
end
|
||||
|
||||
@network_interface.destroy
|
||||
@subnet.destroy
|
||||
@vpc.destroy
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue