Class/Module Index [+]

Quicksearch

Fog::Compute::Vsphere::Server

Public Class Methods

new(attributes={} ) click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 48
def initialize(attributes={} )
  super defaults.merge(attributes)
  self.instance_uuid ||= id # TODO: remvoe instance_uuid as it can be replaced with simple id
  initialize_interfaces
  initialize_volumes
end

Public Instance Methods

clone(options = {}) click to toggle source

Clone from a server object

Parameters

*<~Hash>:

* 'name'<~String> - *REQUIRED* Name of the _new_ VirtualMachine
* See more options in vm_clone request/compute/vm_clone.rb
# File lib/fog/vsphere/models/compute/server.rb, line 106
def clone(options = {})
  requires :name, :datacenter, :relative_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['template_path'] ="#{relative_path}/#{name}"
  req_options['datacenter'] = "#{datacenter}"
  # Perform the actual clone
  clone_results = service.vm_clone(req_options)
  # Create the new VM model. TODO This only works when "wait=true"
  new_vm = self.class.new(clone_results['new_vm'])
  # We need to assign the collection and the connection otherwise we
  # cannot reload the model.
  new_vm.collection = self.collection
  new_vm.service = service
  # Return the new VM model.
  new_vm
end
config_vnc(options = {}) click to toggle source

defines VNC attributes on the hypervisor

# File lib/fog/vsphere/models/compute/server.rb, line 134
def config_vnc(options = {})
  requires :instance_uuid
  service.vm_config_vnc(options.merge('instance_uuid' => instance_uuid))
end
destroy(options = {}) click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 87
def destroy(options = {})
  requires :instance_uuid
  stop if ready? # need to turn it off before destroying
  service.vm_destroy('instance_uuid' => instance_uuid)
end
folder() click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 161
def folder
  return nil unless datacenter and path
  attributes[:folder] ||= service.folders(:datacenter => datacenter, :type => :vm).get(path)
end
interfaces() click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 153
def interfaces
  attributes[:interfaces] ||= id.nil? ? [] : service.interfaces( :vm => self )
end
mac() click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 149
def mac
  interfaces.first.mac unless interfaces.empty?
end
memory() click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 145
def memory
  memory_mb * 1024 * 1024
end
migrate(options = {}) click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 93
def migrate(options = {})
  options = { :priority => 'defaultPriority' }.merge(options)
  requires :instance_uuid
  service.vm_migrate('instance_uuid' => instance_uuid, 'priority' => options[:priority])
end
new?() click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 177
def new?
  id.nil?
end
ready?() click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 125
def ready?
  power_state == "poweredOn"
end
reboot(options = {}) click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 81
def reboot(options = {})
  options = { :force => false }.merge(options)
  requires :instance_uuid
  service.vm_reboot('instance_uuid' => instance_uuid, 'force' => options[:force])
end
reload() click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 181
def reload
  # reload does not re-read assoiciated attributes, so we clear it manually
  [:interfaces, :volumes].each do |attr|
    self.attributes.delete(attr)
  end
  super
end
save() click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 166
def save
  requires :name, :cluster, :datacenter
  if persisted?
    raise "update is not supported yet"
   # service.update_vm(attributes)
  else
    self.id = service.create_vm(attributes)
  end
  reload
end
start(options = {}) click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 70
def start(options = {})
  requires :instance_uuid
  service.vm_power_on('instance_uuid' => instance_uuid)
end
stop(options = {}) click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 75
def stop(options = {})
  options = { :force => !tools_installed? }.merge(options)
  requires :instance_uuid
  service.vm_power_off('instance_uuid' => instance_uuid, 'force' => options[:force])
end
tools_installed?() click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 129
def tools_installed?
  tools_state != "toolsNotInstalled"
end
vm_reconfig_cpus(options = {}) click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 60
def vm_reconfig_cpus(options = {})
  requires :instance_uuid, :cpus
  service.vm_reconfig_cpus('instance_uuid' => instance_uuid, 'cpus' => cpus)
end
vm_reconfig_hardware(options = {}) click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 65
def vm_reconfig_hardware(options = {})
  requires :instance_uuid, :hardware_spec
  service.vm_reconfig_hardware('instance_uuid' => instance_uuid, 'hardware_spec' => hardware_spec)
end
vm_reconfig_memory(options = {}) click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 55
def vm_reconfig_memory(options = {})
  requires :instance_uuid, :memory
  service.vm_reconfig_memory('instance_uuid' => instance_uuid, 'memory' => memory)
end
vnc() click to toggle source

returns a hash of VNC attributes required for service

# File lib/fog/vsphere/models/compute/server.rb, line 140
def vnc
  requires :instance_uuid
  service.vm_get_vnc(instance_uuid)
end
volumes() click to toggle source
# File lib/fog/vsphere/models/compute/server.rb, line 157
def volumes
  attributes[:volumes] ||= id.nil? ? [] : service.volumes( :vm => self )
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.