mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
a36f3888e3
The behavior without this patch is that the performance of the vm_clone operation in unacceptably slow for VMware vCenter deployments with multiple hundreds of virtual machines. Performance is unacceptable because the vm_clone operation makes multiple API calls to list _all_ of the VM's in the inventory. This patch eliminates the need to list all VM's by adding path and folder filters to limit our API calls to subtrees of the VMware inventory. = API Changes = * New datacenters request that caches the Datacenter objects for the life of the process. * New clone() method on the server model that returns a server model of the new VM even if it is not yet done cloning. * Ability to limit collections to inventory paths by passing the * 'folder' filter to the servers collection. For example: `conn = Fog::Compute[:vsphere]; conn.servers('path' => '/Datacenters/DC1/vm/Templates')` this filter will greatly reduce the number of SOAP API calls by limiting the server models in the collection to only those in the Templates inventory folder. Note, this is not recursive yet. = Tests = Tests have been updated. The vm_clone request no longer takes an instance_uuid because we cannot actually use this to search the inventory efficiently. Instead, the vm_clone request now requires a path attribute to allow Fog to search only a subset of the inventory.
43 lines
1.4 KiB
Ruby
43 lines
1.4 KiB
Ruby
require 'fog/core/collection'
|
|
require 'fog/vsphere/models/compute/server'
|
|
|
|
module Fog
|
|
module Compute
|
|
class Vsphere
|
|
|
|
class Servers < Fog::Collection
|
|
|
|
model Fog::Compute::Vsphere::Server
|
|
|
|
# 'path' => '/Datacenters/vm/Jeff/Templates' will be MUCH faster.
|
|
# than simply listing everything.
|
|
def all(filters = {})
|
|
# REVISIT: I'm not sure if this is the best way to implement search
|
|
# filters on a collection but it does work. I need to study the AWS
|
|
# code more to make sure this matches up.
|
|
filters['folder'] ||= attributes['folder']
|
|
response = connection.list_virtual_machines(filters)
|
|
load(response['virtual_machines'])
|
|
end
|
|
|
|
def get(id)
|
|
# Is the id a managed_object_reference? This may be the case if we're reloading
|
|
# a model of a VM in the process of being cloned, since it
|
|
# will not have a instance_uuid yet.
|
|
if id =~ /^vm-/
|
|
response = connection.find_vm_by_ref('vm_ref' => id)
|
|
server_attributes = response['virtual_machine']
|
|
else
|
|
response = connection.list_virtual_machines('instance_uuid' => id)
|
|
server_attributes = response['virtual_machines'].first
|
|
end
|
|
new(server_attributes)
|
|
rescue Fog::Compute::Vsphere::NotFound
|
|
nil
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|