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

13 commits

Author SHA1 Message Date
Jeff McCune
dc9a2e4808 (#9124) Add ability to reload the model of a cloning VM
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.
2011-09-10 13:32:59 -07:00
Jeff McCune
96ada81149 (#9241) Make the reload action of the server models work
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 }
2011-09-10 13:32:58 -07:00
Jeff McCune
27a689b951 (#9241) Don't fail when trying to model a cloning VM
With the introduction of the vm_clone API request, a server
may be returned in the list which does not have a complete
configuration yet.  This is because the system is still in
the process of being cloned.

This is a problem because Fog would throw an undefined
method error when calling the config method of the vm managed
object instance.

This patch fixes the problem by checking if the config method
returns something and only sets attributes that are known to be
available for a cloning VM.
2011-09-10 13:32:58 -07:00
Jeff McCune
ef2833cb20 (#9241) Add vm_clone API request
Without this patch we have no way to clone a new VM
from a template.  This patch adds the vm_clone request
which takes an instance uuid as the source template
to clone from an a name parameter which is the new VM's
name.

The clone operation is handled asynchronously as a vSphere
task object.  The clone request does not return a handle
for this task, which may make it difficult to monitor
the progress of the clone operation from Fog.  A future
enhancement may be to clone and return the task object
itself to monitor progress.
2011-09-10 13:32:58 -07:00
Jeff McCune
856eb7e033 (#9241) Add find_template_by_instance_uuid request
Without this patch we did not have a convenient way to find
a template by instance UUID.  We could only find virtual
machines by instance UUID, which may or may not be a template.

This patch adds a specific request to obtain the VMware managed
object instance of of a specific template.  This is necessary
plumbing for the clone request.
2011-09-10 13:32:58 -07:00
Jeff McCune
4264b1f99c (#9241) Add destroy API request and model action
Without this patch we have no way to completely destroy
a server instance.  This patch adds a vm_destroy API request
and implements the destroy method on the server model.

The vSphere API requires the server to be in a poweredOff state.
The model action and the request do not verify this is the case
before issuing the command.
2011-09-10 13:32:58 -07:00
Jeff McCune
cb4e9701b5 (#9421) Add start, stop, reboot server model methods
This patch implements the start, stop and reboot methods for the Server
model instances.

These server model methods share common names with the AWS server model.

This patch also implements the API requests required to control the
power state of a VMware Virtual Machine.

The requests default to issuing shutdown and reboot commands to the
guest operating system itself.  However, if force is set to true for
power_off and reboot, then the VM is powered off or reset at the virtual
hardware layer.
2011-09-10 13:32:58 -07:00
Jeff McCune
d6fed7e4e4 (#9241) Add ability to find VMs by UUID
This patch adds two request methods to the compute service for VMware.
First, finding a VM by it's own UUID (from the vmx file) is supported.
This UUID is not guaranteed to be unique so this patch also implements
finding by instance UUID which is guaranteed to be unique.

The server models will primarily use these requests to obtain VM
managed objects to issue commands against.
2011-09-10 13:32:58 -07:00
Jeff McCune
00fbdaa932 (#9241) Add test skeleton framework
Without this patch the change set currently has no framework for testing
the Vsphere provider.  This patch doesn't actually test anything, but
does add the skeleton code to being testing mocked versions of other
code.

Particularly, we're going to take the approach of completely mocking the
@connection instance variable of the Compute instance.  This will allow
us to set expectations and return things from the underlying vmware API
library.
2011-09-10 13:32:58 -07:00
Jeff McCune
8bc5c768ec (#9241) Add model for Fog::Compute[:vsphere].servers
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.
2011-09-10 13:32:58 -07:00
Jeff McCune
cf75fb1358 (#9241) Add current_time request
Without this patch, no actual API calls are being made through the Fog
layer to the underlying rbvmobi later and ultimately to the vSphere
target API.

This patch adds a simple current_time request which is similar to a
"ping"  The layers and API are exercised fully using this simple API
call to retrieve the current time on the remote system.

This provides:

    >> Fog::Compute[:vsphere].current_time
    Tue Aug 30 20:46:27 UTC 2011
    >> Fog::Compute[:vsphere].requests
    [:current_time]
2011-09-10 13:32:58 -07:00
Jeff McCune
ec32398811 (#9241) Add SSL verification
Without this patch we were blindly trusting the remote end of our API
connection is who they claim to be.  This is an insecure state because
we leave ourselves open to a man in the middle attack.

This patch adds a vsphere_expected_pubkey_hash setting for the Vsphere
provider.  This setting is expected to be the SHA256 hex digest string
of the PEM encoded text of the RSA public key.

The first time an end user connects this string is displayed to them in
the error message.  They need simply copy and paste it into ~/.fog to
securely connect to the remote end.

For example:

   :vspherebadpw:
     :vsphere_server: vc01.acme.lan
     :vsphere_username: api_login
     :vsphere_password: badpassword
     :vsphere_expected_pubkey_hash: 431dd...
2011-09-10 13:32:58 -07:00
Jeff McCune
98637d39da (#9241) Add skeleton VMware vSphere platform support
This patch adds a compute service to fog setting the stage to model
VMware virtual machines using Fog.  The patch adds support for:

    rdebug -- fog vsphere
    >>> connection = Fog::Compute.new(:provider => :vsphere)

The connection to the VMware API is implemented along with
authentication using an username and password.  The connection is not
fully secured with this patch because no validation of the SSL
certificate is implemented.

Raw API requests are working with this patch, but none of the API
requests have associated Fog models or collections.
2011-09-10 13:32:58 -07:00