1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/vcloud/models/compute/servers.rb
Peter Meier 750fb59f25 [vcloud|compute] improve models add tests
Improve the models to work with the current api version. add tests
that use fake-data, that was captured from a real vCloud.

Also removed a couple of dead code. Tests have been added for
everything that changed or have been added. All the existing but
untouched parts have not been tested.
2011-11-29 11:37:18 +01:00

56 lines
1.2 KiB
Ruby

require 'fog/vcloud/models/compute/server'
module Fog
module Vcloud
class Compute
class Servers < Fog::Vcloud::Collection
undef_method :create
model Fog::Vcloud::Compute::Server
attribute :href, :aliases => :Href
def all
check_href!("Vapp")
vapp.load_unless_loaded!
load(vapp.children||[])
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
rescue Fog::Errors::NotFound
nil
end
def create options
check_href!
options[:vdc_uri] = href
data = connection.instantiate_vapp_template(options).body
object = new(data)
object
end
private
def vapp
@vapp ||= (attributes[:vapp] || init_vapp)
end
def init_vapp
Fog::Vcloud::Compute::Vapp.new(
:connection => connection,
:href => self.href,
:collection => Fog::Vcloud::Compute::Vapps.new(:connection => connection)
)
end
end
end
end
end