Class: Fog::Compute::Vsphere::Server

Inherits:
Server show all
Defined in:
lib/rackspace-fog/vsphere/models/compute/server.rb

Instance Attribute Summary

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Server

#private_key=, #scp, #scp_download, #ssh, #ssh_port, #sshable?

Methods inherited from Model

#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#clone(options = {}) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rackspace-fog/vsphere/models/compute/server.rb', line 91

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

#config_vnc(options = {}) ⇒ Object

defines VNC attributes on the hypervisor



118
119
120
121
# File 'lib/rackspace-fog/vsphere/models/compute/server.rb', line 118

def config_vnc(options = {})
  requires :instance_uuid
  connection.vm_config_vnc(options.merge('instance_uuid' => instance_uuid))
end

#create(options = {}) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/rackspace-fog/vsphere/models/compute/server.rb', line 83

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

#destroy(options = {}) ⇒ Object



72
73
74
75
# File 'lib/rackspace-fog/vsphere/models/compute/server.rb', line 72

def destroy(options = {})
  requires :instance_uuid
  connection.vm_destroy('instance_uuid' => instance_uuid)
end

#memoryObject



129
130
131
# File 'lib/rackspace-fog/vsphere/models/compute/server.rb', line 129

def memory
  memory_mb * 1024 * 1024
end

#migrate(options = {}) ⇒ Object



77
78
79
80
81
# File 'lib/rackspace-fog/vsphere/models/compute/server.rb', line 77

def migrate(options = {})
  options = { :priority => 'defaultPriority' }.merge(options)
  requires :instance_uuid
  connection.vm_migrate('instance_uuid' => instance_uuid, 'priority' => options[:priority])
end

#ready?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/rackspace-fog/vsphere/models/compute/server.rb', line 109

def ready?
  power_state == "poweredOn"
end

#reboot(options = {}) ⇒ Object



66
67
68
69
70
# File 'lib/rackspace-fog/vsphere/models/compute/server.rb', line 66

def reboot(options = {})
  options = { :force => false }.merge(options)
  requires :instance_uuid
  connection.vm_reboot('instance_uuid' => instance_uuid, 'force' => options[:force])
end

#start(options = {}) ⇒ Object



55
56
57
58
# File 'lib/rackspace-fog/vsphere/models/compute/server.rb', line 55

def start(options = {})
  requires :instance_uuid
  connection.vm_power_on('instance_uuid' => instance_uuid)
end

#stop(options = {}) ⇒ Object



60
61
62
63
64
# File 'lib/rackspace-fog/vsphere/models/compute/server.rb', line 60

def stop(options = {})
  options = { :force => !tools_installed? }.merge(options)
  requires :instance_uuid
  connection.vm_power_off('instance_uuid' => instance_uuid, 'force' => options[:force])
end

#tools_installed?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/rackspace-fog/vsphere/models/compute/server.rb', line 113

def tools_installed?
  tools_state != "toolsNotInstalled"
end

#vm_reconfig_cpus(options = {}) ⇒ Object



45
46
47
48
# File 'lib/rackspace-fog/vsphere/models/compute/server.rb', line 45

def vm_reconfig_cpus(options = {})
  requires :instance_uuid, :cpus
  connection.vm_reconfig_cpus('instance_uuid' => instance_uuid, 'cpus' => cpus)
end

#vm_reconfig_hardware(options = {}) ⇒ Object



50
51
52
53
# File 'lib/rackspace-fog/vsphere/models/compute/server.rb', line 50

def vm_reconfig_hardware(options = {})
  requires :instance_uuid, :hardware_spec
  connection.vm_reconfig_hardware('instance_uuid' => instance_uuid, 'hardware_spec' => hardware_spec)
end

#vm_reconfig_memory(options = {}) ⇒ Object



40
41
42
43
# File 'lib/rackspace-fog/vsphere/models/compute/server.rb', line 40

def vm_reconfig_memory(options = {})
  requires :instance_uuid, :memory
  connection.vm_reconfig_memory('instance_uuid' => instance_uuid, 'memory' => memory)
end

#vncObject

returns a hash of VNC attributes required for connection



124
125
126
127
# File 'lib/rackspace-fog/vsphere/models/compute/server.rb', line 124

def vnc
  requires :instance_uuid
  connection.vm_get_vnc(instance_uuid)
end