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

If a reference to the Vsphere::Server object is passed explicitly, to the Vsphere::Volumes collection, a loop is introduced when attempting to print out the Vsphere::Server object. The attributes for the server will include a reference to the Vsphere::Volumes collection, which in turn includes a reference to the server object. As opposed to passing a reference to the Vsphere::Server object to the Vsphere::Volumes collection, this patch modifies the interface to expect a Vsphere:Server ID. The ID is used to perform any subsequent lookups of the server object -- if required. Fixes: #2938
54 lines
1.3 KiB
Ruby
54 lines
1.3 KiB
Ruby
require 'fog/core/collection'
|
|
require 'fog/vsphere/models/compute/volume'
|
|
|
|
module Fog
|
|
module Compute
|
|
class Vsphere
|
|
class Volumes < Fog::Collection
|
|
attribute :server_id
|
|
|
|
model Fog::Compute::Vsphere::Volume
|
|
|
|
def all(filters = {})
|
|
requires :server_id
|
|
|
|
case server
|
|
when Fog::Compute::Vsphere::Server
|
|
load service.list_vm_volumes(server.id)
|
|
when Fog::Compute::Vsphere::Template
|
|
load service.list_template_volumes(server.id)
|
|
else
|
|
raise 'volumes should have vm or template'
|
|
end
|
|
|
|
self.each { |volume| volume.server_id = server.id }
|
|
self
|
|
end
|
|
|
|
def get(id)
|
|
new service.get_volume(id)
|
|
end
|
|
|
|
def new(attributes = {})
|
|
if server_id
|
|
# Default to the root volume datastore if one is not configured.
|
|
datastore = ! attributes.key?(:datastore) && self.any? ? self.first.datastore : nil
|
|
|
|
super({ :server_id => server_id, :datastore => datastore }.merge!(attributes))
|
|
else
|
|
super
|
|
end
|
|
end
|
|
|
|
def server
|
|
return nil if server_id.nil?
|
|
service.servers.get(server_id)
|
|
end
|
|
|
|
def server=(new_server)
|
|
server_id = new_server.id
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|