2012-11-14 08:31:02 -05:00
|
|
|
require 'fog/core/collection'
|
|
|
|
require 'fog/vsphere/models/compute/volume'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Vsphere
|
|
|
|
class Volumes < Fog::Collection
|
2013-10-28 17:57:55 -04:00
|
|
|
attribute :server
|
2012-11-14 08:31:02 -05:00
|
|
|
|
2013-10-28 17:57:55 -04:00
|
|
|
model Fog::Compute::Vsphere::Volume
|
2012-11-14 08:31:02 -05:00
|
|
|
|
|
|
|
def all(filters = {})
|
2013-10-28 17:57:55 -04:00
|
|
|
requires :server
|
|
|
|
|
|
|
|
case server
|
2012-11-14 08:31:02 -05:00
|
|
|
when Fog::Compute::Vsphere::Server
|
2013-10-28 17:57:55 -04:00
|
|
|
load service.list_vm_volumes(server.id)
|
2012-11-14 08:31:02 -05:00
|
|
|
when Fog::Compute::Vsphere::Template
|
2013-10-28 17:57:55 -04:00
|
|
|
load service.list_template_volumes(server.id)
|
2012-11-14 08:31:02 -05:00
|
|
|
else
|
|
|
|
raise 'volumes should have vm or template'
|
2013-10-28 17:57:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
self.each { |volume| volume.server_id = server.id }
|
|
|
|
self
|
2012-11-14 08:31:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def get(id)
|
2012-12-22 18:21:53 -05:00
|
|
|
new service.get_volume(id)
|
2012-11-14 08:31:02 -05:00
|
|
|
end
|
|
|
|
|
2013-10-28 17:57:55 -04:00
|
|
|
def new(attributes = {})
|
|
|
|
if server
|
|
|
|
# Default to the root volume datastore if one is not configured.
|
|
|
|
datastore = ! attributes.has_key?(:datastore) && self.any? ? self.first.datastore : nil
|
|
|
|
|
|
|
|
super({ :server_id => server.id, :datastore => datastore }.merge!(attributes))
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
2012-11-14 08:31:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|