diff --git a/lib/fog/vcloud/compute.rb b/lib/fog/vcloud/compute.rb index ac9d748aa..d883ea79d 100644 --- a/lib/fog/vcloud/compute.rb +++ b/lib/fog/vcloud/compute.rb @@ -74,14 +74,16 @@ module Fog module Vcloud class Compute < Fog::Service - PATH = '/api/v1.0' + BASE_PATH = '/api' + DEFAULT_VERSION = '1.5' + SUPPORTED_VERSIONS = [ '1.5', '1.0' ] PORT = 443 SCHEME = 'https' attr_writer :default_organization_uri requires :vcloud_username, :vcloud_password, :vcloud_host - recognizes :vcloud_port, :vcloud_scheme, :vcloud_path, :vcloud_default_vdc + recognizes :vcloud_port, :vcloud_scheme, :vcloud_path, :vcloud_default_vdc, :vcloud_version, :vcloud_base_path recognizes :provider # remove post deprecation model_path 'fog/vcloud/models/compute' @@ -173,6 +175,8 @@ module Fog end end + attr_reader :version + def initialize(options = {}) require 'builder' require 'fog/core/parser' @@ -181,13 +185,15 @@ module Fog @connection_options = options[:connection_options] || {} @persistent = options[:persistent] - @username = options[:vcloud_username] - @password = options[:vcloud_password] - @host = options[:vcloud_host] - @vdc_href = options[:vcloud_default_vdc] - @path = options[:vcloud_path] || Fog::Vcloud::Compute::PATH - @port = options[:vcloud_port] || Fog::Vcloud::Compute::PORT - @scheme = options[:vcloud_scheme] || Fog::Vcloud::Compute::SCHEME + @username = options[:vcloud_username] + @password = options[:vcloud_password] + @host = options[:vcloud_host] + @vdc_href = options[:vcloud_default_vdc] + @base_path = options[:vcloud_base_path] || Fog::Vcloud::Compute::BASE_PATH + @version = options[:vcloud_version] || Fog::Vcloud::Compute::DEFAULT_VERSION + @path = options[:vcloud_path] || "#{@base_path}/v#{@version}" + @port = options[:vcloud_port] || Fog::Vcloud::Compute::PORT + @scheme = options[:vcloud_scheme] || Fog::Vcloud::Compute::SCHEME end def reload @@ -230,10 +236,17 @@ module Fog end def xmlns - { "xmlns" => "http://www.vmware.com/vcloud/v1", - "xmlns:ovf" => "http://schemas.dmtf.org/ovf/envelope/1", - "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", - "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema" } + if version == '1.0' + { "xmlns" => "http://www.vmware.com/vcloud/v1", + "xmlns:ovf" => "http://schemas.dmtf.org/ovf/envelope/1", + "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", + "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema" } + else + { 'xmlns' => "http://www.vmware.com/vcloud/v1.5", + "xmlns:ovf" => "http://schemas.dmtf.org/ovf/envelope/1", + "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", + "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema" } + end end # If the cookie isn't set, do a get_organizations call to set it @@ -251,7 +264,6 @@ module Fog end end - private def basic_request_params(uri,*args) { @@ -264,6 +276,11 @@ module Fog } end + def base_path_url + "#{@scheme}://#{@host}:#{@port}#{@base_path}" + end + + private def ensure_parsed(uri) if uri.is_a?(String) URI.parse(uri) @@ -300,6 +317,7 @@ module Fog # Set headers to an empty hash if none are set. headers = params[:headers] || {} + headers['Accept'] = 'application/*+xml;version=1.5' if version == '1.5' # Add our auth cookie to the headers if @cookie @@ -316,7 +334,6 @@ module Fog }) # Parse the response body into a hash - #puts response.body unless response.body.empty? if params[:parse] document = Fog::ToHashDocument.new diff --git a/lib/fog/vcloud/models/compute/networks.rb b/lib/fog/vcloud/models/compute/networks.rb index 1e6eee627..84cda7283 100644 --- a/lib/fog/vcloud/models/compute/networks.rb +++ b/lib/fog/vcloud/models/compute/networks.rb @@ -20,7 +20,7 @@ module Fog data = [connection.get_vdc(self.href).available_networks].flatten.compact.reject{|n| n == '' } elsif self.href =~ /\/org\// check_href!("Org") - data = connection.get_organization(self.href).links.select{|l| l[:type] == 'application/vnd.vmware.vcloud.network+xml' } + data = connection.get_organization(self.href).links.select{|l| l[:type] == network_type_id } elsif self.href =~ /\/vApp\// check_href!("Vapp") data = [(connection.get_vapp(self.href).network_configs||{})[:NetworkConfig]].flatten.compact.collect{|n| n[:Configuration][:ParentNetwork] unless n[:Configuration].nil? }.compact @@ -34,6 +34,14 @@ module Fog nil end + private + def network_type_id + if connection.version == '1.0' + 'application/vnd.vmware.vcloud.network+xml' + else + 'application/vnd.vmware.vcloud.orgNetwork+xml' + end + end end end end diff --git a/lib/fog/vcloud/models/compute/organizations.rb b/lib/fog/vcloud/models/compute/organizations.rb index 36702bb11..e0a2053be 100644 --- a/lib/fog/vcloud/models/compute/organizations.rb +++ b/lib/fog/vcloud/models/compute/organizations.rb @@ -11,7 +11,12 @@ module Fog undef_method :create def all - data = connection.login.body[:Org].select { |org| org[:type] == "application/vnd.vmware.vcloud.org+xml" } + raw_orgs = if connection.version == '1.0' + connection.login + else + connection.request(connection.basic_request_params("#{connection.base_path_url}/org/")) + end + data = raw_orgs.body[:Org].select { |org| org[:type] == "application/vnd.vmware.vcloud.org+xml" } data.each { |org| org.delete_if { |key, value| [:rel].include?(key) } } load(data) end diff --git a/lib/fog/vcloud/requests/compute/login.rb b/lib/fog/vcloud/requests/compute/login.rb index fe7ad725d..da7ebdc98 100644 --- a/lib/fog/vcloud/requests/compute/login.rb +++ b/lib/fog/vcloud/requests/compute/login.rb @@ -6,14 +6,18 @@ module Fog def login + headers = { 'Authorization' => authorization_header } + uri = if version == '1.0' + "#{base_url}/login" + else + "#{base_path_url}/sessions" + end unauthenticated_request({ :expects => 200, - :headers => { - 'Authorization' => authorization_header - }, + :headers => headers, :method => 'POST', :parse => true, - :uri => "#{base_url}/login" + :uri => uri }) end diff --git a/tests/vcloud/data/api_+_admin_+_network_+_2 b/tests/vcloud/data/api_+_admin_+_network_+_2 new file mode 100644 index 000000000..13789e898 --- /dev/null +++ b/tests/vcloud/data/api_+_admin_+_network_+_2 @@ -0,0 +1,110 @@ + + + Internet Connection + + + false + 172.0.0.1 + 255.255.255.0 + 172.0.0.2 + 172.0.0.190 + + + 172.0.0.142 + 172.0.0.156 + + + 172.0.0.160 + 172.0.0.184 + + + 172.0.0.195 + 172.0.0.235 + + + + 172.0.0.153 + 172.0.0.147 + 172.0.0.221 + 172.0.0.226 + 172.0.0.151 + 172.0.0.161 + 172.0.0.164 + 172.0.0.163 + 172.0.0.218 + 172.0.0.173 + 172.0.0.172 + 172.0.0.175 + 172.0.0.178 + 172.0.0.197 + 172.0.0.180 + 172.0.0.201 + 172.0.0.156 + 172.0.0.202 + 172.0.0.183 + 172.0.0.149 + 172.0.0.214 + 172.0.0.171 + 172.0.0.162 + 172.0.0.198 + 172.0.0.224 + 172.0.0.195 + 172.0.0.196 + 172.0.0.150 + 172.0.0.169 + 172.0.0.170 + 172.0.0.176 + 172.0.0.200 + 172.0.0.179 + 172.0.0.205 + 172.0.0.213 + 172.0.0.210 + 172.0.0.215 + 172.0.0.219 + 172.0.0.208 + 172.0.0.216 + 172.0.0.217 + 172.0.0.204 + 172.0.0.232 + 172.0.0.154 + 172.0.0.235 + 172.0.0.146 + 172.0.0.209 + 172.0.0.211 + 172.0.0.199 + 172.0.0.155 + 172.0.0.142 + 172.0.0.160 + 172.0.0.212 + 172.0.0.177 + 172.0.0.167 + 172.0.0.166 + 172.0.0.168 + 172.0.0.165 + 172.0.0.181 + 172.0.0.184 + 172.0.0.143 + 172.0.0.230 + 172.0.0.206 + 172.0.0.233 + 172.0.0.222 + 172.0.0.225 + 172.0.0.220 + 172.0.0.227 + 172.0.0.148 + 172.0.0.228 + 172.0.0.229 + 172.0.0.231 + 172.0.0.152 + 172.0.0.145 + 172.0.0.174 + 172.0.0.182 + 172.0.0.203 + 172.0.0.207 + 172.0.0.144 + + + isolated + + NETWORK:dvportgroup-230 on com.vmware.vcloud.entity.vimserver:35935555 + diff --git a/tests/vcloud/data/api_+_network_+_1 b/tests/vcloud/data/api_+_network_+_1 new file mode 100644 index 000000000..1be40bfd4 --- /dev/null +++ b/tests/vcloud/data/api_+_network_+_1 @@ -0,0 +1,44 @@ + + + + Some fancy Network + + + false + 192.168.0.1 + 255.255.255.0 + 172.0.0.2 + 172.0.0.190 + + + 192.168.0.101 + 192.168.0.150 + + + + 192.168.0.1 + + + + natRouted + + + false + 3600 + 7200 + + 192.168.0.151 + 192.168.0.254 + + + + true + + + false + portForwarding + allowTraffic + + + + diff --git a/tests/vcloud/data/api_+_org_+_ b/tests/vcloud/data/api_+_org_+_ new file mode 100644 index 000000000..ac74800d3 --- /dev/null +++ b/tests/vcloud/data/api_+_org_+_ @@ -0,0 +1,5 @@ + + + + + diff --git a/tests/vcloud/data/api_+_org_+_1 b/tests/vcloud/data/api_+_org_+_1 new file mode 100644 index 000000000..58fc44e98 --- /dev/null +++ b/tests/vcloud/data/api_+_org_+_1 @@ -0,0 +1,17 @@ + + + + + + + + + + + + + Some fancy + +Description + My Full Name + diff --git a/tests/vcloud/data/api_+_sessions b/tests/vcloud/data/api_+_sessions new file mode 100644 index 000000000..c8d8c548d --- /dev/null +++ b/tests/vcloud/data/api_+_sessions @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/tests/vcloud/data/api_+_vApp_+_vapp-1 b/tests/vcloud/data/api_+_vApp_+_vapp-1 new file mode 100644 index 000000000..12cf0640d --- /dev/null +++ b/tests/vcloud/data/api_+_vApp_+_vapp-1 @@ -0,0 +1,369 @@ + + + + + + + + + + + Some Description of a vApp + + Lease settings section + + 0 + 0 + + + VApp startup section + + + + + + The list of logical networks + + + + + + The configuration parameters for logical networks + + + Some Network Description + + + false + 192.168.2.1 + 255.255.255.0 + 192.168.2.1 + + + 192.168.2.101 + 192.168.2.150 + + + + 192.168.2.101 + 192.168.2.1 + 192.168.2.102 + + + + natRouted + + + false + 7200 + 7200 + + + + true + + + true + ipTranslation + allowTraffic + + + automatic + 192.168.1.102 + vm1 + 0 + + + + + automatic + 192.168.1.103 + vm2 + 0 + + + + + + true + + + + + + + + vm-595 + VIRTUAL_MACHINE + + + + + + + + + + + + + Virtual hardware requirements + + Virtual Hardware Family + 0 + vm2 + vmx-07 + + + 00:50:56:01:02:03 + 0 + true + Network1 + PCNet32 ethernet adapter + Network adapter 0 + 1 + PCNet32 + 10 + + + 0 + SCSI Controller + SCSI Controller 0 + 2 + lsilogicsas + 6 + + + 0 + Hard disk + Hard disk 1 + + 2000 + 2 + 17 + + + 0 + IDE Controller + IDE Controller 0 + 3 + 5 + + + 0 + false + CD/DVD Drive + CD/DVD Drive 1 + + 3002 + 3 + 15 + + + hertz * 10^6 + Number of Virtual CPUs + 1 virtual CPU(s) + 4 + 0 + 3 + 1 + 0 + + + + byte * 2^20 + Memory Size + 512 MB of memory + 5 + 0 + 4 + 512 + 0 + + + + + + + + + + + + + + + Specifies the operating system installed + Red Hat Enterprise Linux 5 (64-bit) + + + + Specifies the available VM network connections + 0 + + 0 + 192.168.2.102 + 192.168.1.103 + true + 00:50:56:01:00:03 + POOL + + + + + Specifies Guest OS Customization Settings + true + false + 2 + false + false + true + true + password + false + + vm2 + + + vmware_RHEL5-U5-64-small_v02 + + + + + + vm-594 + VIRTUAL_MACHINE + + + + + + + + + + + + + Virtual hardware requirements + + Virtual Hardware Family + 0 + vm1 + vmx-07 + + + 00:50:56:01:02:04 + 0 + true + Network1 + PCNet32 ethernet adapter + Network adapter 0 + 1 + PCNet32 + 10 + + + 0 + SCSI Controller + SCSI Controller 0 + 2 + lsilogicsas + 6 + + + 0 + Hard disk + Hard disk 1 + + 2000 + 2 + 17 + + + 0 + IDE Controller + IDE Controller 0 + 3 + 5 + + + 0 + false + CD/DVD Drive + CD/DVD Drive 1 + + 3002 + 3 + 15 + + + hertz * 10^6 + Number of Virtual CPUs + 1 virtual CPU(s) + 4 + 0 + 3 + 1 + 0 + + + + byte * 2^20 + Memory Size + 512 MB of memory + 5 + 0 + 4 + 512 + 0 + + + + + + + + + + + + + + + Specifies the operating system installed + Red Hat Enterprise Linux 5 (64-bit) + + + + Specifies the available VM network connections + 0 + + 0 + 192.168.2.101 + 192.168.1.102 + true + 00:50:56:01:02:04 + POOL + + + + + Specifies Guest OS Customization Settings + true + false + 1 + false + false + true + true + password + false + + vm1 + + + vmware_RHEL5-U5-64-small_v01 + + + diff --git a/tests/vcloud/data/api_+_vApp_+_vm-2 b/tests/vcloud/data/api_+_vApp_+_vm-2 new file mode 100644 index 000000000..9bbd5934d --- /dev/null +++ b/tests/vcloud/data/api_+_vApp_+_vm-2 @@ -0,0 +1,155 @@ + + + + + + vm-595 + VIRTUAL_MACHINE + + + + + + + + + + + Some VM Description + + Virtual hardware requirements + + Virtual Hardware Family + 0 + vm2 + vmx-07 + + + 00:50:56:01:02:03 + 0 + true + Network1 + PCNet32 ethernet adapter + Network adapter 0 + 1 + PCNet32 + 10 + + + 0 + SCSI Controller + SCSI Controller 0 + 2 + lsilogicsas + 6 + + + 0 + Hard disk + Hard disk 1 + + 2000 + 2 + 17 + + + 1 + Hard disk + Hard disk 2 + + 3000 + 2 + 17 + + + 0 + IDE Controller + IDE Controller 0 + 3 + 5 + + + 0 + false + CD/DVD Drive + CD/DVD Drive 1 + + 3002 + 3 + 15 + + + hertz * 10^6 + Number of Virtual CPUs + 1 virtual CPU(s) + 4 + 0 + 3 + 1 + 0 + + + + byte * 2^20 + Memory Size + 512 MB of memory + 5 + 0 + 4 + 512 + 0 + + + + + + + + + + + + + + + Specifies the operating system installed + Red Hat Enterprise Linux 5 (64-bit) + + + + Specifies the available VM network connections + 0 + + 0 + 192.168.2.102 + 192.168.1.103 + true + 00:50:56:01:02:03 + POOL + + + 1 + 192.168.3.102 + true + 00:50:56:01:02:04 + POOL + + + + + Specifies Guest OS Customization Settings + true + false + 2 + false + false + true + true + password + false + + vm2 + + + vmware_RHEL5-U5-64-small_v02 + diff --git a/tests/vcloud/data/api_+_vdc_+_1 b/tests/vcloud/data/api_+_vdc_+_1 new file mode 100644 index 000000000..cb5bf55ab --- /dev/null +++ b/tests/vcloud/data/api_+_vdc_+_1 @@ -0,0 +1,61 @@ + + + + + + resgroup-1 + RESOURCE_POOL + + + + + + + + + + + + + + + Some Description + AllocationVApp + + MB + 10240 + 102400 + 101650 + 0 + + + + MHz + 20000 + 40000 + 2000 + 0 + + + MB + 1024 + 10240 + 8385 + 0 + + + + + + + + + + + + + 10 + 10 + 10 + true + diff --git a/tests/vcloud/models/compute/network_tests.rb b/tests/vcloud/models/compute/network_tests.rb index 114d6d84d..5a3a9869e 100644 --- a/tests/vcloud/models/compute/network_tests.rb +++ b/tests/vcloud/models/compute/network_tests.rb @@ -2,57 +2,65 @@ require 'fog/vcloud/models/compute/networks' Shindo.tests("Vcloud::Compute | network", ['vcloud']) do - pending if Fog.mocking? + Fog::Vcloud::Compute::SUPPORTED_VERSIONS.each do |version| + tests("api version #{version}") do - connection = Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password') - tests("an org network") do - instance = connection.get_network('https://vcloud.example.com/api/v1.0/network/1') - instance.reload - - tests("#href").returns("https://vcloud.example.com/api/v1.0/network/1") { instance.href } - tests("#name").returns("Network1") { instance.name } - tests("#description").returns("Some fancy Network") { instance.description } - - tests("configuration") do - tests("parent network").returns("ParentNetwork1") { instance.configuration[:ParentNetwork][:name]} - tests("dns").returns("172.0.0.2") { instance.configuration[:IpScope][:Dns1]} - - tests("#fence_mode").returns("natRouted") { instance.configuration[:FenceMode] } - - tests("features") do - tests("dhcp_service") do - tests("#is_enabled").returns("false") { instance.configuration[:Features][:DhcpService][:IsEnabled] } - tests("ip_range") do - tests("#start_address").returns("192.168.0.151") { instance.configuration[:Features][:DhcpService][:IpRange][:StartAddress] } + connection = Fog::Vcloud::Compute.new( + :vcloud_host => 'vcloud.example.com', + :vcloud_username => 'username', + :vcloud_password => 'password', + :vcloud_version => version + ) + tests("an org network") do + instance = connection.get_network("https://vcloud.example.com/api#{version == '1.0' ? '/v1.0' : ''}/network/1") + instance.reload + + tests("#href").returns("https://vcloud.example.com/api#{version == '1.0' ? '/v1.0' : ''}/network/1") { instance.href } + tests("#name").returns("Network1") { instance.name } + tests("#description").returns("Some fancy Network") { instance.description } + + tests("configuration") do + tests("parent network").returns("ParentNetwork1") { instance.configuration[:ParentNetwork][:name]} + tests("dns").returns("172.0.0.2") { instance.configuration[:IpScope][:Dns1]} + + tests("#fence_mode").returns("natRouted") { instance.configuration[:FenceMode] } + + tests("features") do + tests("dhcp_service") do + tests("#is_enabled").returns("false") { instance.configuration[:Features][:DhcpService][:IsEnabled] } + tests("ip_range") do + tests("#start_address").returns("192.168.0.151") { instance.configuration[:Features][:DhcpService][:IpRange][:StartAddress] } + end + end + tests("firewall_server") do + tests("is_enabled").returns("true"){ instance.configuration[:Features][:FirewallService][:IsEnabled] } + end + tests("nat_service") do + tests("is_enabled").returns("false"){ instance.configuration[:Features][:NatService][:IsEnabled] } + end end end - tests("firewall_server") do - tests("is_enabled").returns("true"){ instance.configuration[:Features][:FirewallService][:IsEnabled] } - end - tests("nat_service") do - tests("is_enabled").returns("false"){ instance.configuration[:Features][:NatService][:IsEnabled] } + + tests("#parent_network") do + tests("returned network name").returns("ParentNetwork1"){ p = instance.parent_network; p.name } end end - end - tests("#parent_network") do - tests("returned network name").returns("ParentNetwork1"){ p = instance.parent_network; p.name } + tests("an external network") do + instance = connection.get_network("https://vcloud.example.com/api#{version == '1.0' ? '/v1.0' : ''}/admin/network/2") + instance.reload + tests("#href").returns("https://vcloud.example.com/api#{version == '1.0' ? '/v1.0' : ''}/admin/network/2") { instance.href } + tests("#name").returns("ParentNetwork1") { instance.name } + tests("#description").returns("Internet Connection") { instance.description } + tests("#provider_info").returns("NETWORK:dvportgroup-230 on com.vmware.vcloud.entity.vimserver:35935555") { instance.provider_info } + + tests("configuration") do + tests("dns").returns("172.0.0.2") { instance.configuration[:IpScope][:Dns1]} + tests("allocated addresses").returns("172.0.0.144") { instance.configuration[:IpScope][:AllocatedIpAddresses][:IpAddress].first } + end + + tests("#parent_network").returns(nil){ instance.parent_network } + end end end - - tests("an external network") do - instance = connection.get_network('https://vcloud.example.com/api/v1.0/admin/network/2') - instance.reload - tests("#href").returns("https://vcloud.example.com/api/v1.0/admin/network/2") { instance.href } - tests("#name").returns("ParentNetwork1") { instance.name } - tests("#description").returns("Internet Connection") { instance.description } - tests("#provider_info").returns("NETWORK:dvportgroup-230 on com.vmware.vcloud.entity.vimserver:35935555") { instance.provider_info } - - tests("configuration") do - tests("dns").returns("172.0.0.2") { instance.configuration[:IpScope][:Dns1]} - tests("allocated addresses").returns("172.0.0.144") { instance.configuration[:IpScope][:AllocatedIpAddresses][:IpAddress].first } - end - - tests("#parent_network").returns(nil){ instance.parent_network } - end end diff --git a/tests/vcloud/models/compute/networks_tests.rb b/tests/vcloud/models/compute/networks_tests.rb index 84a946bb3..223f64914 100644 --- a/tests/vcloud/models/compute/networks_tests.rb +++ b/tests/vcloud/models/compute/networks_tests.rb @@ -2,41 +2,59 @@ require 'fog/vcloud/models/compute/networks' Shindo.tests("Vcloud::Compute | networks", ['vcloud']) do - pending if Fog.mocking? + Fog::Vcloud::Compute::SUPPORTED_VERSIONS.each do |version| + tests("api version #{version}") do - tests("from an org perspective") do - instance = Fog::Vcloud::Compute::Networks.new( - :connection => Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password'), - :href => "https://vcloud.example.com/api/v1.0/org/1" - ) - - tests("collection") do - returns(2) { instance.size } - returns("https://vcloud.example.com/api/v1.0/network/1") { instance.first.href } - end - end - - tests("from a vdc perspective") do - instance = Fog::Vcloud::Compute::Networks.new( - :connection => Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password'), - :href => "https://vcloud.example.com/api/v1.0/vdc/1" - ) - - tests("collection") do - returns(2) { instance.size } - returns("https://vcloud.example.com/api/v1.0/network/1") { instance.first.href } - end - end - - tests("from a vapp perspective") do - instance = Fog::Vcloud::Compute::Networks.new( - :connection => Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password'), - :href => "https://vcloud.example.com/api/v1.0/vApp/vapp-1" - ) - - tests("collection") do - returns(1) { instance.size } - returns("https://vcloud.example.com/api/v1.0/network/1") { instance.first.href } + tests("from an org perspective") do + instance = Fog::Vcloud::Compute::Networks.new( + :connection => Fog::Vcloud::Compute.new( + :vcloud_host => 'vcloud.example.com', + :vcloud_username => 'username', + :vcloud_password => 'password', + :vcloud_version => version + ), + :href => "https://vcloud.example.com/api#{version == '1.0' ? '/v1.0' : ''}/org/1" + ) + + tests("collection") do + returns(2) { instance.size } + returns("https://vcloud.example.com/api#{version == '1.0' ? '/v1.0' : ''}/network/1") { instance.first.href } + end + end + + tests("from a vdc perspective") do + instance = Fog::Vcloud::Compute::Networks.new( + :connection => Fog::Vcloud::Compute.new( + :vcloud_host => 'vcloud.example.com', + :vcloud_username => 'username', + :vcloud_password => 'password', + :vcloud_version => version + ), + :href => "https://vcloud.example.com/api#{version == '1.0' ? '/v1.0' : ''}/vdc/1" + ) + + tests("collection") do + returns(2) { instance.size } + returns("https://vcloud.example.com/api#{version == '1.0' ? '/v1.0' : ''}/network/1") { instance.first.href } + end + end + + tests("from a vapp perspective") do + instance = Fog::Vcloud::Compute::Networks.new( + :connection => Fog::Vcloud::Compute.new( + :vcloud_host => 'vcloud.example.com', + :vcloud_username => 'username', + :vcloud_password => 'password', + :vcloud_version => version + ), + :href => "https://vcloud.example.com/api#{version == '1.0' ? '/v1.0' : ''}/vApp/vapp-1" + ) + + tests("collection") do + returns(1) { instance.size } + returns("https://vcloud.example.com/api#{version == '1.0' ? '/v1.0' : ''}/network/1") { instance.first.href } + end + end end end end diff --git a/tests/vcloud/models/compute/organization_tests.rb b/tests/vcloud/models/compute/organization_tests.rb index 1e905e3d3..76ce697f3 100644 --- a/tests/vcloud/models/compute/organization_tests.rb +++ b/tests/vcloud/models/compute/organization_tests.rb @@ -1,17 +1,19 @@ Shindo.tests("Vcloud::Compute | organization", ['vcloud']) do - pending if Fog.mocking? - - instance = Fog::Vcloud::Compute.new( - :vcloud_host => 'vcloud.example.com', - :vcloud_username => 'username', - :vcloud_password => 'password' - ).get_organization('https://vcloud.example.com/api/v1.0/org/1') - instance.reload - - tests("#href").returns('https://vcloud.example.com/api/v1.0/org/1'){ instance.href } - tests("#name").returns('Org1'){ instance.name } - tests("#full_name").returns('My Full Name'){ instance.full_name } - tests("#description").returns("Some fancy\n\nDescription"){ instance.description } - + Fog::Vcloud::Compute::SUPPORTED_VERSIONS.each do |version| + tests("api version #{version}") do + instance = Fog::Vcloud::Compute.new( + :vcloud_host => 'vcloud.example.com', + :vcloud_username => 'username', + :vcloud_password => 'password', + :vcloud_version => version + ).get_organization("https://vcloud.example.com/api#{(version == '1.0') ? '/v1.0' : ''}/org/1") + instance.reload + + tests("#href").returns("https://vcloud.example.com/api#{(version == '1.0') ? '/v1.0' : ''}/org/1"){ instance.href } + tests("#name").returns('Org1'){ instance.name } + tests("#full_name").returns('My Full Name'){ instance.full_name } + tests("#description").returns("Some fancy\n\nDescription"){ instance.description } + end + end end diff --git a/tests/vcloud/models/compute/organizations_tests.rb b/tests/vcloud/models/compute/organizations_tests.rb index 5c3552df0..f347f0aff 100644 --- a/tests/vcloud/models/compute/organizations_tests.rb +++ b/tests/vcloud/models/compute/organizations_tests.rb @@ -2,13 +2,14 @@ require 'fog/vcloud/models/compute/organizations' Shindo.tests("Vcloud::Compute | organizations", ['vcloud']) do - pending if Fog.mocking? - - instance = Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password').organizations - - tests("collection") do - returns(2) { instance.size } - returns("https://vcloud.example.com/api/v1.0/org/1") { instance.first.href } + Fog::Vcloud::Compute::SUPPORTED_VERSIONS.each do |version| + tests("api version #{version}") do + instance = Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password', :vcloud_version => version).organizations + + tests("collection") do + returns(2) { instance.size } + returns("https://vcloud.example.com/api#{(version == '1.0') ? '/v1.0' : ''}/org/1") { instance.first.href } + end + end end - end diff --git a/tests/vcloud/models/compute/server_tests.rb b/tests/vcloud/models/compute/server_tests.rb index 05a6b5cc3..6654e6fd2 100644 --- a/tests/vcloud/models/compute/server_tests.rb +++ b/tests/vcloud/models/compute/server_tests.rb @@ -2,49 +2,51 @@ require 'fog/vcloud/models/compute/servers' Shindo.tests("Vcloud::Compute | server", ['vcloud']) do - pending if Fog.mocking? - - instance = Fog::Vcloud::Compute.new( - :vcloud_host => 'vcloud.example.com', - :vcloud_username => 'username', - :vcloud_password => 'password' - ).get_server('https://vcloud.example.com/api/v1.0/vApp/vm-2') - - instance.reload - - tests("#href").returns("https://vcloud.example.com/api/v1.0/vApp/vm-2") { instance.href } - tests("#name").returns("vm2") { instance.name } - tests("#vapp").returns("vApp1") { instance.vapp.name } - tests("#description").returns("Some VM Description") { instance.description } - tests("#status").returns('8') { instance.status } - tests("#deployed").returns(true) { instance.deployed } - - tests("#os_desc").returns("Red Hat Enterprise Linux 5 (64-bit)") { instance.os_desc } - tests("#os_type").returns("rhel5_64Guest") { instance.os_type } - tests("#computer_name").returns("vm2") { instance.computer_name } - - tests("cpu count").returns(1) { instance.cpus[:count] } - - tests("amount of memory").returns(512){ instance.memory[:amount] } - - tests("#disks") do - tests("#size").returns(2){ instance.disks.size } - tests("#number").returns(0){ instance.disks.first[:number] } - tests("#size").returns(1600){ instance.disks.first[:size] } - tests("#ElementName").returns("Hard disk 1"){ instance.disks.first[:disk_data][:'rasd:ElementName'] } - tests("#InstanceID").returns("2000"){ instance.disks.first[:disk_data][:'rasd:InstanceID'] } + Fog::Vcloud::Compute::SUPPORTED_VERSIONS.each do |version| + tests("api version #{version}") do + instance = Fog::Vcloud::Compute.new( + :vcloud_host => 'vcloud.example.com', + :vcloud_username => 'username', + :vcloud_password => 'password', + :vcloud_version => version + ).get_server("https://vcloud.example.com/api#{(version == '1.0') ? '/v1.0' : ''}/vApp/vm-2") + + instance.reload + + tests("#href").returns("https://vcloud.example.com/api#{(version == '1.0') ? '/v1.0' : ''}/vApp/vm-2") { instance.href } + tests("#name").returns("vm2") { instance.name } + tests("#vapp").returns("vApp1") { instance.vapp.name } + tests("#description").returns("Some VM Description") { instance.description } + tests("#status").returns('8') { instance.status } + tests("#deployed").returns(true) { instance.deployed } + + tests("#os_desc").returns("Red Hat Enterprise Linux 5 (64-bit)") { instance.os_desc } + tests("#os_type").returns("rhel5_64Guest") { instance.os_type } + tests("#computer_name").returns("vm2") { instance.computer_name } + + tests("cpu count").returns(1) { instance.cpus[:count] } + + tests("amount of memory").returns(512){ instance.memory[:amount] } + + tests("#disks") do + tests("#size").returns(2){ instance.disks.size } + tests("#number").returns(0){ instance.disks.first[:number] } + tests("#size").returns(1600){ instance.disks.first[:size] } + tests("#ElementName").returns("Hard disk 1"){ instance.disks.first[:disk_data][:'rasd:ElementName'] } + tests("#InstanceID").returns("2000"){ instance.disks.first[:disk_data][:'rasd:InstanceID'] } + end + + tests("#vapp_scoped_local_id").returns("vmware_RHEL5-U5-64-small_v02") { instance.vapp_scoped_local_id } + + tests("#friendly_status").returns('off') { instance.friendly_status } + tests("#on?").returns(false) { instance.on? } + tests("#off?").returns(true) { instance.off? } + + tests("#network_connections") do + tests("#size").returns(2) { instance.network_connections.size } + end + end end - - tests("#vapp_scoped_local_id").returns("vmware_RHEL5-U5-64-small_v02") { instance.vapp_scoped_local_id } - - tests("#friendly_status").returns('off') { instance.friendly_status } - tests("#on?").returns(false) { instance.on? } - tests("#off?").returns(true) { instance.off? } - - tests("#network_connections") do - tests("#size").returns(2) { instance.network_connections.size } - end - #old tests tests("#server.new('#{Vcloud::Compute::TestSupport::template}')").returns(true) do pending if Fog.mocking? diff --git a/tests/vcloud/models/compute/servers_tests.rb b/tests/vcloud/models/compute/servers_tests.rb index 6b69495ce..4b00797f6 100644 --- a/tests/vcloud/models/compute/servers_tests.rb +++ b/tests/vcloud/models/compute/servers_tests.rb @@ -2,15 +2,21 @@ require 'fog/vcloud/models/compute/servers' Shindo.tests("Vcloud::Compute | servers", ['vcloud']) do - pending if Fog.mocking? - - instance = Fog::Vcloud::Compute::Servers.new( - :connection => Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password'), - :href => "https://vcloud.example.com/api/v1.0/vApp/vapp-1" - ) - - tests("collection") do - returns(2) { instance.size } - returns("https://vcloud.example.com/api/v1.0/vApp/vm-2") { instance.first.href } + Fog::Vcloud::Compute::SUPPORTED_VERSIONS.each do |version| + tests("api version #{version}") do + instance = Fog::Vcloud::Compute::Servers.new( + :connection => Fog::Vcloud::Compute.new( + :vcloud_host => 'vcloud.example.com', + :vcloud_username => 'username', + :vcloud_password => 'password', + :vcloud_version => version), + :href => "https://vcloud.example.com/api#{(version == '1.0') ? '/v1.0' : ''}/vApp/vapp-1" + ) + + tests("collection") do + returns(2) { instance.size } + returns("https://vcloud.example.com/api#{(version == '1.0') ? '/v1.0' : ''}/vApp/vm-2") { instance.first.href } + end + end end end diff --git a/tests/vcloud/models/compute/vapp_tests.rb b/tests/vcloud/models/compute/vapp_tests.rb index d21a24341..e331502f7 100644 --- a/tests/vcloud/models/compute/vapp_tests.rb +++ b/tests/vcloud/models/compute/vapp_tests.rb @@ -3,27 +3,29 @@ require 'fog/vcloud/models/compute/vapp' Shindo.tests("Vcloud::Compute | vapp", ['vcloud']) do - pending if Fog.mocking? - - instance = Fog::Vcloud::Compute.new( - :vcloud_host => 'vcloud.example.com', - :vcloud_username => 'username', - :vcloud_password => 'password' - ).get_vapp('https://vcloud.example.com/api/v1.0/vApp/vapp-1') - instance.reload - - tests("#href").returns("https://vcloud.example.com/api/v1.0/vApp/vapp-1") { instance.href } - tests("#name").returns("vApp1") { instance.name } - tests("#vdc").returns("vDC1"){ instance.vdc.name } - tests("#description").returns("Some Description of a vApp") { instance.description } - tests("#status").returns('8') { instance.status } - tests("#deployed").returns(true) { instance.deployed } - - tests("#children").returns(2) { instance.children.size } - tests("#servers").returns(2) { instance.servers.size } - - tests("#friendly_status").returns('off') { instance.friendly_status } - tests("#on?").returns(false) { instance.on? } - tests("#off?").returns(true) { instance.off? } - + Fog::Vcloud::Compute::SUPPORTED_VERSIONS.each do |version| + tests("api version #{version}") do + instance = Fog::Vcloud::Compute.new( + :vcloud_host => 'vcloud.example.com', + :vcloud_username => 'username', + :vcloud_password => 'password', + :vcloud_version => version + ).get_vapp("https://vcloud.example.com/api#{(version == '1.0') ? '/v1.0' : ''}/vApp/vapp-1") + instance.reload + + tests("#href").returns("https://vcloud.example.com/api#{(version == '1.0') ? '/v1.0' : ''}/vApp/vapp-1") { instance.href } + tests("#name").returns("vApp1") { instance.name } + tests("#vdc").returns("vDC1"){ instance.vdc.name } + tests("#description").returns("Some Description of a vApp") { instance.description } + tests("#status").returns('8') { instance.status } + tests("#deployed").returns(true) { instance.deployed } + + tests("#children").returns(2) { instance.children.size } + tests("#servers").returns(2) { instance.servers.size } + + tests("#friendly_status").returns('off') { instance.friendly_status } + tests("#on?").returns(false) { instance.on? } + tests("#off?").returns(true) { instance.off? } + end + end end diff --git a/tests/vcloud/models/compute/vapps_tests.rb b/tests/vcloud/models/compute/vapps_tests.rb index da0c6211f..7b1d61b3b 100644 --- a/tests/vcloud/models/compute/vapps_tests.rb +++ b/tests/vcloud/models/compute/vapps_tests.rb @@ -2,16 +2,17 @@ require 'fog/vcloud/models/compute/vapps' Shindo.tests("Vcloud::Compute | vapps", ['vcloud']) do - pending if Fog.mocking? - - instance = Fog::Vcloud::Compute::Vapps.new( - :connection => Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password'), - :href => "https://vcloud.example.com/api/v1.0/vdc/1" - ) - - tests("collection") do - returns(2) { instance.size } - returns("https://vcloud.example.com/api/v1.0/vApp/vapp-1") { instance.first.href } + Fog::Vcloud::Compute::SUPPORTED_VERSIONS.each do |version| + tests("api version #{version}") do + instance = Fog::Vcloud::Compute::Vapps.new( + :connection => Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password'), + :href => "https://vcloud.example.com/api#{(version == '1.0') ? '/v1.0' : ''}/vdc/1" + ) + + tests("collection") do + returns(2) { instance.size } + returns("https://vcloud.example.com/api#{(version == '1.0') ? '/v1.0' : ''}/vApp/vapp-1") { instance.first.href } + end + end end - end diff --git a/tests/vcloud/models/compute/vdc_tests.rb b/tests/vcloud/models/compute/vdc_tests.rb index a175b18eb..369c0a9b6 100644 --- a/tests/vcloud/models/compute/vdc_tests.rb +++ b/tests/vcloud/models/compute/vdc_tests.rb @@ -3,43 +3,45 @@ require 'fog/vcloud/models/compute/vdc' Shindo.tests("Vcloud::Compute | vdc", ['vcloud']) do - pending if Fog.mocking? - - instance = Fog::Vcloud::Compute.new( - :vcloud_host => 'vcloud.example.com', - :vcloud_username => 'username', - :vcloud_password => 'password' - ).get_vdc('https://vcloud.example.com/api/v1.0/vdc/1') - - instance.reload - - tests("#href").returns("https://vcloud.example.com/api/v1.0/vdc/1") { instance.href } - tests("#name").returns("vDC1") { instance.name } - tests('#organization').returns("Org1") { instance.organization.name } - tests("#description").returns("Some Description") { instance.description } - tests("#network_quota").returns(10) { instance.network_quota } - tests("#nic_quota").returns(10) { instance.nic_quota } - tests("#vm_quota").returns(10) { instance.vm_quota } - tests("#is_enabled").returns(true) { instance.is_enabled } - - tests("#available_networks") do - tests("#size").returns(2) { instance.available_networks.size } - end - - tests("#storage_capacity") do - tests("units").returns("MB") { instance.storage_capacity[:Units] } - tests("allocated").returns("10240") { instance.storage_capacity[:Allocated] } - end - - tests("#compute_capacity") do - tests("cpu") do - tests("allocated").returns("20000") { instance.compute_capacity[:Cpu][:Allocated] } - tests("units").returns("MHz") { instance.compute_capacity[:Cpu][:Units] } + Fog::Vcloud::Compute::SUPPORTED_VERSIONS.each do |version| + tests("api version #{version}") do + instance = Fog::Vcloud::Compute.new( + :vcloud_host => 'vcloud.example.com', + :vcloud_username => 'username', + :vcloud_password => 'password', + :vcloud_version => version + ).get_vdc("https://vcloud.example.com/api#{(version == '1.0') ? '/v1.0' : ''}/vdc/1") + + instance.reload + + tests("#href").returns("https://vcloud.example.com/api#{(version == '1.0') ? '/v1.0' : ''}/vdc/1") { instance.href } + tests("#name").returns("vDC1") { instance.name } + tests('#organization').returns("Org1") { instance.organization.name } + tests("#description").returns("Some Description") { instance.description } + tests("#network_quota").returns(10) { instance.network_quota } + tests("#nic_quota").returns(10) { instance.nic_quota } + tests("#vm_quota").returns(10) { instance.vm_quota } + tests("#is_enabled").returns(true) { instance.is_enabled } + + tests("#available_networks") do + tests("#size").returns(2) { instance.available_networks.size } + end + + tests("#storage_capacity") do + tests("units").returns("MB") { instance.storage_capacity[:Units] } + tests("allocated").returns("10240") { instance.storage_capacity[:Allocated] } + end + + tests("#compute_capacity") do + tests("cpu") do + tests("allocated").returns("20000") { instance.compute_capacity[:Cpu][:Allocated] } + tests("units").returns("MHz") { instance.compute_capacity[:Cpu][:Units] } + end + tests("memory") do + tests("allocated").returns("1024") { instance.compute_capacity[:Memory][:Allocated] } + tests("units").returns("MB") { instance.compute_capacity[:Memory][:Units] } + end + end end - tests("memory") do - tests("allocated").returns("1024") { instance.compute_capacity[:Memory][:Allocated] } - tests("units").returns("MB") { instance.compute_capacity[:Memory][:Units] } - end - end end diff --git a/tests/vcloud/models/compute/vdcs_tests.rb b/tests/vcloud/models/compute/vdcs_tests.rb index 29933891a..ef53ce2c1 100644 --- a/tests/vcloud/models/compute/vdcs_tests.rb +++ b/tests/vcloud/models/compute/vdcs_tests.rb @@ -2,16 +2,22 @@ require 'fog/vcloud/models/compute/vdcs' Shindo.tests("Vcloud::Compute | vdcs", ['vcloud']) do - pending if Fog.mocking? + Fog::Vcloud::Compute::SUPPORTED_VERSIONS.each do |version| + tests("api version #{version}") do - instance = Fog::Vcloud::Compute::Vdcs.new( - :connection => Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password'), - :href => "https://vcloud.example.com/api/v1.0/org/1" - ) - - tests("collection") do - returns(1) { instance.size } - returns("https://vcloud.example.com/api/v1.0/vdc/1") { instance.first.href } + instance = Fog::Vcloud::Compute::Vdcs.new( + :connection => Fog::Vcloud::Compute.new( + :vcloud_host => 'vcloud.example.com', + :vcloud_username => 'username', + :vcloud_password => 'password', + :vcloud_version => version), + :href => "https://vcloud.example.com/api#{(version == '1.0') ? '/v1.0' : ''}/org/1" + ) + + tests("collection") do + returns(1) { instance.size } + returns("https://vcloud.example.com/api#{(version == '1.0') ? '/v1.0' : ''}/vdc/1") { instance.first.href } + end + end end - end