From aeae34e9489f309fd6067d1357786359069a811f Mon Sep 17 00:00:00 2001 From: Rodrigo Estebanez Date: Wed, 12 Jun 2013 19:50:20 +0200 Subject: [PATCH] get_network implemented --- .../vcloudng/parsers/compute/get_network.rb | 44 +++++++++++++++++++ .../vcloudng/requests/compute/get_network.rb | 42 ++++++++++++++++++ lib/fog/vcloudng/shared.rb | 3 +- 3 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 lib/fog/vcloudng/parsers/compute/get_network.rb create mode 100644 lib/fog/vcloudng/requests/compute/get_network.rb diff --git a/lib/fog/vcloudng/parsers/compute/get_network.rb b/lib/fog/vcloudng/parsers/compute/get_network.rb new file mode 100644 index 000000000..46807e3c3 --- /dev/null +++ b/lib/fog/vcloudng/parsers/compute/get_network.rb @@ -0,0 +1,44 @@ +module Fog + module Parsers + module Vcloudng + module Compute + + + class GetNetwork < VcloudngParser + + def reset + @response = { + "links" => [] + } + end + + def start_element(name,attributes=[]) + super + case name + when "Network" + @response = extract_attributes(attributes) + if @response.has_key?("name") + @response["subnet"] = @response["name"] + end + if @response.has_key?("href") + @response["id"] = @response["href"].split("/").last + end + when "Link" + link = extract_attributes(attributes) + @response["links"] << link + end + end + + def end_element(name) + case name + when "Gateway", "Netmask", "FenceMode" + @response[name.downcase] = value + end + end + + end + + end + end + end +end diff --git a/lib/fog/vcloudng/requests/compute/get_network.rb b/lib/fog/vcloudng/requests/compute/get_network.rb new file mode 100644 index 000000000..59a7c46d0 --- /dev/null +++ b/lib/fog/vcloudng/requests/compute/get_network.rb @@ -0,0 +1,42 @@ +module Fog + module Vcloudng + module Compute + class Real + + require 'fog/vcloudng/parsers/compute/get_network' + + + # Get details for a Network + # + # ==== Parameters + # * network_id<~String> - Id of the network to look up + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # + # ==== How to get the catalog_uuid? + # + # org_uuid = vcloud.get_organizations.data[:body]["OrgList"].first["href"].split('/').last + # org = vcloud.get_organization(org_uuid) + # + # network_id = org.data[:body]["Links"].detect {|l| l["type"] =~ /vcloud.orgNetwork/ }["href"].split('/').last + def get_network(network_id) + request( + :expects => 200, + :headers => { 'Accept' => 'application/*+xml;version=1.5' }, + :method => 'GET', + :parser => Fog::Parsers::Vcloudng::Compute::GetNetwork.new, + :path => "network/#{network_id}" + ) + end + + def network_end_point(network_id = nil) + end_point + ( network_id ? "network/#{network_id}" : "network" ) + end + + end + end + end +end + \ No newline at end of file diff --git a/lib/fog/vcloudng/shared.rb b/lib/fog/vcloudng/shared.rb index 5666382b1..36f51177f 100644 --- a/lib/fog/vcloudng/shared.rb +++ b/lib/fog/vcloudng/shared.rb @@ -260,7 +260,6 @@ module Fog #require 'fog/vcloudng/parsers/compute/get_keys_list' #require 'fog/vcloudng/parsers/compute/instantiate_vapp_template' #require 'fog/vcloudng/parsers/compute/internet_service' - #require 'fog/vcloudng/parsers/compute/network' #require 'fog/vcloudng/parsers/compute/node_service' #require 'fog/vcloudng/parsers/compute/public_ip' #require 'fog/vcloudng/parsers/compute/task' @@ -276,7 +275,7 @@ module Fog require 'fog/vcloudng/requests/compute/get_catalog' require 'fog/vcloudng/requests/compute/get_catalog_item' #require 'fog/vcloudng/requests/compute/get_internet_services' - #require 'fog/vcloudng/requests/compute/get_network' + require 'fog/vcloudng/requests/compute/get_network' #require 'fog/vcloudng/requests/compute/get_network_ips' #require 'fog/vcloudng/requests/compute/get_node_services' require 'fog/vcloudng/requests/compute/get_organization'