Class: Fog::Compute::Vsphere::Server
Instance Attribute Summary
Attributes inherited from Server
#private_key, #private_key_path, #public_key, #public_key_path, #ssh_port, #username
Attributes inherited from Model
#collection, #service
Instance Method Summary
collapse
deprecate, self_deprecate
Methods inherited from Server
#scp, #scp_download, #ssh, #sshable?
Methods inherited from Model
#inspect, #symbolize_keys, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#connection, #connection=, #prepare_service_value
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
48
49
50
51
52
53
|
# File 'lib/fog/vsphere/models/compute/server.rb', line 48
def initialize(attributes={} )
super defaults.merge(attributes)
self.instance_uuid ||= id initialize_interfaces
initialize_volumes
end
|
Instance Method Details
#clone(options = {}) ⇒ Object
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/fog/vsphere/models/compute/server.rb', line 106
def clone(options = {})
requires :name, :datacenter, :relative_path
req_options = options.inject({}) { |hsh, (k,v)| hsh[k.to_s] = v; hsh }
req_options['template_path'] ="#{relative_path}/#{name}"
req_options['datacenter'] = "#{datacenter}"
clone_results = service.vm_clone(req_options)
new_vm = self.class.new(clone_results['new_vm'])
new_vm.collection = self.collection
new_vm.service = service
new_vm
end
|
#config_vnc(options = {}) ⇒ Object
defines VNC attributes on the hypervisor
134
135
136
137
|
# 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 = {}) ⇒ Object
87
88
89
90
91
|
# File 'lib/fog/vsphere/models/compute/server.rb', line 87
def destroy(options = {})
requires :instance_uuid
stop if ready? service.vm_destroy('instance_uuid' => instance_uuid)
end
|
#folder ⇒ Object
161
162
163
164
|
# 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 ⇒ Object
153
154
155
|
# File 'lib/fog/vsphere/models/compute/server.rb', line 153
def interfaces
attributes[:interfaces] ||= id.nil? ? [] : service.interfaces( :vm => self )
end
|
#mac ⇒ Object
149
150
151
|
# File 'lib/fog/vsphere/models/compute/server.rb', line 149
def mac
interfaces.first.mac unless interfaces.empty?
end
|
#memory ⇒ Object
145
146
147
|
# File 'lib/fog/vsphere/models/compute/server.rb', line 145
def memory
memory_mb * 1024 * 1024
end
|
#migrate(options = {}) ⇒ Object
93
94
95
96
97
|
# 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? ⇒ Boolean
177
178
179
|
# File 'lib/fog/vsphere/models/compute/server.rb', line 177
def new?
id.nil?
end
|
#ready? ⇒ Boolean
125
126
127
|
# File 'lib/fog/vsphere/models/compute/server.rb', line 125
def ready?
power_state == "poweredOn"
end
|
#reboot(options = {}) ⇒ Object
81
82
83
84
85
|
# 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 ⇒ Object
181
182
183
184
185
186
187
|
# File 'lib/fog/vsphere/models/compute/server.rb', line 181
def reload
[:interfaces, :volumes].each do |attr|
self.attributes.delete(attr)
end
super
end
|
#save ⇒ Object
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/fog/vsphere/models/compute/server.rb', line 166
def save
requires :name, :cluster, :datacenter
if persisted?
raise "update is not supported yet"
else
self.id = service.create_vm(attributes)
end
reload
end
|
#start(options = {}) ⇒ Object
70
71
72
73
|
# 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 = {}) ⇒ Object
75
76
77
78
79
|
# 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
|
129
130
131
|
# File 'lib/fog/vsphere/models/compute/server.rb', line 129
def tools_installed?
tools_state != "toolsNotInstalled"
end
|
#vm_reconfig_cpus(options = {}) ⇒ Object
60
61
62
63
|
# 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 = {}) ⇒ Object
65
66
67
68
|
# 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 = {}) ⇒ Object
55
56
57
58
|
# 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 ⇒ Object
returns a hash of VNC attributes required for service
140
141
142
143
|
# File 'lib/fog/vsphere/models/compute/server.rb', line 140
def vnc
requires :instance_uuid
service.vm_get_vnc(instance_uuid)
end
|
#volumes ⇒ Object
157
158
159
|
# File 'lib/fog/vsphere/models/compute/server.rb', line 157
def volumes
attributes[:volumes] ||= id.nil? ? [] : service.volumes( :vm => self )
end
|