mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
![Jeff McCune](/assets/img/avatar_default.png)
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.
82 lines
2.8 KiB
Ruby
82 lines
2.8 KiB
Ruby
require 'fog/compute/models/server'
|
|
|
|
module Fog
|
|
module Compute
|
|
class Vsphere
|
|
|
|
class Server < Fog::Compute::Server
|
|
|
|
# This will be the instance uuid which is globally unique across
|
|
# a vSphere deployment.
|
|
identity :id
|
|
|
|
# JJM REVISIT (Extend the model of a vmware server)
|
|
# SEE: http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.VirtualMachine.html
|
|
# (Take note of the See also section.)
|
|
# In particular:
|
|
# GuestInfo: information about the guest operating system
|
|
# VirtualMachineConfigInfo: Access to the VMX file and configuration
|
|
|
|
attribute :name
|
|
# UUID may be the same from VM to VM if the user does not select (I copied it)
|
|
attribute :uuid
|
|
# Instance UUID should be unique across a vCenter deployment.
|
|
attribute :instance_uuid
|
|
attribute :hostname
|
|
attribute :operatingsystem
|
|
attribute :ipaddress
|
|
attribute :power_state, :aliases => 'power'
|
|
attribute :tools_state, :aliases => 'tools'
|
|
attribute :tools_version
|
|
attribute :mac_addresses, :aliases => 'macs'
|
|
attribute :hypervisor, :aliases => 'host'
|
|
attribute :is_a_template
|
|
attribute :connection_state
|
|
attribute :mo_ref
|
|
attribute :path
|
|
|
|
def start(options = {})
|
|
requires :instance_uuid
|
|
connection.vm_power_on('instance_uuid' => instance_uuid)
|
|
end
|
|
|
|
def stop(options = {})
|
|
options = { :force => false }.merge(options)
|
|
requires :instance_uuid
|
|
connection.vm_power_off('instance_uuid' => instance_uuid, 'force' => options[:force])
|
|
end
|
|
|
|
def reboot(options = {})
|
|
options = { :force => false }.merge(options)
|
|
requires :instance_uuid
|
|
connection.vm_reboot('instance_uuid' => instance_uuid, 'force' => options[:force])
|
|
end
|
|
|
|
def destroy(options = {})
|
|
requires :instance_uuid
|
|
connection.vm_destroy('instance_uuid' => instance_uuid)
|
|
end
|
|
|
|
def clone(options = {})
|
|
requires :name, :path
|
|
# Convert symbols to strings
|
|
req_options = options.inject({}) { |hsh, (k,v)| hsh[k.to_s] = v; hsh }
|
|
# Give our path to the request
|
|
req_options['path'] ="#{path}/#{name}"
|
|
# Perform the actual clone
|
|
clone_results = connection.vm_clone(req_options)
|
|
# Create the new VM model.
|
|
new_vm = self.class.new(clone_results['vm_attributes'])
|
|
# We need to assign the collection and the connection otherwise we
|
|
# cannot reload the model.
|
|
new_vm.collection = self.collection
|
|
new_vm.connection = self.connection
|
|
# Return the new VM model.
|
|
new_vm
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|