mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
743882f032
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/
63 lines
2 KiB
Ruby
63 lines
2 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
|
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|