Class OpenNebula::VirtualMachine

  1. OpenNebula/VirtualMachine.rb
Pool VirtualNetworkPool ClusterPool ImagePool VirtualMachinePool HostPool UserPool XMLElement PoolElement XMLPool User VirtualNetwork Cluster Image VirtualMachine Host Enumerable Client ImageRepository Error OpenNebula dot/f_0.png

Constants

VM_METHODS = { :info => "vm.info", :allocate => "vm.allocate", :action => "vm.action", :migrate => "vm.migrate", :deploy => "vm.deploy", :savedisk => "vm.savedisk" }   Constants and Class Methods
VM_STATE = %w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED}
LCM_STATE = %w{LCM_INIT PROLOG BOOT RUNNING MIGRATE SAVE_STOP SAVE_SUSPEND SAVE_MIGRATE PROLOG_MIGRATE PROLOG_RESUME EPILOG_STOP EPILOG SHUTDOWN CANCEL FAILURE DELETE UNKNOWN}
SHORT_VM_STATES = { "INIT" => "init", "PENDING" => "pend", "HOLD" => "hold", "ACTIVE" => "actv", "STOPPED" => "stop", "SUSPENDED" => "susp", "DONE" => "done", "FAILED" => "fail" }
SHORT_LCM_STATES = { "PROLOG" => "prol", "BOOT" => "boot", "RUNNING" => "runn", "MIGRATE" => "migr", "SAVE_STOP" => "save", "SAVE_SUSPEND" => "save", "SAVE_MIGRATE" => "save", "PROLOG_MIGRATE"=> "migr", "PROLOG_RESUME" => "prol", "EPILOG_STOP" => "epil", "EPILOG" => "epil", "SHUTDOWN" => "shut", "CANCEL" => "shut", "FAILURE" => "fail", "DELETE" => "dele", "UNKNOWN" => "unkn" }
MIGRATE_REASON = %w{NONE ERROR STOP_RESUME USER CANCEL}
SHORT_MIGRATE_REASON = { "NONE" => "none", "ERROR" => "erro", "STOP_RESUME" => "stop", "USER" => "user", "CANCEL" => "canc" }

Public class methods

build_xml (pe_id=nil)

Creates a VirtualMachine description with just its identifier this method should be used to create plain VirtualMachine objects. id the id of the vm

Example:

vnet = VirtualMachine.new(VirtualMachine.build_xml(3),rpc_client)
[show source]
    # File OpenNebula/VirtualMachine.rb, line 70
70:         def VirtualMachine.build_xml(pe_id=nil)
71:             if pe_id
72:                 vm_xml = "<VM><ID>#{pe_id}</ID></VM>"
73:             else
74:                 vm_xml = "<VM></VM>"
75:             end
76: 
77:             XMLElement.build_xml(vm_xml, 'VM')
78:         end
get_reason (reason)
[show source]
    # File OpenNebula/VirtualMachine.rb, line 80
80:         def VirtualMachine.get_reason(reason)
81:             reason=MIGRATE_REASON[reason.to_i]
82:             reason_str=SHORT_MIGRATE_REASON[reason]
83: 
84:             reason_str
85:         end
new (xml, client)

Class constructor

[show source]
    # File OpenNebula/VirtualMachine.rb, line 90
90:         def initialize(xml, client)
91:             super(xml,client)
92: 
93:             @element_name = "VM"
94:             @client       = client
95:         end

Public instance methods

allocate (description)

Allocates a new VirtualMachine in OpenNebula

description A string containing the template of the VirtualMachine.

[show source]
     # File OpenNebula/VirtualMachine.rb, line 109
109:         def allocate(description)
110:             super(VM_METHODS[:allocate],description)
111:         end
cancel ()

Cancels a running VM

[show source]
     # File OpenNebula/VirtualMachine.rb, line 132
132:         def cancel
133:             action('cancel')
134:         end
deploy (host_id)

Initiates the instance of the VM on the target host.

host_id The host id (hid) of the target host where the VM will be instantiated.

[show source]
     # File OpenNebula/VirtualMachine.rb, line 117
117:         def deploy(host_id)
118:             return Error.new('ID not defined') if !@pe_id
119: 
120:             rc = @client.call(VM_METHODS[:deploy], @pe_id, host_id.to_i)
121:             rc = nil if !OpenNebula.is_error?(rc)
122: 
123:             return rc
124:         end
finalize ()

Deletes a VM from the pool and DB

[show source]
     # File OpenNebula/VirtualMachine.rb, line 162
162:         def finalize
163:             action('finalize')
164:         end
hold ()

Sets a VM to hold state, scheduler will not deploy it

[show source]
     # File OpenNebula/VirtualMachine.rb, line 137
137:         def hold
138:             action('hold')
139:         end
info ()

Retrieves the information of the given VirtualMachine.

[show source]
     # File OpenNebula/VirtualMachine.rb, line 102
102:         def info()
103:             super(VM_METHODS[:info], 'VM')
104:         end
lcm_state ()

Returns the LCM state of the VirtualMachine (numeric value)

[show source]
     # File OpenNebula/VirtualMachine.rb, line 221
221:         def lcm_state
222:             self['LCM_STATE'].to_i
223:         end
lcm_state_str ()

Returns the LCM state of the VirtualMachine (string value)

[show source]
     # File OpenNebula/VirtualMachine.rb, line 226
226:         def lcm_state_str
227:             LCM_STATE[lcm_state]
228:         end
live_migrate (host_id)

Migrates a running VM to another host without downtime

[show source]
     # File OpenNebula/VirtualMachine.rb, line 182
182:         def live_migrate(host_id)
183:             return Error.new('ID not defined') if !@pe_id
184: 
185:             rc = @client.call(VM_METHODS[:migrate], @pe_id, host_id.to_i, true)
186:             rc = nil if !OpenNebula.is_error?(rc)
187: 
188:             return rc
189:         end
migrate (host_id)

Saves a running VM and starts it again in the specified host

[show source]
     # File OpenNebula/VirtualMachine.rb, line 172
172:         def migrate(host_id)
173:             return Error.new('ID not defined') if !@pe_id
174: 
175:             rc = @client.call(VM_METHODS[:migrate], @pe_id, host_id.to_i, false)
176:             rc = nil if !OpenNebula.is_error?(rc)
177: 
178:             return rc
179:         end
release ()

Releases a VM from hold state

[show source]
     # File OpenNebula/VirtualMachine.rb, line 142
142:         def release
143:             action('release')
144:         end
restart ()

Resubmits the VM after failure

[show source]
     # File OpenNebula/VirtualMachine.rb, line 167
167:         def restart
168:             action('restart')
169:         end
resume ()

Resumes the execution of a saved VM

[show source]
     # File OpenNebula/VirtualMachine.rb, line 157
157:         def resume
158:             action('resume')
159:         end
save_as (disk_id, image_id)

Set the specified vm’s disk to be saved in a new image when the VirtualMachine shutdowns

disk_id ID of the disk to be saved

image_id ID of the new image where the disk will be saved

[show source]
     # File OpenNebula/VirtualMachine.rb, line 197
197:         def save_as(disk_id, image_id)
198:             return Error.new('ID not defined') if !@pe_id
199: 
200:             rc = @client.call(VM_METHODS[:savedisk], @pe_id, disk_id, image_id)
201:             rc = nil if !OpenNebula.is_error?(rc)
202: 
203:             return rc
204:         end
shutdown ()

Shutdowns an already deployed VM

[show source]
     # File OpenNebula/VirtualMachine.rb, line 127
127:         def shutdown
128:             action('shutdown')
129:         end
state ()

Returns the VM state of the VirtualMachine (numeric value)

[show source]
     # File OpenNebula/VirtualMachine.rb, line 211
211:         def state
212:             self['STATE'].to_i
213:         end
state_str ()

Returns the VM state of the VirtualMachine (string value)

[show source]
     # File OpenNebula/VirtualMachine.rb, line 216
216:         def state_str
217:             VM_STATE[state]
218:         end
status ()

Returns the short status string for the VirtualMachine

[show source]
     # File OpenNebula/VirtualMachine.rb, line 231
231:         def status
232:             short_state_str=SHORT_VM_STATES[state_str]
233: 
234:             if short_state_str=="actv"
235:                 short_state_str=SHORT_LCM_STATES[lcm_state_str]
236:             end
237: 
238:             short_state_str
239:         end
stop ()

Stops a running VM

[show source]
     # File OpenNebula/VirtualMachine.rb, line 147
147:         def stop
148:             action('stop')
149:         end
suspend ()

Saves a running VM

[show source]
     # File OpenNebula/VirtualMachine.rb, line 152
152:         def suspend
153:             action('suspend')
154:         end