
Methods
public class
public instance
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
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)
# 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
# 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
Class constructor
# 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
Allocates a new VirtualMachine in OpenNebula
description A string containing the template of the VirtualMachine.
# File OpenNebula/VirtualMachine.rb, line 109 109: def allocate(description) 110: super(VM_METHODS[:allocate],description) 111: end
Cancels a running VM
# File OpenNebula/VirtualMachine.rb, line 132 132: def cancel 133: action('cancel') 134: end
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.
# 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
Deletes a VM from the pool and DB
# File OpenNebula/VirtualMachine.rb, line 162 162: def finalize 163: action('finalize') 164: end
Sets a VM to hold state, scheduler will not deploy it
# File OpenNebula/VirtualMachine.rb, line 137 137: def hold 138: action('hold') 139: end
Retrieves the information of the given VirtualMachine.
# File OpenNebula/VirtualMachine.rb, line 102 102: def info() 103: super(VM_METHODS[:info], 'VM') 104: end
Returns the LCM state of the VirtualMachine (numeric value)
# File OpenNebula/VirtualMachine.rb, line 221 221: def lcm_state 222: self['LCM_STATE'].to_i 223: end
Returns the LCM state of the VirtualMachine (string value)
# File OpenNebula/VirtualMachine.rb, line 226 226: def lcm_state_str 227: LCM_STATE[lcm_state] 228: end
Migrates a running VM to another host without downtime
# 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
Saves a running VM and starts it again in the specified host
# 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
Releases a VM from hold state
# File OpenNebula/VirtualMachine.rb, line 142 142: def release 143: action('release') 144: end
Resubmits the VM after failure
# File OpenNebula/VirtualMachine.rb, line 167 167: def restart 168: action('restart') 169: end
Resumes the execution of a saved VM
# File OpenNebula/VirtualMachine.rb, line 157 157: def resume 158: action('resume') 159: end
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
# 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
Shutdowns an already deployed VM
# File OpenNebula/VirtualMachine.rb, line 127 127: def shutdown 128: action('shutdown') 129: end
Returns the VM state of the VirtualMachine (numeric value)
# File OpenNebula/VirtualMachine.rb, line 211 211: def state 212: self['STATE'].to_i 213: end
Returns the VM state of the VirtualMachine (string value)
# File OpenNebula/VirtualMachine.rb, line 216 216: def state_str 217: VM_STATE[state] 218: end
Returns the short status string for the VirtualMachine
# 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
Stops a running VM
# File OpenNebula/VirtualMachine.rb, line 147 147: def stop 148: action('stop') 149: end
Saves a running VM
# File OpenNebula/VirtualMachine.rb, line 152 152: def suspend 153: action('suspend') 154: end