Class: Fog::Compute::Vsphere::Server
- Inherits:
-
Server
- Object
- Server
- Fog::Compute::Vsphere::Server
- Extended by:
- Deprecation
- Defined in:
- lib/fog/vsphere/models/compute/server.rb
Instance Method Summary collapse
- #add_interface(attrs) ⇒ Object
-
#clone(options = {}) ⇒ Object
Clone from a server object.
-
#config_vnc(options = {}) ⇒ Object
defines VNC attributes on the hypervisor.
- #customvalues ⇒ Object
- #destroy(options = {}) ⇒ Object
- #destroy_interface(attrs) ⇒ Object
- #folder ⇒ Object
-
#initialize(attributes = {}) ⇒ Server
constructor
A new instance of Server.
- #interface_ready?(attrs) ⇒ Boolean
- #interfaces ⇒ Object
- #mac ⇒ Object
- #memory ⇒ Object
- #migrate(options = {}) ⇒ Object
- #new? ⇒ Boolean
- #ready? ⇒ Boolean
- #reboot(options = {}) ⇒ Object
- #reload ⇒ Object
- #save ⇒ Object
- #scsi_controller ⇒ Object
- #sockets ⇒ Object
- #start(options = {}) ⇒ Object
- #stop(options = {}) ⇒ Object
- #tools_installed? ⇒ Boolean
- #tools_running? ⇒ Boolean
- #update_interface(attrs) ⇒ Object
- #vm_reconfig_cpus(options = {}) ⇒ Object
- #vm_reconfig_hardware(hardware_spec, options = {}) ⇒ Object
-
#vm_reconfig_memory(options = {}) ⇒ Object
End Lazy Loaded Attributes.
-
#vnc ⇒ Object
returns a hash of VNC attributes required for service.
- #volumes ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
51 52 53 54 55 56 57 58 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 51 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 initialize_customvalues initialize_scsi_controller end |
Instance Method Details
#add_interface(attrs) ⇒ Object
193 194 195 196 197 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 193 def add_interface attrs Fog::Logger.deprecation("<server>.add_interface is deprecated. Call <server>.interfaces.create instead.") interfaces.create(attrs) end |
#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
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 124 def clone( = {}) requires :name, :datacenter, :relative_path # Convert symbols to strings = .reduce({}) { |hsh, (k,v)| hsh[k.to_s] = v; hsh } # Give our path to the request ['template_path'] ="#{relative_path}/#{name}" ['datacenter'] = "#{datacenter}" # Perform the actual clone clone_results = service.vm_clone() # We need to assign the service, otherwise we can't reload the model # Create the new VM model. TODO This only works when "wait=true" new_vm = self.class.new(clone_results['new_vm'].merge(:service => self.service)) # We need to assign the collection otherwise we # cannot reload the model. new_vm.collection = self.collection # Return the new VM model. new_vm end |
#config_vnc(options = {}) ⇒ Object
defines VNC attributes on the hypervisor
162 163 164 165 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 162 def config_vnc( = {}) requires :instance_uuid service.vm_config_vnc(.merge('instance_uuid' => instance_uuid)) end |
#customvalues ⇒ Object
214 215 216 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 214 def customvalues attributes[:customvalues] ||= id.nil? ? [] : service.customvalues( :vm => self ) end |
#destroy(options = {}) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 101 def destroy( = {}) requires :instance_uuid if ready? # need to turn it off before destroying stop() wait_for { !ready? } end service.vm_destroy('instance_uuid' => instance_uuid) end |
#destroy_interface(attrs) ⇒ Object
204 205 206 207 208 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 204 def destroy_interface attrs Fog::Logger.deprecation("<server>.destroy_vm_interface is deprecated. Call <server>.interfaces.get(:key => <nic_key>).destroy instead.") interfaces.get(attrs[:key] || attrs['key']).destroy end |
#folder ⇒ Object
222 223 224 225 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 222 def folder return nil unless datacenter and path attributes[:folder] ||= service.folders(:datacenter => datacenter, :type => :vm).get(path) end |
#interface_ready?(attrs) ⇒ Boolean
189 190 191 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 189 def interface_ready? attrs (attrs.is_a? Hash and attrs[:blocking]) or attrs.is_a? Fog::Compute::Vsphere::Interface end |
#interfaces ⇒ Object
185 186 187 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 185 def interfaces attributes[:interfaces] ||= id.nil? ? [] : service.interfaces( :server => self ) end |
#mac ⇒ Object
181 182 183 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 181 def mac interfaces.first.mac unless interfaces.empty? end |
#memory ⇒ Object
173 174 175 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 173 def memory memory_mb * 1024 * 1024 end |
#migrate(options = {}) ⇒ Object
111 112 113 114 115 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 111 def migrate( = {}) = { :priority => 'defaultPriority' }.merge() requires :instance_uuid service.vm_migrate('instance_uuid' => instance_uuid, 'priority' => [:priority]) end |
#new? ⇒ Boolean
238 239 240 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 238 def new? id.nil? end |
#ready? ⇒ Boolean
149 150 151 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 149 def ready? power_state == "poweredOn" end |
#reboot(options = {}) ⇒ Object
95 96 97 98 99 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 95 def reboot( = {}) = { :force => false }.merge() requires :instance_uuid service.vm_reboot('instance_uuid' => instance_uuid, 'force' => [:force]) end |
#reload ⇒ Object
242 243 244 245 246 247 248 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 242 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 ⇒ Object
227 228 229 230 231 232 233 234 235 236 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 227 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 |
#scsi_controller ⇒ Object
218 219 220 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 218 def scsi_controller self.attributes[:scsi_controller] ||= service.get_vm_first_scsi_controller(id) end |
#sockets ⇒ Object
177 178 179 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 177 def sockets cpus / corespersocket end |
#start(options = {}) ⇒ Object
84 85 86 87 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 84 def start( = {}) requires :instance_uuid service.vm_power_on('instance_uuid' => instance_uuid) end |
#stop(options = {}) ⇒ Object
89 90 91 92 93 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 89 def stop( = {}) = { :force => !tools_installed? || !tools_running? }.merge() requires :instance_uuid service.vm_power_off('instance_uuid' => instance_uuid, 'force' => [:force]) end |
#tools_installed? ⇒ Boolean
153 154 155 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 153 def tools_installed? tools_state != "toolsNotInstalled" end |
#tools_running? ⇒ Boolean
157 158 159 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 157 def tools_running? tools_state == "toolsOk" end |
#update_interface(attrs) ⇒ Object
199 200 201 202 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 199 def update_interface attrs wait_for { not ready? } if interface_ready? attrs service.update_vm_interface(id, attrs) end |
#vm_reconfig_cpus(options = {}) ⇒ Object
74 75 76 77 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 74 def vm_reconfig_cpus( = {}) requires :instance_uuid, :cpus, :corespersocket service.vm_reconfig_cpus('instance_uuid' => instance_uuid, 'cpus' => cpus, 'corespersocket' => corespersocket) end |
#vm_reconfig_hardware(hardware_spec, options = {}) ⇒ Object
79 80 81 82 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 79 def vm_reconfig_hardware(hardware_spec, = {}) requires :instance_uuid service.vm_reconfig_hardware('instance_uuid' => instance_uuid, 'hardware_spec' => hardware_spec) end |
#vm_reconfig_memory(options = {}) ⇒ Object
End Lazy Loaded Attributes
69 70 71 72 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 69 def vm_reconfig_memory( = {}) requires :instance_uuid, :memory service.vm_reconfig_memory('instance_uuid' => instance_uuid, 'memory' => memory_mb) end |
#vnc ⇒ Object
returns a hash of VNC attributes required for service
168 169 170 171 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 168 def vnc requires :instance_uuid service.vm_get_vnc(instance_uuid) end |
#volumes ⇒ Object
210 211 212 |
# File 'lib/fog/vsphere/models/compute/server.rb', line 210 def volumes attributes[:volumes] ||= id.nil? ? [] : service.volumes(:server => self) end |