missing:
- new model tests
- templates model
- clone
this patch includes a lot of changes and cleanups, exposing more fog
collections/models and rewriting most requests
it includes valuable feedback from endzyme <nick.huanca@gmail.com>
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.
This massive commit refactors all of the request methods on the
Fog::Compute[:vsphere] instance to return simple hashes. The behavior
before this commit returned full vmware object references which was a
problem because it was difficult to unit test.
With this patch, it is much easier to add and maintain Mock
implementations of the request methods. This makes adding behavior
tests for the server model much easier.
In addition, test coverage using Shindo has been added. Previously
there was little test coverage of the behavior.
To run the tests:
shindont tests/vsphere/
Without this patch it is very difficult to reload the model of a VM in
the process of being cloned. All we have is the vmware managed object
reference ID string and the name of the VM.
This patch adds a number of improvements:
First, the model of a VM being cloned can reload itself after the VM
finishes cloning, even though we don't have an instance_uuid until the
clone completes.
Because the model can reload itself, it's now possible to do something
like:
c = Fog::Compute[:vsphere]
new_vm_name = "test"
c.vm_clone(:instance_uuid => "abc123", :name => new_vm_name)
my_new_vm = c.servers.find { |vm| vm.name == new_vm_name }
my_new_vm.wait_for { uuid }
puts "New VM is ready! (It has a UUID)"
my_new_vm.wait_for { ipaddress }
puts "New VM is on the network!"
Without this patch, a VM model could not reload itself with an id of
'vm-123', reloading the model only works if the ID is a UUID.
In addition, a number of the attributes of the server model have been
adjusted to be nil values when the VM is in the process of cloning.
This makes it easier to use wait_for conditionals in blocks.
Without this patch, we could not call the reload method
of a server model instance. This is because the Fog library
would try to call the get method using the existing identity
(instance_uuid) as the key.
This patch implements the get method by instantiating a new
model instance from a set of attributes obtained from the
vmware managed object instance.
The logic reflects that inside of the backspace servers
collection implementation.
As a side effect of this patch we also get wait_for.
For example:
server = Fog::Compute[:vsphere].servers.last
server.start
server.wait_for { ipaddress }
This patch adds a request list_virtual_machines which is responsible for
making an API connection and returning a raw "response" object from the
API.
Model instances of a Server (compute resource) are returned as a
collection through the "all" method. The Fog framework calls all on the
instance of the collection.