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

[ninefold|compute] NAT functionality.

This commit is contained in:
Lincoln Stoll 2011-05-11 15:59:08 -07:00
parent 3fe91ca26f
commit 0b3630f124
8 changed files with 236 additions and 0 deletions

View file

@ -56,6 +56,12 @@ module Fog
request :associate_ip_address
request :list_public_ip_addresses
request :disassociate_ip_address
# NAT
request :enable_static_nat
request :disable_static_nat
request :create_ip_forwarding_rule
request :delete_ip_forwarding_rule
request :list_ip_forwarding_rules
class Mock

View file

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def create_ip_forwarding_rule(options = {})
request('createIpForwardingRule', options, :expects => [200],
:response_prefix => 'createipforwardingruleresponse', :response_type => Hash)
end
end
class Mock
def create_ip_forwarding_rule(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def delete_ip_forwarding_rule(options = {})
request('deleteIpForwardingRule', options, :expects => [200],
:response_prefix => 'deleteipforwardingruleresponse', :response_type => Hash)
end
end
class Mock
def delete_ip_forwarding_rule(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def disable_static_nat(options = {})
request('disableStaticNat', options, :expects => [200],
:response_prefix => 'disablestaticnatresponse', :response_type => Hash)
end
end
class Mock
def disable_static_nat(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def enable_static_nat(options = {})
request('enableStaticNat', options, :expects => [200],
:response_prefix => 'enablestaticnatresponse', :response_type => Hash)
end
end
class Mock
def enable_static_nat(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,23 @@
module Fog
module Ninefold
class Compute
class Real
def list_ip_forwarding_rules(options = {})
request('listIpForwardingRules', options, :expects => [200],
:response_prefix => 'listipforwardingrulesresponse/ipforwardingrule', :response_type => Hash)
end
end
class Mock
def list_ip_forwarding_rules(*args)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -318,6 +318,29 @@ class Ninefold
ADDRESSES = [ADDRESS]
DISASSOC_ADDRESS = {"jobid"=>Integer}
end
module Nat
ENABLE_NAT_RESPONSE = {
'success' => String
}
DISABLE_NAT_RESPONSE = {
'success' => Fog::Boolean
}
DELETE_RULE_RESPONSE = {
'success' => Fog::Boolean
}
FORWARDING_RULE = {
"id"=>Integer,
"protocol"=>String,
"virtualmachineid"=>Integer,
"virtualmachinename"=>String,
"ipaddressid"=>Integer,
"ipaddress"=>String,
"startport"=>Integer,
"endport"=>Integer,
"state"=>String
}
FORWARDING_RULES = [FORWARDING_RULE]
end
end
end
end

View file

@ -0,0 +1,92 @@
## Note:
# If needed, these tests will create a new VM and public IP address. Because this is expensive, you
# can optionally specify VM_ID and IP_ID as environment variables, and we will use those. Note:
# The IP must not already have static nat enabled or any port mappings.
Shindo.tests('Ninefold::Compute | server requests', ['ninefold']) do
if ENV['VM_ID'] && ENV['IP_ID']
@ipid, @vmid = ENV['IP_ID'], ENV['VM_ID']
else
begin
# Create a VM to work with
networks = Ninefold[:compute].list_networks
vm_job = Ninefold[:compute].deploy_virtual_machine(:serviceofferingid => Ninefold::Compute::TestSupport::SERVICE_OFFERING,
:templateid => Ninefold::Compute::TestSupport::TEMPLATE_ID,
:zoneid => Ninefold::Compute::TestSupport::ZONE_ID,
:networkids => networks[0]['id'])
@vm = Ninefold::Compute::TestSupport.wait_for_job(vm_job)['jobresult']['virtualmachine']
@vmid = @vm['id']
# Allocate a public IP to work with
ip_job = Ninefold[:compute].associate_ip_address(:zoneid => Ninefold::Compute::TestSupport::ZONE_ID)
@ip = Ninefold::Compute::TestSupport.wait_for_job(ip_job)['jobresult']['ipaddress']
@ipid = @ip['id']
rescue => e
puts "*** CREATING VM OR IP FAILED - PLEASE TEST AND CORRECT THIS FIRST"
raise e
end
end
tests('success') do
tests("#enable_static_nat()").formats(Ninefold::Compute::Formats::Nat::ENABLE_NAT_RESPONSE) do
pending if Fog.mocking?
Ninefold[:compute].enable_static_nat(:ipaddressid => @ipid, :virtualmachineid => @vmid)
end
tests("#create_ip_forwarding_rule()").formats(Ninefold::Compute::Formats::Nat::FORWARDING_RULE) do
pending if Fog.mocking?
job = Ninefold[:compute].create_ip_forwarding_rule(:ipaddressid => @ipid,
:protocol => 'TCP',
:startport => 22)
result = Ninefold::Compute::TestSupport.wait_for_job(job)['jobresult']['ipforwardingrule']
@fwd_rule_id = result['id']
result
end
tests("#list_ip_forwarding_rules()").formats(Ninefold::Compute::Formats::Nat::FORWARDING_RULES) do
pending if Fog.mocking?
Ninefold[:compute].list_ip_forwarding_rules
end
tests("#delete_ip_forwarding_rule()").formats(Ninefold::Compute::Formats::Nat::DELETE_RULE_RESPONSE) do
pending if Fog.mocking?
job = Ninefold[:compute].delete_ip_forwarding_rule(:id => @fwd_rule_id)
Ninefold::Compute::TestSupport.wait_for_job(job)['jobresult']
end
tests("#disable_static_nat()").formats(Ninefold::Compute::Formats::Nat::DISABLE_NAT_RESPONSE) do
pending if Fog.mocking?
job = Ninefold[:compute].disable_static_nat(:ipaddressid => @ipid)
Ninefold::Compute::TestSupport.wait_for_job(job)['jobresult']
end
end
tests('failure') do
tests("#associate_ip_address()").raises(Excon::Errors::HTTPStatusError) do
pending if Fog.mocking?
Ninefold[:compute].associate_ip_address
end
end
unless ENV['VM_ID'] && ENV['IP_ID']
begin
# Kill test VM
vm_job = Ninefold[:compute].destroy_virtual_machine(:id => @vmid)
Ninefold::Compute::TestSupport.wait_for_job(vm_job)
# Disassociate public IP
ip_job = Ninefold[:compute].disassociate_ip_address(:id => @ipid)
Ninefold::Compute::TestSupport.wait_for_job(ip_job)
rescue => e
puts "*** DESTROYING VM OR IP FAILED - PLEASE TEST AND CORRECT THIS FIRST"
raise e
end
end
end