From 3e240474ac400d5a0c16518a1149f663eb797dee Mon Sep 17 00:00:00 2001 From: Peter Meier Date: Mon, 30 Jan 2012 15:24:14 +0100 Subject: [PATCH] [vcloud|compute] improve models + additional tests vCloud has also the concept of links in the responses. So we should make use of them to navigate through the tree of resources in the vCloud. Furthermore, we can make various calls a bit easier by directly returning the specific resource object than the plain xml response. Adjust tests to work with the new changes, and also test the added parts. --- lib/fog/vcloud/compute.rb | 68 +++++++++++++++---- lib/fog/vcloud/models/compute/catalog.rb | 2 +- lib/fog/vcloud/models/compute/catalog_item.rb | 2 +- lib/fog/vcloud/models/compute/catalogs.rb | 6 +- lib/fog/vcloud/models/compute/ip.rb | 4 +- lib/fog/vcloud/models/compute/network.rb | 12 +--- lib/fog/vcloud/models/compute/networks.rb | 13 ++-- lib/fog/vcloud/models/compute/organization.rb | 7 +- .../vcloud/models/compute/organizations.rb | 4 +- lib/fog/vcloud/models/compute/server.rb | 9 +-- lib/fog/vcloud/models/compute/servers.rb | 6 +- lib/fog/vcloud/models/compute/task.rb | 2 +- lib/fog/vcloud/models/compute/tasks.rb | 4 +- lib/fog/vcloud/models/compute/vapp.rb | 10 +-- lib/fog/vcloud/models/compute/vapps.rb | 8 +-- lib/fog/vcloud/models/compute/vdc.rb | 10 +-- lib/fog/vcloud/models/compute/vdcs.rb | 7 +- tests/vcloud/data/api_+_v1.0_+_vApp_+_vapp-1 | 2 +- tests/vcloud/data/api_+_v1.0_+_vApp_+_vm-1 | 2 +- tests/vcloud/data/api_+_v1.0_+_vApp_+_vm-2 | 2 +- tests/vcloud/models/compute/network_tests.rb | 13 +--- .../models/compute/organization_tests.rb | 6 +- tests/vcloud/models/compute/server_tests.rb | 11 +-- tests/vcloud/models/compute/vapp_tests.rb | 10 +-- tests/vcloud/models/compute/vdc_tests.rb | 11 +-- 25 files changed, 125 insertions(+), 106 deletions(-) diff --git a/lib/fog/vcloud/compute.rb b/lib/fog/vcloud/compute.rb index ce8c58a92..ac9d748aa 100644 --- a/lib/fog/vcloud/compute.rb +++ b/lib/fog/vcloud/compute.rb @@ -52,6 +52,20 @@ module Fog end end + def link_up + load_unless_loaded! + self.links.find{|l| l[:rel] == 'up' } + end + + def self.has_up(item) + class_eval <<-EOS, __FILE__,__LINE__ + def #{item} + load_unless_loaded! + connection.get_#{item}(link_up[:href]) + end + EOS + end + end end end @@ -99,22 +113,15 @@ module Fog request :configure_vm_name_description request :configure_vm_disks request :delete_vapp - request :get_catalog request :get_catalog_item request :get_customization_options - request :get_network request :get_network_ip request :get_network_ips request :get_network_extensions - request :get_organization - request :get_server - request :get_task request :get_task_list - request :get_vapp request :get_vapp_template request :get_vm_disks request :get_vm_memory - request :get_vdc request :instantiate_vapp_template request :login request :power_off @@ -138,13 +145,16 @@ module Fog def basic_request(*args) self.class_eval <<-EOS, __FILE__,__LINE__ def #{args[0]}(uri) - request({ - :expects => #{args[1] || 200}, - :method => '#{args[2] || 'GET'}', - :headers => #{args[3] ? args[3].inspect : '{}'}, - :body => '#{args[4] ? args[4] : ''}', - :parse => true, - :uri => uri }) + request( + { + :expects => #{args[1] || 200}, + :method => '#{args[2] || 'GET'}', + :headers => #{args[3] ? args[3].inspect : '{}'}, + :body => '#{args[4] ? args[4] : ''}', + :parse => true, + :uri => uri + } + ) end EOS end @@ -161,7 +171,6 @@ module Fog end EOS end - end def initialize(options = {}) @@ -244,6 +253,17 @@ module Fog private + def basic_request_params(uri,*args) + { + :expects => args[0] || 200, + :method => args[1] || 'GET', + :headers => args[2] ? args[2].inspect : {}, + :body => args[3] ? args[3] : '', + :parse => true, + :uri => uri + } + end + def ensure_parsed(uri) if uri.is_a?(String) URI.parse(uri) @@ -311,7 +331,25 @@ module Fog end end + def self.item_requests(*types) + types.each{|t| item_request(t) } + end + def self.item_request(type) + Fog::Vcloud::Compute::Real.class_eval <<-EOS, __FILE__,__LINE__ + def get_#{type}(uri) + Fog::Vcloud::Compute::#{type.to_s.capitalize}.new( + self.request(basic_request_params(uri)).body.merge( + :connection => self, + :collection => Fog::Vcloud::Compute::#{type.to_s.capitalize}s.new( + :connection => self + ) + ) + ) + end + EOS + end + item_requests :organization, :vdc, :network, :vapp, :server, :catalog, :task end end end diff --git a/lib/fog/vcloud/models/compute/catalog.rb b/lib/fog/vcloud/models/compute/catalog.rb index 43e68a717..6a4b67969 100644 --- a/lib/fog/vcloud/models/compute/catalog.rb +++ b/lib/fog/vcloud/models/compute/catalog.rb @@ -4,7 +4,7 @@ module Fog class Catalog < Fog::Vcloud::Model identity :href, :aliases => :Href - + attribute :links, :aliases => :Link, :type => :array ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd attribute :type diff --git a/lib/fog/vcloud/models/compute/catalog_item.rb b/lib/fog/vcloud/models/compute/catalog_item.rb index 35b819b14..d52c03b1b 100644 --- a/lib/fog/vcloud/models/compute/catalog_item.rb +++ b/lib/fog/vcloud/models/compute/catalog_item.rb @@ -4,7 +4,7 @@ module Fog class CatalogItem < Fog::Vcloud::Model identity :href, :aliases => :Href - + attribute :links, :aliases => :Link, :type => :array ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd attribute :type diff --git a/lib/fog/vcloud/models/compute/catalogs.rb b/lib/fog/vcloud/models/compute/catalogs.rb index 3df357be1..89a8dcd14 100644 --- a/lib/fog/vcloud/models/compute/catalogs.rb +++ b/lib/fog/vcloud/models/compute/catalogs.rb @@ -11,14 +11,12 @@ module Fog def all org_uri = self.organization_uri || connection.default_organization_uri - data = connection.get_organization(org_uri).body[:Link].select { |link| link[:type] == "application/vnd.vmware.vcloud.catalog+xml" } + data = connection.get_organization(org_uri).links.select { |link| link[:type] == "application/vnd.vmware.vcloud.catalog+xml" } load(data) end def get(uri) - if data = connection.get_catalog(uri) - new(data.body) - end + connection.get_catalog(uri) rescue Fog::Errors::NotFound nil end diff --git a/lib/fog/vcloud/models/compute/ip.rb b/lib/fog/vcloud/models/compute/ip.rb index a8403a115..19169b79d 100644 --- a/lib/fog/vcloud/models/compute/ip.rb +++ b/lib/fog/vcloud/models/compute/ip.rb @@ -3,9 +3,9 @@ module Fog class Compute class Ip < Fog::Vcloud::Model - ignore_attributes :xmlns_i, :xmlns - identity :href, :aliases => :Href + attribute :links, :aliases => :Link, :type => :array + ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd attribute :name, :aliases => :Name attribute :status, :aliases => :Status diff --git a/lib/fog/vcloud/models/compute/network.rb b/lib/fog/vcloud/models/compute/network.rb index d2e56bdc4..d91139552 100644 --- a/lib/fog/vcloud/models/compute/network.rb +++ b/lib/fog/vcloud/models/compute/network.rb @@ -4,8 +4,8 @@ module Fog class Network < Fog::Vcloud::Model identity :href, :aliases => :Href - - ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd, :xmlns_i, :Id + attribute :links, :aliases => :Link, :type => :array + ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd attribute :name, :aliases => :Name @@ -13,15 +13,9 @@ module Fog attribute :configuration, :aliases => :Configuration attribute :provider_info, :aliases => :ProviderInfo - attribute :links, :aliases => :Link, :type => :array - def parent_network return nil if configuration[:ParentNetwork].nil? - @parent_network ||= Fog::Vcloud::Compute::Network.new( - :connection => connection, - :collection => Fog::Vcloud::Compute::Networks.new(:connection => connection), - :href => configuration[:ParentNetwork][:href] - ) + @parent_network ||= connection.get_network(configuration[:ParentNetwork][:href]) end end end diff --git a/lib/fog/vcloud/models/compute/networks.rb b/lib/fog/vcloud/models/compute/networks.rb index 003e79e70..1e6eee627 100644 --- a/lib/fog/vcloud/models/compute/networks.rb +++ b/lib/fog/vcloud/models/compute/networks.rb @@ -17,23 +17,20 @@ module Fog data = nil if self.href =~ /\/vdc\// check_href!("Vdc") - data = [connection.get_vdc(self.href).body[:AvailableNetworks][:Network]].flatten.compact + data = [connection.get_vdc(self.href).available_networks].flatten.compact.reject{|n| n == '' } elsif self.href =~ /\/org\// check_href!("Org") - links = (l=connection.get_organization(self.href).body[:Link]).is_a?(Array) ? l : [l].compact - data = links.select{|l| l[:type] == 'application/vnd.vmware.vcloud.network+xml' } + data = connection.get_organization(self.href).links.select{|l| l[:type] == 'application/vnd.vmware.vcloud.network+xml' } elsif self.href =~ /\/vApp\// check_href!("Vapp") - data = [(connection.get_vapp(self.href).body[:NetworkConfigSection]||{})[:NetworkConfig]].flatten.compact.collect{|n| n[:Configuration][:ParentNetwork] unless n[:Configuration].nil? }.compact + data = [(connection.get_vapp(self.href).network_configs||{})[:NetworkConfig]].flatten.compact.collect{|n| n[:Configuration][:ParentNetwork] unless n[:Configuration].nil? }.compact end load([*data]) unless data.nil? end def get(uri) - if data = connection.get_network(uri) - new(data.body) - end - rescue Fog::Errors::NotFound + connection.get_network(uri) + rescue Fog::Errors::NotFound nil end diff --git a/lib/fog/vcloud/models/compute/organization.rb b/lib/fog/vcloud/models/compute/organization.rb index ac76ec407..c8513a1ea 100644 --- a/lib/fog/vcloud/models/compute/organization.rb +++ b/lib/fog/vcloud/models/compute/organization.rb @@ -3,15 +3,14 @@ module Fog class Compute class Organization < Fog::Vcloud::Model - identity :href - - ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd + identity :href, :aliases => :Href + attribute :links, :aliases => :Link, :type => :array + ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd attribute :name attribute :description, :aliases => :Description attribute :type attribute :full_name, :aliases => :FullName - attribute :other_links, :aliases => :Link def networks @networks ||= Fog::Vcloud::Compute::Networks. diff --git a/lib/fog/vcloud/models/compute/organizations.rb b/lib/fog/vcloud/models/compute/organizations.rb index 8bf6f8748..36702bb11 100644 --- a/lib/fog/vcloud/models/compute/organizations.rb +++ b/lib/fog/vcloud/models/compute/organizations.rb @@ -17,9 +17,7 @@ module Fog end def get(uri) - if data = connection.get_organization(uri) - new(data.body) - end + connection.get_organization(uri) rescue Fog::Errors::NotFound nil end diff --git a/lib/fog/vcloud/models/compute/server.rb b/lib/fog/vcloud/models/compute/server.rb index a4d6e1770..7e7c497aa 100644 --- a/lib/fog/vcloud/models/compute/server.rb +++ b/lib/fog/vcloud/models/compute/server.rb @@ -7,7 +7,7 @@ module Fog include Fog::Vcloud::Compute::Helpers::Status identity :href, :aliases => :Href - + attribute :links, :aliases => :Link, :type => :array ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd attribute :type @@ -24,9 +24,10 @@ module Fog attribute :guest_customization, :aliases => :GuestCustomizationSection attribute :operating_system, :aliases => :'ovf:OperatingSystemSection' - attribute :links, :aliases => :Link, :type => :array attribute :tasks, :aliases => :Tasks, :type => :array + has_up :vapp + def computer_name load_unless_loaded! self.guest_customization[:ComputerName] @@ -44,7 +45,7 @@ module Fog def ip_addresses load_unless_loaded! - self.network_connections.collect{|n| n[:IpAddress] } + [self.network_connections].flatten.collect{|n| n[:IpAddress] } end def ready? @@ -262,7 +263,7 @@ module Fog end def reload_status - self.status = connection.get_vapp(href).body[:status] + self.status = connection.get_vapp(href).status end end end diff --git a/lib/fog/vcloud/models/compute/servers.rb b/lib/fog/vcloud/models/compute/servers.rb index 8c27c84ed..ca4179a90 100644 --- a/lib/fog/vcloud/models/compute/servers.rb +++ b/lib/fog/vcloud/models/compute/servers.rb @@ -19,11 +19,7 @@ module Fog end def get(uri) - if data = connection.get_vapp(uri) - # If no tasks returned, set a mock entry to flush on reload - data.body[:Tasks] = {} unless data.body[:Tasks] - new(data.body) - end + connection.get_vapp(uri) rescue Fog::Errors::NotFound nil end diff --git a/lib/fog/vcloud/models/compute/task.rb b/lib/fog/vcloud/models/compute/task.rb index 13566ae7a..2f8c1f61d 100644 --- a/lib/fog/vcloud/models/compute/task.rb +++ b/lib/fog/vcloud/models/compute/task.rb @@ -4,7 +4,7 @@ module Fog class Task < Fog::Vcloud::Model identity :href, :aliases => :Href - + attribute :links, :aliases => :Link, :type => :array ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd attribute :status diff --git a/lib/fog/vcloud/models/compute/tasks.rb b/lib/fog/vcloud/models/compute/tasks.rb index 48798317a..c0532728b 100644 --- a/lib/fog/vcloud/models/compute/tasks.rb +++ b/lib/fog/vcloud/models/compute/tasks.rb @@ -19,9 +19,7 @@ module Fog end def get(uri) - if data = connection.get_task(uri) - new(data.body) - end + connection.get_task(uri) rescue Fog::Errors::NotFound nil end diff --git a/lib/fog/vcloud/models/compute/vapp.rb b/lib/fog/vcloud/models/compute/vapp.rb index 465759753..72a135917 100644 --- a/lib/fog/vcloud/models/compute/vapp.rb +++ b/lib/fog/vcloud/models/compute/vapp.rb @@ -6,9 +6,9 @@ module Fog include Fog::Vcloud::Compute::Helpers::Status - identity :href - - ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd + identity :href, :aliases => :Href + attribute :links, :aliases => :Link, :type => :array + ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd attribute :name attribute :type @@ -19,7 +19,9 @@ module Fog attribute :children, :aliases => :Children, :squash => :Vm attribute :lease_settings, :aliases => :LeaseSettingsSection - attribute :other_links, :aliases => :Link + attribute :network_configs, :aliases => :NetworkConfigSection + + has_up :vdc def servers @servers ||= Fog::Vcloud::Compute::Servers. diff --git a/lib/fog/vcloud/models/compute/vapps.rb b/lib/fog/vcloud/models/compute/vapps.rb index 66cf9c4fa..a0452b1fa 100644 --- a/lib/fog/vcloud/models/compute/vapps.rb +++ b/lib/fog/vcloud/models/compute/vapps.rb @@ -13,15 +13,11 @@ module Fog attribute :href def all - resource_entities = (re=connection.get_vdc(self.href).body[:ResourceEntities][:ResourceEntity]).is_a?(Array) ? re : [re].compact - data = resource_entities.select { |re| re[:type] == "application/vnd.vmware.vcloud.vApp+xml" } - load(data) + load([connection.get_vdc(self.href).resource_entities].flatten.select { |re| re[:type] == "application/vnd.vmware.vcloud.vApp+xml" }) end def get(uri) - if data = connection.get_vapp(uri) - new(data.body) - end + connection.get_vapp(uri) rescue Fog::Errors::NotFound nil end diff --git a/lib/fog/vcloud/models/compute/vdc.rb b/lib/fog/vcloud/models/compute/vdc.rb index 78744ca34..d05810659 100644 --- a/lib/fog/vcloud/models/compute/vdc.rb +++ b/lib/fog/vcloud/models/compute/vdc.rb @@ -3,9 +3,9 @@ module Fog class Compute class Vdc < Fog::Vcloud::Model - identity :href - - ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd + identity :href, :aliases => :Href + attribute :links, :aliases => :Link, :type => :array + ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd attribute :name attribute :type @@ -18,10 +18,10 @@ module Fog attribute :storage_capacity, :aliases => :StorageCapacity attribute :available_networks, :aliases => :AvailableNetworks, :squash => :Network - attribute :other_links, :aliases => :Link - attribute :resource_entities, :aliases => :ResourceEntities, :squash => :ResourceEntity + has_up :organization + def networks @networks ||= Fog::Vcloud::Compute::Networks. new( :connection => connection, diff --git a/lib/fog/vcloud/models/compute/vdcs.rb b/lib/fog/vcloud/models/compute/vdcs.rb index b120cd04f..7ad93a157 100644 --- a/lib/fog/vcloud/models/compute/vdcs.rb +++ b/lib/fog/vcloud/models/compute/vdcs.rb @@ -13,16 +13,13 @@ module Fog attribute :href def all - links = (l=connection.get_organization(org_uri).body[:Link]).is_a?(Array) ? l : [l].compact - data = links.select { |link| link[:type] == "application/vnd.vmware.vcloud.vdc+xml" } + data = connection.get_organization(org_uri).links.select { |link| link[:type] == "application/vnd.vmware.vcloud.vdc+xml" } data.each { |link| link.delete_if { |key, value| [:rel].include?(key) } } load(data) end def get(uri) - if data = connection.get_vdc(uri) - new(data.body) - end + connection.get_vdc(uri) rescue Fog::Errors::NotFound nil end diff --git a/tests/vcloud/data/api_+_v1.0_+_vApp_+_vapp-1 b/tests/vcloud/data/api_+_v1.0_+_vApp_+_vapp-1 index 353d7215c..8c4c5414e 100644 --- a/tests/vcloud/data/api_+_v1.0_+_vApp_+_vapp-1 +++ b/tests/vcloud/data/api_+_v1.0_+_vApp_+_vapp-1 @@ -6,7 +6,7 @@ - + Some Description of a vApp diff --git a/tests/vcloud/data/api_+_v1.0_+_vApp_+_vm-1 b/tests/vcloud/data/api_+_v1.0_+_vApp_+_vm-1 index 69b9c3a5a..275cbd08c 100644 --- a/tests/vcloud/data/api_+_v1.0_+_vApp_+_vm-1 +++ b/tests/vcloud/data/api_+_v1.0_+_vApp_+_vm-1 @@ -10,7 +10,7 @@ - + diff --git a/tests/vcloud/data/api_+_v1.0_+_vApp_+_vm-2 b/tests/vcloud/data/api_+_v1.0_+_vApp_+_vm-2 index 892ceca6d..8b2d3ed74 100644 --- a/tests/vcloud/data/api_+_v1.0_+_vApp_+_vm-2 +++ b/tests/vcloud/data/api_+_v1.0_+_vApp_+_vm-2 @@ -10,7 +10,7 @@ - + diff --git a/tests/vcloud/models/compute/network_tests.rb b/tests/vcloud/models/compute/network_tests.rb index ea32075ad..114d6d84d 100644 --- a/tests/vcloud/models/compute/network_tests.rb +++ b/tests/vcloud/models/compute/network_tests.rb @@ -6,10 +6,7 @@ Shindo.tests("Vcloud::Compute | network", ['vcloud']) do connection = Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password') tests("an org network") do - instance = Fog::Vcloud::Compute::Networks.new( - :connection => connection, - :href => "https://vcloud.example.com/api/v1.0/vApp/vapp-1" - ).first + 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 } @@ -39,16 +36,12 @@ Shindo.tests("Vcloud::Compute | network", ['vcloud']) do end tests("#parent_network") do - tests("returned network name").returns("ParentNetwork1"){ p = instance.parent_network; p.reload; p.name } + tests("returned network name").returns("ParentNetwork1"){ p = instance.parent_network; p.name } end end tests("an external network") do - instance = Fog::Vcloud::Compute::Network.new( - :connection => connection, - :collection => Fog::Vcloud::Compute::Networks.new(:connection => connection), - :href => "https://vcloud.example.com/api/v1.0/admin/network/2" - ) + 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 } diff --git a/tests/vcloud/models/compute/organization_tests.rb b/tests/vcloud/models/compute/organization_tests.rb index d53604c37..1e905e3d3 100644 --- a/tests/vcloud/models/compute/organization_tests.rb +++ b/tests/vcloud/models/compute/organization_tests.rb @@ -2,7 +2,11 @@ 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').organizations.first + 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 } diff --git a/tests/vcloud/models/compute/server_tests.rb b/tests/vcloud/models/compute/server_tests.rb index b9382d9dc..05a6b5cc3 100644 --- a/tests/vcloud/models/compute/server_tests.rb +++ b/tests/vcloud/models/compute/server_tests.rb @@ -4,14 +4,17 @@ Shindo.tests("Vcloud::Compute | server", ['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" - ).first + 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 } diff --git a/tests/vcloud/models/compute/vapp_tests.rb b/tests/vcloud/models/compute/vapp_tests.rb index 30c276db4..d21a24341 100644 --- a/tests/vcloud/models/compute/vapp_tests.rb +++ b/tests/vcloud/models/compute/vapp_tests.rb @@ -5,14 +5,16 @@ Shindo.tests("Vcloud::Compute | vapp", ['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" - ).first + 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 } diff --git a/tests/vcloud/models/compute/vdc_tests.rb b/tests/vcloud/models/compute/vdc_tests.rb index dcb3db192..a175b18eb 100644 --- a/tests/vcloud/models/compute/vdc_tests.rb +++ b/tests/vcloud/models/compute/vdc_tests.rb @@ -5,14 +5,17 @@ Shindo.tests("Vcloud::Compute | vdc", ['vcloud']) do pending if Fog.mocking? - 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" - ).first + 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 }