mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[ninefold|compute] IP Address requests.
This commit is contained in:
parent
41cbff4acc
commit
ad7b299d20
6 changed files with 127 additions and 1 deletions
|
@ -52,6 +52,10 @@ module Fog
|
|||
request :query_async_job_result
|
||||
# Networks
|
||||
request :list_networks
|
||||
# Addresses
|
||||
request :associate_ip_address
|
||||
request :list_public_ip_addresses
|
||||
request :disassociate_ip_address
|
||||
|
||||
class Mock
|
||||
|
||||
|
|
23
lib/fog/compute/requests/ninefold/associate_ip_address.rb
Normal file
23
lib/fog/compute/requests/ninefold/associate_ip_address.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Ninefold
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
def associate_ip_address(options = {})
|
||||
request('associateIpAddress', options, :expects => [200],
|
||||
:response_prefix => 'associateipaddressresponse', :response_type => Hash)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def associate_ip_address(*args)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/compute/requests/ninefold/disassociate_ip_address.rb
Normal file
23
lib/fog/compute/requests/ninefold/disassociate_ip_address.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Ninefold
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
def disassociate_ip_address(options = {})
|
||||
request('disassociateIpAddress', options, :expects => [200],
|
||||
:response_prefix => 'disassociateipaddressresponse', :response_type => Hash)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def disassociate_ip_address(*args)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,7 +5,7 @@ module Fog
|
|||
|
||||
def list_public_ip_addresses(options = {})
|
||||
request('listPublicIpAddresses', options, :expects => [200],
|
||||
:response_prefix => 'listpublicipaddressesresponse/publicipaddress', :response_type => Array)
|
||||
:response_prefix => 'listpublicipaddressesresponse/publicipaddress', :response_type => Hash)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
43
tests/compute/requests/ninefold/address_tests.rb
Normal file
43
tests/compute/requests/ninefold/address_tests.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
Shindo.tests('Ninefold::Compute | server requests', ['ninefold']) do
|
||||
|
||||
tests('success') do
|
||||
|
||||
|
||||
tests("#associate_ip_address()").formats(Ninefold::Compute::Formats::Addresses::ADDRESS) do
|
||||
pending if Fog.mocking?
|
||||
job = newaddress = Ninefold[:compute].associate_ip_address(:zoneid => Ninefold::Compute::TestSupport::ZONE_ID)
|
||||
while Ninefold[:compute].query_async_job_result(:jobid => job['jobid'])['jobstatus'] == 0
|
||||
sleep 1
|
||||
end
|
||||
result = Ninefold[:compute].query_async_job_result(:jobid => job['jobid'])['jobresult']['ipaddress']
|
||||
@newaddressid = result['id']
|
||||
Ninefold::Compute::Formats::Addresses::fill_address_data(result)
|
||||
end
|
||||
|
||||
tests("#list_public_ip_addresses()").formats(Ninefold::Compute::Formats::Addresses::ADDRESSES) do
|
||||
pending if Fog.mocking?
|
||||
result = Ninefold[:compute].list_public_ip_addresses
|
||||
Ninefold::Compute::Formats::Addresses::fill_address_data(result)
|
||||
end
|
||||
|
||||
tests("#disassociate_ip_address()").formats(Ninefold::Compute::Formats::Addresses::DISASSOC_ADDRESS) do
|
||||
pending if Fog.mocking?
|
||||
job = Ninefold[:compute].disassociate_ip_address(:id => @newaddressid)
|
||||
while Ninefold[:compute].query_async_job_result(:jobid => job['jobid'])['jobstatus'] == 0
|
||||
sleep 1
|
||||
end
|
||||
job
|
||||
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
|
||||
|
||||
end
|
|
@ -275,6 +275,39 @@ class Ninefold
|
|||
"securitygroupenabled"=>Fog::Boolean
|
||||
}]
|
||||
end
|
||||
module Addresses
|
||||
def fill_address_data(data)
|
||||
if data.kind_of? Hash
|
||||
data['virtualmachineid'] ||= 0
|
||||
data['virtualmachinename'] ||= ''
|
||||
elsif data.kind_of? Array
|
||||
data.each {|d| fill_address_data(d) }
|
||||
end
|
||||
data
|
||||
end
|
||||
|
||||
module_function :fill_address_data
|
||||
ADDRESS = {
|
||||
"id"=>Integer,
|
||||
"ipaddress"=>String,
|
||||
"allocated"=>String,
|
||||
"zoneid"=>Integer,
|
||||
"zonename"=>String,
|
||||
"issourcenat"=>Fog::Boolean,
|
||||
"account"=>String,
|
||||
"domainid"=>Integer,
|
||||
"domain"=>String,
|
||||
"forvirtualnetwork"=>Fog::Boolean,
|
||||
"isstaticnat"=>Fog::Boolean,
|
||||
"associatednetworkid"=>Integer,
|
||||
"networkid"=>Integer,
|
||||
"state"=>String,
|
||||
"virtualmachineid"=>Integer,
|
||||
"virtualmachinename"=>String
|
||||
}
|
||||
ADDRESSES = [ADDRESS]
|
||||
DISASSOC_ADDRESS = {"jobid"=>Integer}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue