mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace|networks] Add Cloud Networks requests.
This commit is contained in:
parent
31b72b42f2
commit
b2601eb913
6 changed files with 110 additions and 0 deletions
|
@ -62,6 +62,11 @@ module Fog
|
|||
request :set_metadata_item
|
||||
request :delete_metadata_item
|
||||
|
||||
request :list_networks
|
||||
request :get_network
|
||||
request :create_network
|
||||
request :delete_network
|
||||
|
||||
class Mock
|
||||
include Fog::Rackspace::MockData
|
||||
|
||||
|
|
23
lib/fog/rackspace/requests/compute_v2/create_network.rb
Normal file
23
lib/fog/rackspace/requests/compute_v2/create_network.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def create_network(label, cidr)
|
||||
data = {
|
||||
'network' => {
|
||||
'label' => label,
|
||||
'cidr' => cidr
|
||||
}
|
||||
}
|
||||
|
||||
request(
|
||||
:method => 'POST',
|
||||
:body => Fog::JSON.encode(data),
|
||||
:path => "os-networksv2",
|
||||
:expects => 200
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
11
lib/fog/rackspace/requests/compute_v2/delete_network.rb
Normal file
11
lib/fog/rackspace/requests/compute_v2/delete_network.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def delete_network(id)
|
||||
request(:method => 'DELETE', :path => "os-networksv2/#{id}", :expects => 202)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
11
lib/fog/rackspace/requests/compute_v2/get_network.rb
Normal file
11
lib/fog/rackspace/requests/compute_v2/get_network.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def get_network(id)
|
||||
request(:method => 'GET', :path => "os-networksv2/#{id}", :expects => 200)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
11
lib/fog/rackspace/requests/compute_v2/list_networks.rb
Normal file
11
lib/fog/rackspace/requests/compute_v2/list_networks.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def list_networks
|
||||
request(:method => 'GET', :path => 'os-networksv2', :expects => 200)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
49
tests/rackspace/requests/compute_v2/network_tests.rb
Normal file
49
tests/rackspace/requests/compute_v2/network_tests.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
Shindo.tests('Fog::Compute::RackspaceV2 | network_tests', ['rackspace']) do
|
||||
service = Fog::Compute.new(:provider => 'Rackspace', :version => 'V2')
|
||||
|
||||
network_format = {
|
||||
'id' => String,
|
||||
'label' => String,
|
||||
'cidr' => Fog::Nullable::String
|
||||
}
|
||||
|
||||
get_network_format = {
|
||||
'network' => network_format
|
||||
}
|
||||
|
||||
list_networks_format = {
|
||||
'networks' => [network_format]
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
network_id = nil
|
||||
|
||||
tests('#create_network').formats(get_network_format) do
|
||||
service.create_network("fog_#{Time.now.to_i.to_s}", '192.168.0.0/24').body.tap do |r|
|
||||
network_id = r['network']['id']
|
||||
end
|
||||
end
|
||||
|
||||
tests('#list_networks').formats(list_networks_format) do
|
||||
service.list_networks.body
|
||||
end
|
||||
|
||||
tests('#get_network').formats(get_network_format) do
|
||||
service.get_network(network_id).body
|
||||
end
|
||||
|
||||
tests('#delete_network').succeeds do
|
||||
service.delete_network(network_id)
|
||||
end
|
||||
end
|
||||
|
||||
test('failure') do
|
||||
tests('#get_network').raises(Fog::Compute::RackspaceV2::NotFound) do
|
||||
service.get_network(0)
|
||||
end
|
||||
|
||||
tests('#delete_network').raises(Fog::Compute::RackspaceV2::NotFound) do
|
||||
service.delete_network(0)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue