diff --git a/lib/fog/compute.rb b/lib/fog/compute.rb index a8e27e93b..43f9513e3 100644 --- a/lib/fog/compute.rb +++ b/lib/fog/compute.rb @@ -38,6 +38,9 @@ module Fog when :vcloud require 'fog/vcloud/compute' Fog::Vcloud::Compute.new(attributes) + when :vcloudng + require 'fog/vcloudng/compute' + Fog::Vcloudng::Compute.new(attributes) else if self.providers.include?(provider) require "fog/#{provider}/compute" diff --git a/lib/fog/vcloudng.rb b/lib/fog/vcloudng.rb index 9ee5b3093..c7ae7f0e3 100644 --- a/lib/fog/vcloudng.rb +++ b/lib/fog/vcloudng.rb @@ -1,10 +1,11 @@ require 'fog/core' -require 'fog/vcloudng/parser' -require 'fog/vcloudng/compute' - module Fog - module Vcloudng - VCLOUDNG_OPTIONS = [:vcloudng_username, :vcloudng_password, :vcloudng_host] + module Vcloud + + extend Fog::Provider + + service(:compute, 'vcloudng/compute', 'Compute') + end end \ No newline at end of file diff --git a/lib/fog/vcloudng/compute.rb b/lib/fog/vcloudng/compute.rb index 4e2b1df03..6d7cf763e 100644 --- a/lib/fog/vcloudng/compute.rb +++ b/lib/fog/vcloudng/compute.rb @@ -1,57 +1,132 @@ -require_relative './shared' +require 'fog/vcloudng' +require 'fog/compute' + +class String + def to_bool + return true if self == true || self =~ (/(true|t|yes|y|1)$/i) + return false if self == false || self.empty? || self =~ (/(false|f|no|n|0)$/i) + raise ArgumentError.new("invalid value for Boolean: \"#{self}\"") + end +end + + +class VcloudngParser < Fog::Parsers::Base + + def extract_attributes(attributes_xml) + attributes = {} + until attributes_xml.empty? + if attributes_xml.first.is_a?(Array) + until attributes_xml.first.empty? + attribute = attributes_xml.first.shift + attributes[attribute.localname] = attribute.value + end + else + attribute = attributes_xml.shift + attributes[attribute.localname] = attribute.value + end + end + attributes + end +end module Fog - module Vcloudng - module Compute - - module Bin - end - + module Compute + class Vcloudng < Fog::Service + module Defaults PATH = '/api' PORT = 443 SCHEME = 'https' end - - extend Fog::Vcloudng::Shared - - def self.new(options={}) - # Fog::Logger.deprecation("Fog::Vcloudng::Compute is deprecated, to be replaced with Compute 1.0 someday/maybe [light_black](#{caller.first})[/]") - - unless @required - shared_requires - @required = true - end - - check_shared_options(options) - - if Fog.mocking? - Fog::Vcloudng::Compute::Mock.new(options) - else - Fog::Vcloudng::Compute::Real.new(options) - end - end + + requires :vcloudng_username, :vcloudng_password, :vcloudng_host + + request_path 'fog/vcloudng/requests/compute' + request :get_organizations + request :get_organization + request :get_catalog + request :get_catalog_item + request :get_vdc + request :get_vapp_template + request :instantiate_vapp_template + + class Real attr_reader :end_point - - include Fog::Vcloudng::Shared::Real - include Fog::Vcloudng::Shared::Parser def initialize(options={}) @vcloudng_password = options[:vcloudng_password] @vcloudng_username = options[:vcloudng_username] @connection_options = options[:connection_options] || {} @host = options[:vcloudng_host] - @path = options[:path] || Fog::Vcloudng::Compute::Defaults::PATH + @path = options[:path] || Fog::Compute::Vcloudng::Defaults::PATH @persistent = options[:persistent] || false - @port = options[:port] || Fog::Vcloudng::Compute::Defaults::PORT - @scheme = options[:scheme] || Fog::Vcloudng::Compute::Defaults::SCHEME + @port = options[:port] || Fog::Compute::Vcloudng::Defaults::PORT + @scheme = options[:scheme] || Fog::Compute::Vcloudng::Defaults::SCHEME @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) @end_point = "#{@scheme}://#{@host}#{@path}/" end + def auth_token + response = @connection.request({ + :expects => 200, + :headers => { 'Authorization' => "Basic #{Base64.encode64("#{@vcloudng_username}:#{@vcloudng_password}").delete("\r\n")}", + 'Accept' => 'application/*+xml;version=1.5' + }, + :host => @host, + :method => 'POST', + :parser => Fog::Parsers::Compute::Vcloudng::GetOrganizations.new, + :path => "/api/sessions" # curl http://example.com/api/versions | grep LoginUrl + }) + response.headers['Set-Cookie'] + end + + + def reload + @cookie = nil # verify that this makes the connection to be restored, if so use Excon::Errors::Forbidden instead of Excon::Errors::Unauthorized + @connection.reset + end + + def request(params) + unless @cookie + @cookie = auth_token + end + begin + do_request(params) + # this is to know if Excon::Errors::Unauthorized really happens + #rescue Excon::Errors::Unauthorized + # @cookie = auth_token + # do_request(params) + end + end + + def do_request(params) + headers = {} + if @cookie + headers.merge!('Cookie' => @cookie) + end + if params[:path] + if params[:override_path] == true + path = params[:path] + else + path = "#{@path}/#{params[:path]}" + end + else + path = "#{@path}" + end + @connection.request({ + :body => params[:body], + :expects => params[:expects], + :headers => headers.merge!(params[:headers] || {}), + :host => @host, + :method => params[:method], + :parser => params[:parser], + :path => path + }) + end + def default_vdc_id if default_organization_id @default_vdc_id ||= begin @@ -121,32 +196,30 @@ module Fog end end + def default_organization_id + @default_organization_id ||= begin + org_list = get_organizations.body['OrgList'] + if org_list.length == 1 + org_list.first['href'].split('/').last + else + nil + end + end + end + def default_organization_body + return nil unless default_organization_id + @default_organization_body ||= begin + response = get_organization(default_organization_id) + return nil unless response.respond_to? 'data' + response.data[:body] + end + end end class Mock - include Fog::Vcloudng::Shared::Mock - include Fog::Vcloudng::Shared::Parser - - def initialize(option = {}) - super - @base_url = Fog::Vcloudng::Compute::Defaults::SCHEME + "://" + - options[:vcloudng_host] + - Fog::Vcloudng::Compute::Defaults::PATH - - @vcloudng_username = options[:vcloudng_username] - end - - def data - self.class.data[@vcloudng_username] - end - - def reset_data - self.class.data.delete(@vcloudng_username) - end - end end diff --git a/lib/fog/vcloudng/parser.rb b/lib/fog/vcloudng/parser.rb deleted file mode 100644 index 28f5e4df8..000000000 --- a/lib/fog/vcloudng/parser.rb +++ /dev/null @@ -1,20 +0,0 @@ -class VcloudngParser < Fog::Parsers::Base - - def extract_attributes(attributes_xml) - attributes = {} - until attributes_xml.empty? - if attributes_xml.first.is_a?(Array) - until attributes_xml.first.empty? - attribute = attributes_xml.first.shift - attributes[attribute.localname] = attribute.value - end - else - attribute = attributes_xml.shift - attributes[attribute.localname] = attribute.value - end - end - attributes - end -end - - diff --git a/lib/fog/vcloudng/parsers/compute/get_catalog.rb b/lib/fog/vcloudng/parsers/compute/get_catalog.rb index 0feb68a10..4b1fa80a6 100644 --- a/lib/fog/vcloudng/parsers/compute/get_catalog.rb +++ b/lib/fog/vcloudng/parsers/compute/get_catalog.rb @@ -16,8 +16,9 @@ module Fog module Parsers - module Vcloudng - module Compute + module Compute + module Vcloudng + class GetCatalog < VcloudngParser diff --git a/lib/fog/vcloudng/parsers/compute/get_catalog_item.rb b/lib/fog/vcloudng/parsers/compute/get_catalog_item.rb index 575125fd7..ddc288a7c 100644 --- a/lib/fog/vcloudng/parsers/compute/get_catalog_item.rb +++ b/lib/fog/vcloudng/parsers/compute/get_catalog_item.rb @@ -10,8 +10,8 @@ module Fog module Parsers - module Vcloudng - module Compute + module Compute + module Vcloudng class GetCatalogItem < VcloudngParser diff --git a/lib/fog/vcloudng/parsers/compute/get_network.rb b/lib/fog/vcloudng/parsers/compute/get_network.rb index c271c0593..8c581e088 100644 --- a/lib/fog/vcloudng/parsers/compute/get_network.rb +++ b/lib/fog/vcloudng/parsers/compute/get_network.rb @@ -26,8 +26,9 @@ module Fog module Parsers - module Vcloudng - module Compute + module Compute + module Vcloudng + class GetNetwork < VcloudngParser diff --git a/lib/fog/vcloudng/parsers/compute/get_organization.rb b/lib/fog/vcloudng/parsers/compute/get_organization.rb index d5d951848..9de42829e 100644 --- a/lib/fog/vcloudng/parsers/compute/get_organization.rb +++ b/lib/fog/vcloudng/parsers/compute/get_organization.rb @@ -78,8 +78,9 @@ module Fog module Parsers - module Vcloudng - module Compute + module Compute + module Vcloudng + class GetOrganization < VcloudngParser diff --git a/lib/fog/vcloudng/parsers/compute/get_organizations.rb b/lib/fog/vcloudng/parsers/compute/get_organizations.rb index 0b01de90e..a66626fdd 100644 --- a/lib/fog/vcloudng/parsers/compute/get_organizations.rb +++ b/lib/fog/vcloudng/parsers/compute/get_organizations.rb @@ -15,8 +15,9 @@ module Fog module Parsers - module Vcloudng - module Compute + module Compute + module Vcloudng + class GetOrganizations < VcloudngParser diff --git a/lib/fog/vcloudng/parsers/compute/get_vapp.rb b/lib/fog/vcloudng/parsers/compute/get_vapp.rb index 0b03093d5..914785e45 100644 --- a/lib/fog/vcloudng/parsers/compute/get_vapp.rb +++ b/lib/fog/vcloudng/parsers/compute/get_vapp.rb @@ -1,7 +1,8 @@ module Fog module Parsers - module Vcloudng - module Compute + module Compute + module Vcloudng + class GetVapp < VcloudngParser diff --git a/lib/fog/vcloudng/parsers/compute/get_vapp_template.rb b/lib/fog/vcloudng/parsers/compute/get_vapp_template.rb index 47ca0e3fc..55beab136 100644 --- a/lib/fog/vcloudng/parsers/compute/get_vapp_template.rb +++ b/lib/fog/vcloudng/parsers/compute/get_vapp_template.rb @@ -75,8 +75,9 @@ # #module Fog # module Parsers -# module Vcloudng -# module Compute +# module Compute +# module Vcloudng +# # # # class GetVappTemplate < VcloudngParser @@ -188,8 +189,9 @@ module Fog module Parsers - module Vcloudng - module Compute + module Compute + module Vcloudng + class GetVappTemplate < VcloudngParser diff --git a/lib/fog/vcloudng/parsers/compute/get_vdc.rb b/lib/fog/vcloudng/parsers/compute/get_vdc.rb index 87aa33c55..a4be9434b 100644 --- a/lib/fog/vcloudng/parsers/compute/get_vdc.rb +++ b/lib/fog/vcloudng/parsers/compute/get_vdc.rb @@ -1,7 +1,7 @@ module Fog module Parsers - module Vcloudng - module Compute + module Compute + module Vcloudng class GetVdc < VcloudngParser diff --git a/lib/fog/vcloudng/parsers/compute/instantiate_vapp_template.rb b/lib/fog/vcloudng/parsers/compute/instantiate_vapp_template.rb index 2e4a8e4d1..52a3f2e12 100644 --- a/lib/fog/vcloudng/parsers/compute/instantiate_vapp_template.rb +++ b/lib/fog/vcloudng/parsers/compute/instantiate_vapp_template.rb @@ -1,7 +1,8 @@ module Fog module Parsers - module Vcloudng - module Compute + module Compute + module Vcloudng + class InstantiateVappTemplate < VcloudngParser diff --git a/lib/fog/vcloudng/requests/compute/get_catalog.rb b/lib/fog/vcloudng/requests/compute/get_catalog.rb index a9368c086..8f87094aa 100644 --- a/lib/fog/vcloudng/requests/compute/get_catalog.rb +++ b/lib/fog/vcloudng/requests/compute/get_catalog.rb @@ -1,6 +1,6 @@ module Fog - module Vcloudng - module Compute + module Compute + class Vcloudng class Real require 'fog/vcloudng/parsers/compute/get_catalog' @@ -32,7 +32,7 @@ module Fog :expects => 200, :headers => { 'Accept' => 'application/*+xml;version=1.5' }, :method => 'GET', - :parser => Fog::Parsers::Vcloudng::Compute::GetCatalog.new, + :parser => Fog::Parsers::Compute::Vcloudng::GetCatalog.new, :path => "catalog/#{catalog_uuid}" ) end diff --git a/lib/fog/vcloudng/requests/compute/get_catalog_item.rb b/lib/fog/vcloudng/requests/compute/get_catalog_item.rb index ee10edf56..a6305e7d2 100644 --- a/lib/fog/vcloudng/requests/compute/get_catalog_item.rb +++ b/lib/fog/vcloudng/requests/compute/get_catalog_item.rb @@ -1,6 +1,6 @@ module Fog - module Vcloudng - module Compute + module Compute + class Vcloudng class Real require 'fog/vcloudng/parsers/compute/get_catalog_item' @@ -36,7 +36,7 @@ module Fog :expects => 200, :headers => { 'Accept' => 'application/*+xml;version=1.5' }, :method => 'GET', - :parser => Fog::Parsers::Vcloudng::Compute::GetCatalogItem.new, + :parser => Fog::Parsers::Compute::Vcloudng::GetCatalogItem.new, :path => "catalogItem/#{catalog_item_id}" ) end diff --git a/lib/fog/vcloudng/requests/compute/get_network.rb b/lib/fog/vcloudng/requests/compute/get_network.rb index 59a7c46d0..97d7c0807 100644 --- a/lib/fog/vcloudng/requests/compute/get_network.rb +++ b/lib/fog/vcloudng/requests/compute/get_network.rb @@ -1,7 +1,8 @@ module Fog - module Vcloudng - module Compute + module Compute + class Vcloudng class Real + require 'fog/vcloudng/parsers/compute/get_network' @@ -26,7 +27,7 @@ module Fog :expects => 200, :headers => { 'Accept' => 'application/*+xml;version=1.5' }, :method => 'GET', - :parser => Fog::Parsers::Vcloudng::Compute::GetNetwork.new, + :parser => Fog::Parsers::Compute::Vcloudng::GetNetwork.new, :path => "network/#{network_id}" ) end diff --git a/lib/fog/vcloudng/requests/compute/get_organization.rb b/lib/fog/vcloudng/requests/compute/get_organization.rb index e4d36632d..cd421fd53 100644 --- a/lib/fog/vcloudng/requests/compute/get_organization.rb +++ b/lib/fog/vcloudng/requests/compute/get_organization.rb @@ -1,7 +1,8 @@ module Fog - module Vcloudng - module Compute + module Compute + class Vcloudng class Real + require 'fog/vcloudng/parsers/compute/get_organization' @@ -26,7 +27,7 @@ module Fog :expects => 200, :headers => { 'Accept' => 'application/*+xml;version=1.5' }, :method => 'GET', - :parser => Fog::Parsers::Vcloudng::Compute::GetOrganization.new, + :parser => Fog::Parsers::Compute::Vcloudng::GetOrganization.new, :path => "org/#{organization_id}" }) end diff --git a/lib/fog/vcloudng/requests/compute/get_organizations.rb b/lib/fog/vcloudng/requests/compute/get_organizations.rb index 27467a6b1..181185d54 100644 --- a/lib/fog/vcloudng/requests/compute/get_organizations.rb +++ b/lib/fog/vcloudng/requests/compute/get_organizations.rb @@ -1,7 +1,8 @@ module Fog - module Vcloudng - module Compute + module Compute + class Vcloudng class Real + require 'fog/vcloudng/parsers/compute/get_organizations' @@ -18,7 +19,7 @@ module Fog :expects => 200, :headers => { 'Accept' => 'application/*+xml;version=1.5' }, :method => 'GET', - :parser => Fog::Parsers::Vcloudng::Compute::GetOrganizations.new, + :parser => Fog::Parsers::Compute::Vcloudng::GetOrganizations.new, :path => "org" }) end diff --git a/lib/fog/vcloudng/requests/compute/get_vapp.rb b/lib/fog/vcloudng/requests/compute/get_vapp.rb index fc697a4db..4713832cf 100644 --- a/lib/fog/vcloudng/requests/compute/get_vapp.rb +++ b/lib/fog/vcloudng/requests/compute/get_vapp.rb @@ -1,8 +1,9 @@ module Fog - module Vcloudng - module Compute + module Compute + class Vcloudng class Real + require 'fog/vcloudng/parsers/compute/get_vapp' @@ -35,7 +36,7 @@ module Fog :expects => 200, :headers => { 'Accept' => 'application/*+xml;version=1.5' }, :method => 'GET', - :parser => Fog::Parsers::Vcloudng::Compute::GetVapp.new, + :parser => Fog::Parsers::Compute::Vcloudng::GetVapp.new, :path => "vApp/#{vapp_id}" ) end diff --git a/lib/fog/vcloudng/requests/compute/get_vapp_template.rb b/lib/fog/vcloudng/requests/compute/get_vapp_template.rb index 0c9e10eed..d98d89155 100644 --- a/lib/fog/vcloudng/requests/compute/get_vapp_template.rb +++ b/lib/fog/vcloudng/requests/compute/get_vapp_template.rb @@ -1,8 +1,9 @@ module Fog - module Vcloudng - module Compute + module Compute + class Vcloudng class Real + require 'fog/vcloudng/parsers/compute/get_vapp_template' # Get details of a vapp template @@ -40,7 +41,7 @@ module Fog :expects => 200, :headers => { 'Accept' => 'application/*+xml;version=1.5' }, :method => 'GET', - :parser => Fog::Parsers::Vcloudng::Compute::GetVappTemplate.new, + :parser => Fog::Parsers::Compute::Vcloudng::GetVappTemplate.new, :path => "vAppTemplate/#{vapp_template_id}" ) end diff --git a/lib/fog/vcloudng/requests/compute/get_vdc.rb b/lib/fog/vcloudng/requests/compute/get_vdc.rb index eb4599f21..b0f5af86f 100644 --- a/lib/fog/vcloudng/requests/compute/get_vdc.rb +++ b/lib/fog/vcloudng/requests/compute/get_vdc.rb @@ -1,8 +1,9 @@ module Fog - module Vcloudng - module Compute + module Compute + class Vcloudng class Real + require 'fog/vcloudng/parsers/compute/get_vdc' # Get details of a vdc @@ -34,7 +35,7 @@ module Fog :expects => 200, :headers => { 'Accept' => 'application/*+xml;version=1.5' }, :method => 'GET', - :parser => Fog::Parsers::Vcloudng::Compute::GetVdc.new, + :parser => Fog::Parsers::Compute::Vcloudng::GetVdc.new, :path => "vdc/#{vdc_id}" ) end diff --git a/lib/fog/vcloudng/requests/compute/instantiate_vapp_template.rb b/lib/fog/vcloudng/requests/compute/instantiate_vapp_template.rb index 61cad327c..a42650426 100644 --- a/lib/fog/vcloudng/requests/compute/instantiate_vapp_template.rb +++ b/lib/fog/vcloudng/requests/compute/instantiate_vapp_template.rb @@ -1,6 +1,6 @@ module Fog - module Vcloudng - module Compute + module Compute + class Vcloudng class Real require 'fog/vcloudng/parsers/compute/instantiate_vapp_template' @@ -25,7 +25,6 @@ module Fog # * 'status'<~String> - 0(pending) --> 2(off) -->4(on) def instantiate_vapp_template(vapp_name, template_id, options = {}) params = populate_uris(options.merge(vapp_name: vapp_name, template_id: template_id)) - puts params validate_uris(params) data = generate_instantiate_vapp_template_request(params) @@ -36,7 +35,7 @@ module Fog :headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml', 'Accept' => 'application/*+xml;version=1.5' }, :method => 'POST', - :parser => Fog::Parsers::Vcloudng::Compute::InstantiateVappTemplate.new, + :parser => Fog::Parsers::Compute::Vcloudng::InstantiateVappTemplate.new, :path => "vdc/#{params[:vdc_id]}/action/instantiateVAppTemplate" ) end diff --git a/lib/fog/vcloudng/shared.rb b/lib/fog/vcloudng/shared.rb deleted file mode 100644 index 252254351..000000000 --- a/lib/fog/vcloudng/shared.rb +++ /dev/null @@ -1,316 +0,0 @@ -class String - def to_bool - return true if self == true || self =~ (/(true|t|yes|y|1)$/i) - return false if self == false || self.empty? || self =~ (/(false|f|no|n|0)$/i) - raise ArgumentError.new("invalid value for Boolean: \"#{self}\"") - end -end - -module Fog - module Vcloudng - module Shared - - # Commond methods shared by Real and Mock - module Common - - def default_organization_id - @default_organization_id ||= begin - org_list = get_organizations.body['OrgList'] - if org_list.length == 1 - org_list.first['href'].split('/').last - else - nil - end - end - end - - def default_organization_body - return nil unless default_organization_id - @default_organization_body ||= begin - response = get_organization(default_organization_id) - return nil unless response.respond_to? 'data' - response.data[:body] - end - end - - end - - module Parser - - def parse(data) - case data['type'] - when 'application/vnd.vmware.vcloud.vApp+xml' - servers.new(data.merge!(:service => self)) - else - data - end - end - - end - - module Real - include Common - -# private - - def auth_token - response = @connection.request({ - :expects => 200, - :headers => { 'Authorization' => "Basic #{Base64.encode64("#{@vcloudng_username}:#{@vcloudng_password}").delete("\r\n")}", - 'Accept' => 'application/*+xml;version=1.5' - }, - :host => @host, - :method => 'POST', - :parser => Fog::Parsers::Vcloudng::Compute::GetOrganizations.new, - :path => "/api/sessions" # curl http://example.com/api/versions | grep LoginUrl - }) - response.headers['Set-Cookie'] - end - - def reload - @connection.reset - end - - def request(params) - unless @cookie - @cookie = auth_token - end - begin - do_request(params) - rescue Excon::Errors::Unauthorized - @cookie = auth_token - do_request(params) - end - end - - def do_request(params) - headers = {} - if @cookie - headers.merge!('Cookie' => @cookie) - end - if params[:path] - if params[:override_path] == true - path = params[:path] - else - path = "#{@path}/#{params[:path]}" - end - else - path = "#{@path}" - end - @connection.request({ - :body => params[:body], - :expects => params[:expects], - :headers => headers.merge!(params[:headers] || {}), - :host => @host, - :method => params[:method], - :parser => params[:parser], - :path => path - }) - end - - end - - module Mock - include Common - - def self.mock_data - { - :organizations => - [ - { - :info => { - :name => "Boom Inc.", - :id => 1 - }, - :vdcs => [ - { :id => 21, - :name => "Boomstick", - :storage => { :used => 105, :allocated => 200 }, - :cpu => { :allocated => 10000 }, - :memory => { :allocated => 20480 }, - :networks => [ - { :id => 31, - :name => "1.2.3.0/24", - :subnet => "1.2.3.0/24", - :gateway => "1.2.3.1", - :netmask => "255.255.255.0", - :fencemode => "isolated" - }, - { :id => 32, - :name => "4.5.6.0/24", - :subnet => "4.5.6.0/24", - :gateway => "4.5.6.1", - :netmask => "255.255.255.0", - :fencemode => "isolated" - }, - ], - :vms => [ - { :id => 41, - :name => "Broom 1" - }, - { :id => 42, - :name => "Broom 2" - }, - { :id => 43, - :name => "Email!" - } - ], - :public_ips => [ - { :id => 51, - :name => "99.1.2.3" - }, - { :id => 52, - :name => "99.1.2.4" - }, - { :id => 53, - :name => "99.1.9.7" - } - ] - }, - { :id => 22, - :storage => { :used => 40, :allocated => 150 }, - :cpu => { :allocated => 1000 }, - :memory => { :allocated => 2048 }, - :name => "Rock-n-Roll", - :networks => [ - { :id => 33, - :name => "7.8.9.0/24", - :subnet => "7.8.9.0/24", - :gateway => "7.8.9.1", - :netmask => "255.255.255.0", - :fencemode => "isolated" - } - ], - :vms => [ - { :id => 44, - :name => "Master Blaster" - } - ], - :public_ips => [ - { :id => 54, - :name => "99.99.99.99" - } - ] - } - ] - } - ] - } - end - - def self.error_headers - {"X-Powered-By"=>"ASP.NET", - "Date"=> Time.now.to_s, - "Content-Type"=>"text/html", - "Content-Length"=>"0", - "Server"=>"Microsoft-IIS/7.0", - "Cache-Control"=>"private"} - end - - def self.unathorized_status - 401 - end - - def self.headers(body, content_type) - {"X-Powered-By"=>"ASP.NET", - "Date"=> Time.now.to_s, - "Content-Type"=> content_type, - "Content-Length"=> body.to_s.length, - "Server"=>"Microsoft-IIS/7.0", - "Set-Cookie"=>"vcloud-token=ecb37bfc-56f0-421d-97e5-bf2gdf789457; path=/", - "Cache-Control"=>"private"} - end - - def self.status - 200 - end - - def initialize(options={}) - self.class.instance_eval ' - def self.data - @data ||= Hash.new do |hash, key| - hash[key] = Fog::Vcloudng::Compute::Mock.mock_data - end - end' - self.class.instance_eval ' - def self.reset - @data = nil - end - - def self.reset_data(keys=data.keys) - for key in [*keys] - data.delete(key) - end - end' - end - end - - def check_shared_options(options) - cloud_option_keys = options.keys.select { |key| key.to_s =~ /^vcloudng_.*/ } - unless cloud_option_keys.length == 0 || cloud_option_keys.length == 3 - raise ArgumentError.new("vcloudng_username, vcloudng_password and vcloudng_host required to access vcloud") - end - end - - def shared_requires - #require 'fog/vcloudng/models/compute/address' - #require 'fog/vcloudng/models/compute/addresses' - #require 'fog/vcloudng/models/compute/network' - #require 'fog/vcloudng/models/compute/networks' - #require 'fog/vcloudng/models/compute/server' - #require 'fog/vcloudng/models/compute/servers' - #require 'fog/vcloudng/models/compute/image' - #require 'fog/vcloudng/models/compute/images' - #require 'fog/vcloudng/models/compute/task' - #require 'fog/vcloudng/models/compute/tasks' - #require 'fog/vcloudng/models/compute/vdc' - #require 'fog/vcloudng/models/compute/vdcs' - #require 'fog/vcloudng/models/compute/internetservice' - #require 'fog/vcloudng/models/compute/internetservices' - #require 'fog/vcloudng/models/compute/nodeservice' - #require 'fog/vcloudng/models/compute/nodeservices' - #require 'fog/vcloudng/parsers/compute/get_internet_services' - #require 'fog/vcloudng/parsers/compute/get_network_ips' - #require 'fog/vcloudng/parsers/compute/get_node_services' - #require 'fog/vcloudng/parsers/compute/get_public_ips' - #require 'fog/vcloudng/parsers/compute/get_tasks_list' - #require 'fog/vcloudng/parsers/compute/get_keys_list' - #require 'fog/vcloudng/parsers/compute/internet_service' - #require 'fog/vcloudng/parsers/compute/node_service' - #require 'fog/vcloudng/parsers/compute/public_ip' - #require 'fog/vcloudng/parsers/compute/task' - #require 'fog/vcloudng/requests/compute/add_internet_service' - #require 'fog/vcloudng/requests/compute/add_node_service' - #require 'fog/vcloudng/requests/compute/create_internet_service' - #require 'fog/vcloudng/requests/compute/delete_internet_service' - #require 'fog/vcloudng/requests/compute/delete_public_ip' - #require 'fog/vcloudng/requests/compute/delete_node_service' - #require 'fog/vcloudng/requests/compute/delete_vapp' - #require 'fog/vcloudng/requests/compute/deploy_vapp' - 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_ips' - #require 'fog/vcloudng/requests/compute/get_node_services' - require 'fog/vcloudng/requests/compute/get_organization' - require 'fog/vcloudng/requests/compute/get_organizations' - #require 'fog/vcloudng/requests/compute/get_public_ip' - #require 'fog/vcloudng/requests/compute/get_public_ips' - #require 'fog/vcloudng/requests/compute/get_task' - #require 'fog/vcloudng/requests/compute/get_tasks_list' - #require 'fog/vcloudng/requests/compute/get_keys_list' - require 'fog/vcloudng/requests/compute/get_vapp' - require 'fog/vcloudng/requests/compute/get_vapp_template' - require 'fog/vcloudng/requests/compute/get_vdc' - require 'fog/vcloudng/requests/compute/instantiate_vapp_template' - #require 'fog/vcloudng/requests/compute/configure_vapp' - #require 'fog/vcloudng/requests/compute/power_off' - #require 'fog/vcloudng/requests/compute/power_on' - #require 'fog/vcloudng/requests/compute/power_reset' - #require 'fog/vcloudng/requests/compute/power_shutdown' - end - - end - end -end