2011-09-01 18:10:57 -04:00
|
|
|
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
|
2011-09-10 16:27:52 -04:00
|
|
|
attribute :connection_state
|
|
|
|
attribute :mo_ref
|
2011-10-28 10:10:37 -04:00
|
|
|
attribute :path
|
2011-09-01 18:10:57 -04:00
|
|
|
|
2011-09-10 16:27:52 -04:00
|
|
|
def start(options = {})
|
2011-09-02 14:04:24 -04:00
|
|
|
requires :instance_uuid
|
2011-09-10 16:27:52 -04:00
|
|
|
connection.vm_power_on('instance_uuid' => instance_uuid)
|
2011-09-02 14:04:24 -04:00
|
|
|
end
|
|
|
|
|
2011-09-10 16:27:52 -04:00
|
|
|
def stop(options = {})
|
|
|
|
options = { :force => false }.merge(options)
|
2011-09-02 14:04:24 -04:00
|
|
|
requires :instance_uuid
|
2011-09-10 16:27:52 -04:00
|
|
|
connection.vm_power_off('instance_uuid' => instance_uuid, 'force' => options[:force])
|
2011-09-02 14:04:24 -04:00
|
|
|
end
|
|
|
|
|
2011-09-10 16:27:52 -04:00
|
|
|
def reboot(options = {})
|
|
|
|
options = { :force => false }.merge(options)
|
2011-09-02 14:04:24 -04:00
|
|
|
requires :instance_uuid
|
2011-09-10 16:27:52 -04:00
|
|
|
connection.vm_reboot('instance_uuid' => instance_uuid, 'force' => options[:force])
|
2011-09-02 14:04:24 -04:00
|
|
|
end
|
|
|
|
|
2011-09-10 16:27:52 -04:00
|
|
|
def destroy(options = {})
|
2011-09-06 19:41:37 -04:00
|
|
|
requires :instance_uuid
|
2011-09-10 16:27:52 -04:00
|
|
|
connection.vm_destroy('instance_uuid' => instance_uuid)
|
2011-09-06 19:41:37 -04:00
|
|
|
end
|
2012-01-11 21:35:55 -05:00
|
|
|
def create(options ={})
|
|
|
|
requires :name, :path
|
|
|
|
new_vm = self.class.new(create_results['vm_attributes'])
|
|
|
|
new_vm.collection = self.collection
|
|
|
|
new_vm.connection = self.connection
|
|
|
|
new_vm
|
|
|
|
end
|
2011-11-10 19:01:22 -05:00
|
|
|
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
|
|
|
|
|
2011-09-01 18:10:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|