From b2601eb913b335bd91148ec9b29f1f523f01b864 Mon Sep 17 00:00:00 2001 From: Brad Gignac Date: Thu, 31 Jan 2013 21:49:29 -0500 Subject: [PATCH] [rackspace|networks] Add Cloud Networks requests. --- lib/fog/rackspace/compute_v2.rb | 5 ++ .../requests/compute_v2/create_network.rb | 23 +++++++++ .../requests/compute_v2/delete_network.rb | 11 +++++ .../requests/compute_v2/get_network.rb | 11 +++++ .../requests/compute_v2/list_networks.rb | 11 +++++ .../requests/compute_v2/network_tests.rb | 49 +++++++++++++++++++ 6 files changed, 110 insertions(+) create mode 100644 lib/fog/rackspace/requests/compute_v2/create_network.rb create mode 100644 lib/fog/rackspace/requests/compute_v2/delete_network.rb create mode 100644 lib/fog/rackspace/requests/compute_v2/get_network.rb create mode 100644 lib/fog/rackspace/requests/compute_v2/list_networks.rb create mode 100644 tests/rackspace/requests/compute_v2/network_tests.rb diff --git a/lib/fog/rackspace/compute_v2.rb b/lib/fog/rackspace/compute_v2.rb index 164768591..e14d94d36 100644 --- a/lib/fog/rackspace/compute_v2.rb +++ b/lib/fog/rackspace/compute_v2.rb @@ -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 diff --git a/lib/fog/rackspace/requests/compute_v2/create_network.rb b/lib/fog/rackspace/requests/compute_v2/create_network.rb new file mode 100644 index 000000000..aede54f4e --- /dev/null +++ b/lib/fog/rackspace/requests/compute_v2/create_network.rb @@ -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 diff --git a/lib/fog/rackspace/requests/compute_v2/delete_network.rb b/lib/fog/rackspace/requests/compute_v2/delete_network.rb new file mode 100644 index 000000000..39d84d412 --- /dev/null +++ b/lib/fog/rackspace/requests/compute_v2/delete_network.rb @@ -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 diff --git a/lib/fog/rackspace/requests/compute_v2/get_network.rb b/lib/fog/rackspace/requests/compute_v2/get_network.rb new file mode 100644 index 000000000..5bb825ab3 --- /dev/null +++ b/lib/fog/rackspace/requests/compute_v2/get_network.rb @@ -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 diff --git a/lib/fog/rackspace/requests/compute_v2/list_networks.rb b/lib/fog/rackspace/requests/compute_v2/list_networks.rb new file mode 100644 index 000000000..19061b5e2 --- /dev/null +++ b/lib/fog/rackspace/requests/compute_v2/list_networks.rb @@ -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 diff --git a/tests/rackspace/requests/compute_v2/network_tests.rb b/tests/rackspace/requests/compute_v2/network_tests.rb new file mode 100644 index 000000000..2d3a2d841 --- /dev/null +++ b/tests/rackspace/requests/compute_v2/network_tests.rb @@ -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