1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[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.
This commit is contained in:
Peter Meier 2012-01-30 15:24:14 +01:00
parent f3d97623d4
commit 3e240474ac
25 changed files with 125 additions and 106 deletions

View file

@ -52,6 +52,20 @@ module Fog
end end
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 end
end end
@ -99,22 +113,15 @@ module Fog
request :configure_vm_name_description request :configure_vm_name_description
request :configure_vm_disks request :configure_vm_disks
request :delete_vapp request :delete_vapp
request :get_catalog
request :get_catalog_item request :get_catalog_item
request :get_customization_options request :get_customization_options
request :get_network
request :get_network_ip request :get_network_ip
request :get_network_ips request :get_network_ips
request :get_network_extensions request :get_network_extensions
request :get_organization
request :get_server
request :get_task
request :get_task_list request :get_task_list
request :get_vapp
request :get_vapp_template request :get_vapp_template
request :get_vm_disks request :get_vm_disks
request :get_vm_memory request :get_vm_memory
request :get_vdc
request :instantiate_vapp_template request :instantiate_vapp_template
request :login request :login
request :power_off request :power_off
@ -138,13 +145,16 @@ module Fog
def basic_request(*args) def basic_request(*args)
self.class_eval <<-EOS, __FILE__,__LINE__ self.class_eval <<-EOS, __FILE__,__LINE__
def #{args[0]}(uri) def #{args[0]}(uri)
request({ request(
:expects => #{args[1] || 200}, {
:method => '#{args[2] || 'GET'}', :expects => #{args[1] || 200},
:headers => #{args[3] ? args[3].inspect : '{}'}, :method => '#{args[2] || 'GET'}',
:body => '#{args[4] ? args[4] : ''}', :headers => #{args[3] ? args[3].inspect : '{}'},
:parse => true, :body => '#{args[4] ? args[4] : ''}',
:uri => uri }) :parse => true,
:uri => uri
}
)
end end
EOS EOS
end end
@ -161,7 +171,6 @@ module Fog
end end
EOS EOS
end end
end end
def initialize(options = {}) def initialize(options = {})
@ -244,6 +253,17 @@ module Fog
private 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) def ensure_parsed(uri)
if uri.is_a?(String) if uri.is_a?(String)
URI.parse(uri) URI.parse(uri)
@ -311,7 +331,25 @@ module Fog
end end
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 end
end end

View file

@ -4,7 +4,7 @@ module Fog
class Catalog < Fog::Vcloud::Model class Catalog < Fog::Vcloud::Model
identity :href, :aliases => :Href identity :href, :aliases => :Href
attribute :links, :aliases => :Link, :type => :array
ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd
attribute :type attribute :type

View file

@ -4,7 +4,7 @@ module Fog
class CatalogItem < Fog::Vcloud::Model class CatalogItem < Fog::Vcloud::Model
identity :href, :aliases => :Href identity :href, :aliases => :Href
attribute :links, :aliases => :Link, :type => :array
ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd
attribute :type attribute :type

View file

@ -11,14 +11,12 @@ module Fog
def all def all
org_uri = self.organization_uri || connection.default_organization_uri 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) load(data)
end end
def get(uri) def get(uri)
if data = connection.get_catalog(uri) connection.get_catalog(uri)
new(data.body)
end
rescue Fog::Errors::NotFound rescue Fog::Errors::NotFound
nil nil
end end

View file

@ -3,9 +3,9 @@ module Fog
class Compute class Compute
class Ip < Fog::Vcloud::Model class Ip < Fog::Vcloud::Model
ignore_attributes :xmlns_i, :xmlns
identity :href, :aliases => :Href identity :href, :aliases => :Href
attribute :links, :aliases => :Link, :type => :array
ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd
attribute :name, :aliases => :Name attribute :name, :aliases => :Name
attribute :status, :aliases => :Status attribute :status, :aliases => :Status

View file

@ -4,8 +4,8 @@ module Fog
class Network < Fog::Vcloud::Model class Network < Fog::Vcloud::Model
identity :href, :aliases => :Href identity :href, :aliases => :Href
attribute :links, :aliases => :Link, :type => :array
ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd, :xmlns_i, :Id ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd
attribute :name, :aliases => :Name attribute :name, :aliases => :Name
@ -13,15 +13,9 @@ module Fog
attribute :configuration, :aliases => :Configuration attribute :configuration, :aliases => :Configuration
attribute :provider_info, :aliases => :ProviderInfo attribute :provider_info, :aliases => :ProviderInfo
attribute :links, :aliases => :Link, :type => :array
def parent_network def parent_network
return nil if configuration[:ParentNetwork].nil? return nil if configuration[:ParentNetwork].nil?
@parent_network ||= Fog::Vcloud::Compute::Network.new( @parent_network ||= connection.get_network(configuration[:ParentNetwork][:href])
:connection => connection,
:collection => Fog::Vcloud::Compute::Networks.new(:connection => connection),
:href => configuration[:ParentNetwork][:href]
)
end end
end end
end end

View file

@ -17,23 +17,20 @@ module Fog
data = nil data = nil
if self.href =~ /\/vdc\// if self.href =~ /\/vdc\//
check_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\// elsif self.href =~ /\/org\//
check_href!("Org") check_href!("Org")
links = (l=connection.get_organization(self.href).body[:Link]).is_a?(Array) ? l : [l].compact data = connection.get_organization(self.href).links.select{|l| l[:type] == 'application/vnd.vmware.vcloud.network+xml' }
data = links.select{|l| l[:type] == 'application/vnd.vmware.vcloud.network+xml' }
elsif self.href =~ /\/vApp\// elsif self.href =~ /\/vApp\//
check_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 end
load([*data]) unless data.nil? load([*data]) unless data.nil?
end end
def get(uri) def get(uri)
if data = connection.get_network(uri) connection.get_network(uri)
new(data.body) rescue Fog::Errors::NotFound
end
rescue Fog::Errors::NotFound
nil nil
end end

View file

@ -3,15 +3,14 @@ module Fog
class Compute class Compute
class Organization < Fog::Vcloud::Model class Organization < Fog::Vcloud::Model
identity :href identity :href, :aliases => :Href
attribute :links, :aliases => :Link, :type => :array
ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd
attribute :name attribute :name
attribute :description, :aliases => :Description attribute :description, :aliases => :Description
attribute :type attribute :type
attribute :full_name, :aliases => :FullName attribute :full_name, :aliases => :FullName
attribute :other_links, :aliases => :Link
def networks def networks
@networks ||= Fog::Vcloud::Compute::Networks. @networks ||= Fog::Vcloud::Compute::Networks.

View file

@ -17,9 +17,7 @@ module Fog
end end
def get(uri) def get(uri)
if data = connection.get_organization(uri) connection.get_organization(uri)
new(data.body)
end
rescue Fog::Errors::NotFound rescue Fog::Errors::NotFound
nil nil
end end

View file

@ -7,7 +7,7 @@ module Fog
include Fog::Vcloud::Compute::Helpers::Status include Fog::Vcloud::Compute::Helpers::Status
identity :href, :aliases => :Href identity :href, :aliases => :Href
attribute :links, :aliases => :Link, :type => :array
ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd
attribute :type attribute :type
@ -24,9 +24,10 @@ module Fog
attribute :guest_customization, :aliases => :GuestCustomizationSection attribute :guest_customization, :aliases => :GuestCustomizationSection
attribute :operating_system, :aliases => :'ovf:OperatingSystemSection' attribute :operating_system, :aliases => :'ovf:OperatingSystemSection'
attribute :links, :aliases => :Link, :type => :array
attribute :tasks, :aliases => :Tasks, :type => :array attribute :tasks, :aliases => :Tasks, :type => :array
has_up :vapp
def computer_name def computer_name
load_unless_loaded! load_unless_loaded!
self.guest_customization[:ComputerName] self.guest_customization[:ComputerName]
@ -44,7 +45,7 @@ module Fog
def ip_addresses def ip_addresses
load_unless_loaded! load_unless_loaded!
self.network_connections.collect{|n| n[:IpAddress] } [self.network_connections].flatten.collect{|n| n[:IpAddress] }
end end
def ready? def ready?
@ -262,7 +263,7 @@ module Fog
end end
def reload_status def reload_status
self.status = connection.get_vapp(href).body[:status] self.status = connection.get_vapp(href).status
end end
end end
end end

View file

@ -19,11 +19,7 @@ module Fog
end end
def get(uri) def get(uri)
if data = connection.get_vapp(uri) 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
rescue Fog::Errors::NotFound rescue Fog::Errors::NotFound
nil nil
end end

View file

@ -4,7 +4,7 @@ module Fog
class Task < Fog::Vcloud::Model class Task < Fog::Vcloud::Model
identity :href, :aliases => :Href identity :href, :aliases => :Href
attribute :links, :aliases => :Link, :type => :array
ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd
attribute :status attribute :status

View file

@ -19,9 +19,7 @@ module Fog
end end
def get(uri) def get(uri)
if data = connection.get_task(uri) connection.get_task(uri)
new(data.body)
end
rescue Fog::Errors::NotFound rescue Fog::Errors::NotFound
nil nil
end end

View file

@ -6,9 +6,9 @@ module Fog
include Fog::Vcloud::Compute::Helpers::Status include Fog::Vcloud::Compute::Helpers::Status
identity :href identity :href, :aliases => :Href
attribute :links, :aliases => :Link, :type => :array
ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd
attribute :name attribute :name
attribute :type attribute :type
@ -19,7 +19,9 @@ module Fog
attribute :children, :aliases => :Children, :squash => :Vm attribute :children, :aliases => :Children, :squash => :Vm
attribute :lease_settings, :aliases => :LeaseSettingsSection attribute :lease_settings, :aliases => :LeaseSettingsSection
attribute :other_links, :aliases => :Link attribute :network_configs, :aliases => :NetworkConfigSection
has_up :vdc
def servers def servers
@servers ||= Fog::Vcloud::Compute::Servers. @servers ||= Fog::Vcloud::Compute::Servers.

View file

@ -13,15 +13,11 @@ module Fog
attribute :href attribute :href
def all def all
resource_entities = (re=connection.get_vdc(self.href).body[:ResourceEntities][:ResourceEntity]).is_a?(Array) ? re : [re].compact load([connection.get_vdc(self.href).resource_entities].flatten.select { |re| re[:type] == "application/vnd.vmware.vcloud.vApp+xml" })
data = resource_entities.select { |re| re[:type] == "application/vnd.vmware.vcloud.vApp+xml" }
load(data)
end end
def get(uri) def get(uri)
if data = connection.get_vapp(uri) connection.get_vapp(uri)
new(data.body)
end
rescue Fog::Errors::NotFound rescue Fog::Errors::NotFound
nil nil
end end

View file

@ -3,9 +3,9 @@ module Fog
class Compute class Compute
class Vdc < Fog::Vcloud::Model class Vdc < Fog::Vcloud::Model
identity :href identity :href, :aliases => :Href
attribute :links, :aliases => :Link, :type => :array
ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd
attribute :name attribute :name
attribute :type attribute :type
@ -18,10 +18,10 @@ module Fog
attribute :storage_capacity, :aliases => :StorageCapacity attribute :storage_capacity, :aliases => :StorageCapacity
attribute :available_networks, :aliases => :AvailableNetworks, :squash => :Network attribute :available_networks, :aliases => :AvailableNetworks, :squash => :Network
attribute :other_links, :aliases => :Link
attribute :resource_entities, :aliases => :ResourceEntities, :squash => :ResourceEntity attribute :resource_entities, :aliases => :ResourceEntities, :squash => :ResourceEntity
has_up :organization
def networks def networks
@networks ||= Fog::Vcloud::Compute::Networks. @networks ||= Fog::Vcloud::Compute::Networks.
new( :connection => connection, new( :connection => connection,

View file

@ -13,16 +13,13 @@ module Fog
attribute :href attribute :href
def all def all
links = (l=connection.get_organization(org_uri).body[:Link]).is_a?(Array) ? l : [l].compact data = connection.get_organization(org_uri).links.select { |link| link[:type] == "application/vnd.vmware.vcloud.vdc+xml" }
data = links.select { |link| link[:type] == "application/vnd.vmware.vcloud.vdc+xml" }
data.each { |link| link.delete_if { |key, value| [:rel].include?(key) } } data.each { |link| link.delete_if { |key, value| [:rel].include?(key) } }
load(data) load(data)
end end
def get(uri) def get(uri)
if data = connection.get_vdc(uri) connection.get_vdc(uri)
new(data.body)
end
rescue Fog::Errors::NotFound rescue Fog::Errors::NotFound
nil nil
end end

View file

@ -6,7 +6,7 @@
<Link rel="undeploy" type="application/vnd.vmware.vcloud.undeployVAppParams+xml" href="https://vcloud.example.com/api/v1.0/vApp/vapp-1/action/undeploy"/> <Link rel="undeploy" type="application/vnd.vmware.vcloud.undeployVAppParams+xml" href="https://vcloud.example.com/api/v1.0/vApp/vapp-1/action/undeploy"/>
<Link rel="down" type="application/vnd.vmware.vcloud.controlAccess+xml" href="https://vcloud.example.com/api/v1.0/vApp/vapp-1/controlAccess/"/> <Link rel="down" type="application/vnd.vmware.vcloud.controlAccess+xml" href="https://vcloud.example.com/api/v1.0/vApp/vapp-1/controlAccess/"/>
<Link rel="controlAccess" type="application/vnd.vmware.vcloud.controlAccess+xml" href="https://vcloud.example.com/api/v1.0/vApp/vapp-1/action/controlAccess"/> <Link rel="controlAccess" type="application/vnd.vmware.vcloud.controlAccess+xml" href="https://vcloud.example.com/api/v1.0/vApp/vapp-1/action/controlAccess"/>
<Link rel="up" type="application/vnd.vmware.vcloud.vdc+xml" href="https://vcloud.example.com/api/v1.0/vdc/652994200"/> <Link rel="up" type="application/vnd.vmware.vcloud.vdc+xml" href="https://vcloud.example.com/api/v1.0/vdc/1"/>
<Link rel="edit" type="application/vnd.vmware.vcloud.vApp+xml" href="https://vcloud.example.com/api/v1.0/vApp/vapp-1"/> <Link rel="edit" type="application/vnd.vmware.vcloud.vApp+xml" href="https://vcloud.example.com/api/v1.0/vApp/vapp-1"/>
<Description>Some Description of a vApp</Description> <Description>Some Description of a vApp</Description>
<LeaseSettingsSection type="application/vnd.vmware.vcloud.leaseSettingsSection+xml" href="https://vcloud.example.com/api/v1.0/vApp/vapp-1/leaseSettingsSection/" ovf:required="false"> <LeaseSettingsSection type="application/vnd.vmware.vcloud.leaseSettingsSection+xml" href="https://vcloud.example.com/api/v1.0/vApp/vapp-1/leaseSettingsSection/" ovf:required="false">

View file

@ -10,7 +10,7 @@
<Link rel="power:powerOn" href="https://vcloud.example.com/api/v1.0/vApp/vm-1/power/action/powerOn"/> <Link rel="power:powerOn" href="https://vcloud.example.com/api/v1.0/vApp/vm-1/power/action/powerOn"/>
<Link rel="power:powerOff" href="https://vcloud.example.com/api/v1.0/vApp/vm-1/power/action/powerOff"/> <Link rel="power:powerOff" href="https://vcloud.example.com/api/v1.0/vApp/vm-1/power/action/powerOff"/>
<Link rel="undeploy" type="application/vnd.vmware.vcloud.undeployVAppParams+xml" href="https://vcloud.example.com/api/v1.0/vApp/vm-1/action/undeploy"/> <Link rel="undeploy" type="application/vnd.vmware.vcloud.undeployVAppParams+xml" href="https://vcloud.example.com/api/v1.0/vApp/vm-1/action/undeploy"/>
<Link rel="up" type="application/vnd.vmware.vcloud.vApp+xml" href="https://vcloud.example.com/api/v1.0/vApp/vapp-1006933678"/> <Link rel="up" type="application/vnd.vmware.vcloud.vApp+xml" href="https://vcloud.example.com/api/v1.0/vApp/vapp-1"/>
<Link rel="edit" type="application/vnd.vmware.vcloud.vm+xml" href="https://vcloud.example.com/api/v1.0/vApp/vm-1"/> <Link rel="edit" type="application/vnd.vmware.vcloud.vm+xml" href="https://vcloud.example.com/api/v1.0/vApp/vm-1"/>
<Link rel="screen:thumbnail" href="https://vcloud.example.com/api/v1.0/vApp/vm-1/screen"/> <Link rel="screen:thumbnail" href="https://vcloud.example.com/api/v1.0/vApp/vm-1/screen"/>
<Link rel="media:insertMedia" type="application/vnd.vmware.vcloud.mediaInsertOrEjectParams+xml" href="https://vcloud.example.com/api/v1.0/vApp/vm-1/media/action/insertMedia"/> <Link rel="media:insertMedia" type="application/vnd.vmware.vcloud.mediaInsertOrEjectParams+xml" href="https://vcloud.example.com/api/v1.0/vApp/vm-1/media/action/insertMedia"/>

View file

@ -10,7 +10,7 @@
<Link rel="power:powerOn" href="https://vcloud.example.com/api/v1.0/vApp/vm-2/power/action/powerOn"/> <Link rel="power:powerOn" href="https://vcloud.example.com/api/v1.0/vApp/vm-2/power/action/powerOn"/>
<Link rel="power:powerOff" href="https://vcloud.example.com/api/v1.0/vApp/vm-2/power/action/powerOff"/> <Link rel="power:powerOff" href="https://vcloud.example.com/api/v1.0/vApp/vm-2/power/action/powerOff"/>
<Link rel="undeploy" type="application/vnd.vmware.vcloud.undeployVAppParams+xml" href="https://vcloud.example.com/api/v1.0/vApp/vm-2/action/undeploy"/> <Link rel="undeploy" type="application/vnd.vmware.vcloud.undeployVAppParams+xml" href="https://vcloud.example.com/api/v1.0/vApp/vm-2/action/undeploy"/>
<Link rel="up" type="application/vnd.vmware.vcloud.vApp+xml" href="https://vcloud.example.com/api/v1.0/vApp/vapp-1006933678"/> <Link rel="up" type="application/vnd.vmware.vcloud.vApp+xml" href="https://vcloud.example.com/api/v1.0/vApp/vapp-1"/>
<Link rel="edit" type="application/vnd.vmware.vcloud.vm+xml" href="https://vcloud.example.com/api/v1.0/vApp/vm-2"/> <Link rel="edit" type="application/vnd.vmware.vcloud.vm+xml" href="https://vcloud.example.com/api/v1.0/vApp/vm-2"/>
<Link rel="screen:thumbnail" href="https://vcloud.example.com/api/v1.0/vApp/vm-2/screen"/> <Link rel="screen:thumbnail" href="https://vcloud.example.com/api/v1.0/vApp/vm-2/screen"/>
<Link rel="media:insertMedia" type="application/vnd.vmware.vcloud.mediaInsertOrEjectParams+xml" href="https://vcloud.example.com/api/v1.0/vApp/vm-2/media/action/insertMedia"/> <Link rel="media:insertMedia" type="application/vnd.vmware.vcloud.mediaInsertOrEjectParams+xml" href="https://vcloud.example.com/api/v1.0/vApp/vm-2/media/action/insertMedia"/>

View file

@ -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') connection = Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password')
tests("an org network") do tests("an org network") do
instance = Fog::Vcloud::Compute::Networks.new( instance = connection.get_network('https://vcloud.example.com/api/v1.0/network/1')
:connection => connection,
:href => "https://vcloud.example.com/api/v1.0/vApp/vapp-1"
).first
instance.reload instance.reload
tests("#href").returns("https://vcloud.example.com/api/v1.0/network/1") { instance.href } 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 end
tests("#parent_network") do 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
end end
tests("an external network") do tests("an external network") do
instance = Fog::Vcloud::Compute::Network.new( instance = connection.get_network('https://vcloud.example.com/api/v1.0/admin/network/2')
:connection => connection,
:collection => Fog::Vcloud::Compute::Networks.new(:connection => connection),
:href => "https://vcloud.example.com/api/v1.0/admin/network/2"
)
instance.reload instance.reload
tests("#href").returns("https://vcloud.example.com/api/v1.0/admin/network/2") { instance.href } tests("#href").returns("https://vcloud.example.com/api/v1.0/admin/network/2") { instance.href }
tests("#name").returns("ParentNetwork1") { instance.name } tests("#name").returns("ParentNetwork1") { instance.name }

View file

@ -2,7 +2,11 @@ Shindo.tests("Vcloud::Compute | organization", ['vcloud']) do
pending if Fog.mocking? 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 instance.reload
tests("#href").returns('https://vcloud.example.com/api/v1.0/org/1'){ instance.href } tests("#href").returns('https://vcloud.example.com/api/v1.0/org/1'){ instance.href }

View file

@ -4,14 +4,17 @@ Shindo.tests("Vcloud::Compute | server", ['vcloud']) do
pending if Fog.mocking? pending if Fog.mocking?
instance = Fog::Vcloud::Compute::Servers.new( instance = Fog::Vcloud::Compute.new(
:connection => Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password'), :vcloud_host => 'vcloud.example.com',
:href => "https://vcloud.example.com/api/v1.0/vApp/vapp-1" :vcloud_username => 'username',
).first :vcloud_password => 'password'
).get_server('https://vcloud.example.com/api/v1.0/vApp/vm-2')
instance.reload instance.reload
tests("#href").returns("https://vcloud.example.com/api/v1.0/vApp/vm-2") { instance.href } tests("#href").returns("https://vcloud.example.com/api/v1.0/vApp/vm-2") { instance.href }
tests("#name").returns("vm2") { instance.name } tests("#name").returns("vm2") { instance.name }
tests("#vapp").returns("vApp1") { instance.vapp.name }
tests("#description").returns("Some VM Description") { instance.description } tests("#description").returns("Some VM Description") { instance.description }
tests("#status").returns('8') { instance.status } tests("#status").returns('8') { instance.status }
tests("#deployed").returns(true) { instance.deployed } tests("#deployed").returns(true) { instance.deployed }

View file

@ -5,14 +5,16 @@ Shindo.tests("Vcloud::Compute | vapp", ['vcloud']) do
pending if Fog.mocking? pending if Fog.mocking?
instance = Fog::Vcloud::Compute::Vapps.new( instance = Fog::Vcloud::Compute.new(
:connection => Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password'), :vcloud_host => 'vcloud.example.com',
:href => "https://vcloud.example.com/api/v1.0/vdc/1" :vcloud_username => 'username',
).first :vcloud_password => 'password'
).get_vapp('https://vcloud.example.com/api/v1.0/vApp/vapp-1')
instance.reload instance.reload
tests("#href").returns("https://vcloud.example.com/api/v1.0/vApp/vapp-1") { instance.href } tests("#href").returns("https://vcloud.example.com/api/v1.0/vApp/vapp-1") { instance.href }
tests("#name").returns("vApp1") { instance.name } tests("#name").returns("vApp1") { instance.name }
tests("#vdc").returns("vDC1"){ instance.vdc.name }
tests("#description").returns("Some Description of a vApp") { instance.description } tests("#description").returns("Some Description of a vApp") { instance.description }
tests("#status").returns('8') { instance.status } tests("#status").returns('8') { instance.status }
tests("#deployed").returns(true) { instance.deployed } tests("#deployed").returns(true) { instance.deployed }

View file

@ -5,14 +5,17 @@ Shindo.tests("Vcloud::Compute | vdc", ['vcloud']) do
pending if Fog.mocking? pending if Fog.mocking?
instance = Fog::Vcloud::Compute::Vdcs.new( instance = Fog::Vcloud::Compute.new(
:connection => Fog::Vcloud::Compute.new(:vcloud_host => 'vcloud.example.com', :vcloud_username => 'username', :vcloud_password => 'password'), :vcloud_host => 'vcloud.example.com',
:href => "https://vcloud.example.com/api/v1.0/org/1" :vcloud_username => 'username',
).first :vcloud_password => 'password'
).get_vdc('https://vcloud.example.com/api/v1.0/vdc/1')
instance.reload instance.reload
tests("#href").returns("https://vcloud.example.com/api/v1.0/vdc/1") { instance.href } tests("#href").returns("https://vcloud.example.com/api/v1.0/vdc/1") { instance.href }
tests("#name").returns("vDC1") { instance.name } tests("#name").returns("vDC1") { instance.name }
tests('#organization').returns("Org1") { instance.organization.name }
tests("#description").returns("Some Description") { instance.description } tests("#description").returns("Some Description") { instance.description }
tests("#network_quota").returns(10) { instance.network_quota } tests("#network_quota").returns(10) { instance.network_quota }
tests("#nic_quota").returns(10) { instance.nic_quota } tests("#nic_quota").returns(10) { instance.nic_quota }