Class: OpenNebula::VirtualMachine
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::VirtualMachine
- Defined in:
- lib/opennebula/virtual_machine.rb
Defined Under Namespace
Modules: Driver
Constant Summary collapse
- VM_METHODS =
Constants and Class Methods
{ :info => 'vm.info', :allocate => 'vm.allocate', :action => 'vm.action', :migrate => 'vm.migrate', :deploy => 'vm.deploy', :chown => 'vm.chown', :chmod => 'vm.chmod', :monitoring => 'vm.monitoring', :attach => 'vm.attach', :detach => 'vm.detach', :rename => 'vm.rename', :update => 'vm.update', :resize => 'vm.resize', :snapshotcreate => 'vm.snapshotcreate', :snapshotrevert => 'vm.snapshotrevert', :snapshotdelete => 'vm.snapshotdelete', :attachnic => 'vm.attachnic', :detachnic => 'vm.detachnic', :recover => 'vm.recover', :disksaveas => 'vm.disksaveas', :disksnapshotcreate => 'vm.disksnapshotcreate', :disksnapshotrevert => 'vm.disksnapshotrevert', :disksnapshotdelete => 'vm.disksnapshotdelete', :disksnapshotrename => 'vm.disksnapshotrename', :diskresize => 'vm.diskresize', :updateconf => 'vm.updateconf', :lock => 'vm.lock', :unlock => 'vm.unlock', :schedadd => 'vm.schedadd', :scheddelete => 'vm.scheddelete', :schedupdate => 'vm.schedupdate', :attachsg => 'vm.attachsg', :detachsg => 'vm.detachsg', :backup => 'vm.backup', :updatenic => 'vm.updatenic', :backupcancel => 'vm.backupcancel', :attachpci => 'vm.attachpci', :detachpci => 'vm.detachpci', :restore => 'vm.restore', :exec => 'vm.exec', :retryexec => 'vm.retryexec', :cancelexec => 'vm.cancelexec' }
- VM_STATE =
['INIT', 'PENDING', 'HOLD', 'ACTIVE', 'STOPPED', 'SUSPENDED', 'DONE', 'FAILED', 'POWEROFF', 'UNDEPLOYED', 'CLONING', 'CLONING_FAILURE']
- LCM_STATE =
[ 'LCM_INIT', 'PROLOG', 'BOOT', 'RUNNING', 'MIGRATE', 'SAVE_STOP', 'SAVE_SUSPEND', 'SAVE_MIGRATE', 'PROLOG_MIGRATE', 'PROLOG_RESUME', 'EPILOG_STOP', 'EPILOG', 'SHUTDOWN', 'CANCEL', 'FAILURE', 'CLEANUP_RESUBMIT', 'UNKNOWN', 'HOTPLUG', 'SHUTDOWN_POWEROFF', 'BOOT_UNKNOWN', 'BOOT_POWEROFF', 'BOOT_SUSPENDED', 'BOOT_STOPPED', 'CLEANUP_DELETE', 'HOTPLUG_SNAPSHOT', 'HOTPLUG_NIC', 'HOTPLUG_SAVEAS', 'HOTPLUG_SAVEAS_POWEROFF', 'HOTPLUG_SAVEAS_SUSPENDED', 'SHUTDOWN_UNDEPLOY', 'EPILOG_UNDEPLOY', 'PROLOG_UNDEPLOY', 'BOOT_UNDEPLOY', 'HOTPLUG_PROLOG_POWEROFF', 'HOTPLUG_EPILOG_POWEROFF', 'BOOT_MIGRATE', 'BOOT_FAILURE', 'BOOT_MIGRATE_FAILURE', 'PROLOG_MIGRATE_FAILURE', 'PROLOG_FAILURE', 'EPILOG_FAILURE', 'EPILOG_STOP_FAILURE', 'EPILOG_UNDEPLOY_FAILURE', 'PROLOG_MIGRATE_POWEROFF', 'PROLOG_MIGRATE_POWEROFF_FAILURE', 'PROLOG_MIGRATE_SUSPEND', 'PROLOG_MIGRATE_SUSPEND_FAILURE', 'BOOT_UNDEPLOY_FAILURE', 'BOOT_STOPPED_FAILURE', 'PROLOG_RESUME_FAILURE', 'PROLOG_UNDEPLOY_FAILURE', 'DISK_SNAPSHOT_POWEROFF', 'DISK_SNAPSHOT_REVERT_POWEROFF', 'DISK_SNAPSHOT_DELETE_POWEROFF', 'DISK_SNAPSHOT_SUSPENDED', 'DISK_SNAPSHOT_REVERT_SUSPENDED', 'DISK_SNAPSHOT_DELETE_SUSPENDED', 'DISK_SNAPSHOT', 'DISK_SNAPSHOT_REVERT', 'DISK_SNAPSHOT_DELETE', 'PROLOG_MIGRATE_UNKNOWN', 'PROLOG_MIGRATE_UNKNOWN_FAILURE', 'DISK_RESIZE', 'DISK_RESIZE_POWEROFF', 'DISK_RESIZE_UNDEPLOYED', 'HOTPLUG_NIC_POWEROFF', 'HOTPLUG_RESIZE', 'HOTPLUG_SAVEAS_UNDEPLOYED', 'HOTPLUG_SAVEAS_STOPPED', 'BACKUP', 'BACKUP_POWEROFF', 'RESTORE' ]
- SHORT_VM_STATES =
{ 'INIT' => 'init', 'PENDING' => 'pend', 'HOLD' => 'hold', 'ACTIVE' => 'actv', 'STOPPED' => 'stop', 'SUSPENDED' => 'susp', 'DONE' => 'done', 'FAILED' => 'fail', 'POWEROFF' => 'poff', 'UNDEPLOYED' => 'unde', 'CLONING' => 'clon', 'CLONING_FAILURE' => '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', 'CLEANUP_RESUBMIT' => 'clea', 'UNKNOWN' => 'unkn', 'HOTPLUG' => 'hotp', 'SHUTDOWN_POWEROFF' => 'shut', 'BOOT_UNKNOWN' => 'boot', 'BOOT_POWEROFF' => 'boot', 'BOOT_SUSPENDED' => 'boot', 'BOOT_STOPPED' => 'boot', 'CLEANUP_DELETE' => 'clea', 'HOTPLUG_SNAPSHOT' => 'snap', 'HOTPLUG_NIC' => 'hotp', 'HOTPLUG_SAVEAS' => 'hotp', 'HOTPLUG_SAVEAS_POWEROFF' => 'hotp', 'HOTPLUG_SAVEAS_SUSPENDED' => 'hotp', 'SHUTDOWN_UNDEPLOY' => 'shut', 'EPILOG_UNDEPLOY' => 'epil', 'PROLOG_UNDEPLOY' => 'prol', 'BOOT_UNDEPLOY' => 'boot', 'HOTPLUG_PROLOG_POWEROFF' => 'hotp', 'HOTPLUG_EPILOG_POWEROFF' => 'hotp', 'BOOT_MIGRATE' => 'boot', 'BOOT_FAILURE' => 'fail', 'BOOT_MIGRATE_FAILURE' => 'fail', 'PROLOG_MIGRATE_FAILURE' => 'fail', 'PROLOG_FAILURE' => 'fail', 'EPILOG_FAILURE' => 'fail', 'EPILOG_STOP_FAILURE' => 'fail', 'EPILOG_UNDEPLOY_FAILURE' => 'fail', 'PROLOG_MIGRATE_POWEROFF' => 'migr', 'PROLOG_MIGRATE_POWEROFF_FAILURE' => 'fail', 'PROLOG_MIGRATE_SUSPEND' => 'migr', 'PROLOG_MIGRATE_SUSPEND_FAILURE' => 'fail', 'BOOT_UNDEPLOY_FAILURE' => 'fail', 'BOOT_STOPPED_FAILURE' => 'fail', 'PROLOG_RESUME_FAILURE' => 'fail', 'PROLOG_UNDEPLOY_FAILURE' => 'fail', 'DISK_SNAPSHOT_POWEROFF' => 'snap', 'DISK_SNAPSHOT_REVERT_POWEROFF' => 'snap', 'DISK_SNAPSHOT_DELETE_POWEROFF' => 'snap', 'DISK_SNAPSHOT_SUSPENDED' => 'snap', 'DISK_SNAPSHOT_REVERT_SUSPENDED'=> 'snap', 'DISK_SNAPSHOT_DELETE_SUSPENDED'=> 'snap', 'DISK_SNAPSHOT' => 'snap', 'DISK_SNAPSHOT_DELETE' => 'snap', 'PROLOG_MIGRATE_UNKNOWN' => 'migr', 'PROLOG_MIGRATE_UNKNOWN_FAILURE' => 'fail', 'DISK_RESIZE' => 'drsz', 'DISK_RESIZE_POWEROFF' => 'drsz', 'DISK_RESIZE_UNDEPLOYED' => 'drsz', 'HOTPLUG_NIC_POWEROFF' => 'hotp', 'HOTPLUG_RESIZE' => 'hotp', 'HOTPLUG_SAVEAS_UNDEPLOYED' => 'hotp', 'HOTPLUG_SAVEAS_STOPPED' => 'hotp', 'BACKUP' => 'back', 'BACKUP_POWEROFF' => 'back', 'RESTORE' => 'rest' }
- HISTORY_ACTION =
[ 'none', 'migrate', 'live-migrate', 'shutdown', 'shutdown-hard', 'undeploy', 'undeploy-hard', 'hold', 'release', 'stop', 'suspend', 'resume', 'boot', 'delete', 'delete-recreate', 'reboot', 'reboot-hard', 'resched', 'unresched', 'poweroff', 'poweroff-hard', 'disk-attach', 'disk-detach', 'nic-attach', 'nic-detach', 'disk-snapshot-create', 'disk-snapshot-delete', 'terminate', 'terminate-hard', 'disk-resize', 'deploy', 'chown', 'chmod', 'updateconf', 'rename', 'resize', 'update', 'snapshot-resize', 'snapshot-delete', 'snapshot-revert', 'disk-saveas', 'disk-snapshot-revert', 'recover', 'retry', 'monitor', 'disk-snapshot-rename', 'alias-attach', 'alias-detach', 'poweroff-migrate', 'poweroff-hard-migrate', 'backup', 'nic-update', 'backup-cancel', 'sched-add', 'sched-update', 'sched-delete', 'sg-attach', 'sg-detach', 'pci-attach', 'pci-detach', 'restore', 'exec', 'exec-retry', 'exec-cancel' ]
Instance Attribute Summary
Attributes inherited from PoolElement
Class Method Summary collapse
-
.build_xml(pe_id = nil) ⇒ Object
Creates a VirtualMachine description with just its identifier this method should be used to create plain VirtualMachine objects.
- .get_history_action(action) ⇒ Object
Instance Method Summary collapse
-
#allocate(description, hold = false) ⇒ nil, OpenNebula::Error
Allocates a new VirtualMachine in OpenNebula.
-
#backup(ds_id = -1,, reset = false) ⇒ Integer, OpenNebula::Error
Generate a backup for the VM (backup config must be set).
-
#backup_cancel ⇒ nil, OpenNebula::Error
Cancel ongoing backup operation for the VM.
-
#chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) ⇒ nil, OpenNebula::Error
Changes the permissions.
-
#chmod_octet(octet) ⇒ nil, OpenNebula::Error
Changes the permissions.
-
#chown(uid, gid) ⇒ Object
- Changes the owner/group uid
-
Integer the new owner id.
-
#delete(recreate = false) ⇒ Object
Deletes a VM from the pool.
-
#deploy(host_id, enforce = false, ds_id = -1,, extra_template = '') ⇒ nil, OpenNebula::Error
Initiates the instance of the VM on the target host.
-
#deploy_id ⇒ Object
Returns the deploy_id of the VirtualMachine (numeric value).
-
#disk_attach(disk_template) ⇒ nil, OpenNebula::Error
(also: #attachdisk)
Attaches a disk to a running VM.
-
#disk_detach(disk_id) ⇒ nil, OpenNebula::Error
(also: #detachdisk)
Detaches a disk from a running VM.
-
#disk_resize(disk_id, size) ⇒ nil, OpenNebula::Error
Changes the size of a disk.
-
#disk_saveas(disk_id, image_name, image_type = '', snap_id = -1)) ⇒ Integer, OpenNebula::Error
Set the specified vm’s disk to be saved as a new image.
-
#disk_snapshot_create(disk_id, name) ⇒ Integer, OpenNebula::Error
Takes a new snapshot of a disk.
-
#disk_snapshot_delete(disk_id, snap_id) ⇒ nil, OpenNebula::Error
Deletes a disk snapshot.
-
#disk_snapshot_rename(disk_id, snap_id, new_name) ⇒ nil, OpenNebula::Error
Renames a disk snapshot.
-
#disk_snapshot_revert(disk_id, snap_id) ⇒ nil, OpenNebula::Error
Reverts disk state to a previously taken snapshot.
-
#exec(cmd, cmd_stdin) ⇒ nil, OpenNebula::Error
Execute a command in the VM.
-
#exec_cancel ⇒ nil, OpenNebula::Error
Cancel the command being executed in the VM.
-
#exec_retry ⇒ nil, OpenNebula::Error
Retry the last command executed in the VM.
- #get_history_record(seq) ⇒ Object
-
#gid ⇒ Object
Returns the group identifier [return] Integer the element’s group ID.
-
#hold ⇒ Object
Sets a VM to hold state, scheduler will not deploy it.
-
#info(decrypt = false) ⇒ Object
(also: #info!)
Retrieves the information of the given VirtualMachine.
-
#initialize(xml, client) ⇒ VirtualMachine
constructor
Class constructor.
-
#lcm_state ⇒ Object
Returns the LCM state of the VirtualMachine (numeric value).
-
#lcm_state_str ⇒ Object
Returns the LCM state of the VirtualMachine (string value).
-
#live_migrate(host_id, enforce = false) ⇒ Object
deprecated
Deprecated.
use #migrate instead
-
#migrate(host_id, live = false, enforce = false, ds_id = -1,, mtype = 0) ⇒ nil, OpenNebula::Error
Moves a running VM to the specified host.
-
#monitoring(xpath_expressions) ⇒ Hash<String, Array<Array<int>>>, OpenNebula::Error
Retrieves this VM’s monitoring data from OpenNebula.
-
#monitoring_xml ⇒ String
Retrieves this VM’s monitoring data from OpenNebula, in XML.
-
#nic_attach(nic_template) ⇒ nil, OpenNebula::Error
Attaches a NIC to a running VM.
-
#nic_detach(nic_id) ⇒ nil, OpenNebula::Error
Detaches a NIC from a running VM.
-
#nic_update(nic_id, nic_template, append = false) ⇒ nil, OpenNebula::Error
Updates a NIC for a running VM.
-
#pci_attach(pci) ⇒ nil, OpenNebula::Error
Attaches a PCI to a VM.
-
#pci_detach(pci_id) ⇒ nil, OpenNebula::Error
Detaches a PCI from a VM.
-
#poweroff(hard = false) ⇒ Object
Powers off a running VM.
-
#reboot(hard = false) ⇒ Object
Reboots an already deployed VM.
-
#recover(result) ⇒ nil, OpenNebula::Error
Recovers an ACTIVE VM.
-
#release ⇒ Object
Releases a VM from hold state.
-
#rename(name) ⇒ nil, OpenNebula::Error
Renames this VM.
- #replace(opts = {}) ⇒ Object
-
#resched ⇒ Object
Sets the re-scheduling flag for the VM.
-
#resize(capacity_template, enforce) ⇒ nil, OpenNebula::Error
Resize the VM.
-
#restore(img_id, inc_id, disk_id) ⇒ nil, OpenNebula::Error
Restore the VM from backup Image.
-
#resume ⇒ Object
Resumes the execution of a saved VM.
-
#sched_action_add(sched_template) ⇒ nil, OpenNebula::Error
Add sched actions.
-
#sched_action_delete(sched_id) ⇒ nil, OpenNebula::Error
Delete sched action.
-
#sched_action_update(sched_id, sched_template) ⇒ nil, OpenNebula::Error
Update sched_action.
-
#sg_attach(nic_id, sg_id) ⇒ nil, OpenNebula::Error
Attaches a Security Groupt to a running VM.
-
#sg_detach(nic_id, sg_id) ⇒ nil, OpenNebula::Error
Detaches a Security Group from a running VM.
-
#snapshot_create(name = '') ⇒ Integer, OpenNebula::Error
Creates a new VM snapshot.
-
#snapshot_delete(snap_id) ⇒ nil, OpenNebula::Error
Deletes a VM snapshot.
-
#snapshot_revert(snap_id) ⇒ nil, OpenNebula::Error
Reverts to a snapshot.
-
#state ⇒ Object
Returns the VM state of the VirtualMachine (numeric value).
-
#state_str ⇒ Object
Returns the VM state of the VirtualMachine (string value).
-
#status ⇒ Object
Returns the short status string for the VirtualMachine.
-
#stop ⇒ Object
Stops a running VM.
-
#suspend ⇒ Object
Saves a running VM.
-
#terminate(hard = false) ⇒ Object
(also: #shutdown)
Shutdowns an already deployed VM.
-
#undeploy(hard = false) ⇒ Object
Shuts down an already deployed VM, saving its state in the system DS.
-
#unresched ⇒ Object
Unsets the re-scheduling flag for the VM.
-
#update(new_template = nil, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents.
-
#updateconf(new_conf, append = false) ⇒ nil, OpenNebula::Error
Changes the attributes of a VM in power off, failure and undeploy states.
-
#user_template_str(indent = true) ⇒ String
Returns the <USER_TEMPLATE> element in text form.
-
#user_template_xml ⇒ String
Returns the <USER_TEMPLATE> element in XML form.
- #wait_state(state, timeout = 120) ⇒ Object
- #wait_state2(state, lcm_state, timeout = 120) ⇒ Object
Methods inherited from PoolElement
Methods inherited from XMLElement
#[], #add_element, #attr, #delete_element, #each, #each_xpath, #element_xml, #has_elements?, #initialize_xml, #name, #retrieve_elements, #retrieve_xmlelements, #set_content, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml, #xml_nil?
Constructor Details
#initialize(xml, client) ⇒ VirtualMachine
Class constructor
351 352 353 354 355 |
# File 'lib/opennebula/virtual_machine.rb', line 351 def initialize(xml, client) LockableExt.make_lockable(self, VM_METHODS) super(xml, client) end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
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:
vm = VirtualMachine.new(VirtualMachine.build_xml(3),rpc_client)
336 337 338 339 340 341 342 343 344 |
# File 'lib/opennebula/virtual_machine.rb', line 336 def self.build_xml(pe_id = nil) if pe_id vm_xml = "<VM><ID>#{pe_id}</ID></VM>" else vm_xml = '<VM></VM>' end XMLElement.build_xml(vm_xml, 'VM') end |
.get_history_action(action) ⇒ Object
346 347 348 |
# File 'lib/opennebula/virtual_machine.rb', line 346 def self.get_history_action(action) HISTORY_ACTION[action.to_i] end |
Instance Method Details
#allocate(description, hold = false) ⇒ nil, OpenNebula::Error
Allocates a new VirtualMachine in OpenNebula
377 378 379 |
# File 'lib/opennebula/virtual_machine.rb', line 377 def allocate(description, hold = false) super(VM_METHODS[:allocate], description, hold) end |
#backup(ds_id = -1,, reset = false) ⇒ Integer, OpenNebula::Error
Generate a backup for the VM (backup config must be set)
865 866 867 |
# File 'lib/opennebula/virtual_machine.rb', line 865 def backup(ds_id = -1, reset = false) @client.call(VM_METHODS[:backup], @pe_id, ds_id, reset) end |
#backup_cancel ⇒ nil, OpenNebula::Error
Cancel ongoing backup operation for the VM
873 874 875 |
# File 'lib/opennebula/virtual_machine.rb', line 873 def backup_cancel @client.call(VM_METHODS[:backupcancel], @pe_id) end |
#chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) ⇒ nil, OpenNebula::Error
Changes the permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
661 662 663 664 665 |
# File 'lib/opennebula/virtual_machine.rb', line 661 def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) super(VM_METHODS[:chmod], owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) end |
#chmod_octet(octet) ⇒ nil, OpenNebula::Error
Changes the permissions.
652 653 654 |
# File 'lib/opennebula/virtual_machine.rb', line 652 def chmod_octet(octet) super(VM_METHODS[:chmod], octet) end |
#chown(uid, gid) ⇒ Object
Changes the owner/group
- uid
-
Integer the new owner id. Set to -1 to leave the current one
- gid
-
Integer the new group id. Set to -1 to leave the current one
- return
-
nil in case of success or an Error object
643 644 645 |
# File 'lib/opennebula/virtual_machine.rb', line 643 def chown(uid, gid) super(VM_METHODS[:chown], uid, gid) end |
#delete(recreate = false) ⇒ Object
Deletes a VM from the pool
806 807 808 809 810 811 812 |
# File 'lib/opennebula/virtual_machine.rb', line 806 def delete(recreate = false) if recreate recover(4) else recover(3) end end |
#deploy(host_id, enforce = false, ds_id = -1,, extra_template = '') ⇒ nil, OpenNebula::Error
Initiates the instance of the VM on the target host.
429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/opennebula/virtual_machine.rb', line 429 def deploy(host_id, enforce = false, ds_id = -1, extra_template = '') enforce ||= false ds_id ||= -1 extra_template ||= '' info call(VM_METHODS[:deploy], @pe_id, host_id.to_i, enforce, ds_id.to_i, extra_template) end |
#deploy_id ⇒ Object
Returns the deploy_id of the VirtualMachine (numeric value)
971 972 973 |
# File 'lib/opennebula/virtual_machine.rb', line 971 def deploy_id self['DEPLOY_ID'] end |
#disk_attach(disk_template) ⇒ nil, OpenNebula::Error Also known as: attachdisk
Attaches a disk to a running VM
496 497 498 |
# File 'lib/opennebula/virtual_machine.rb', line 496 def disk_attach(disk_template) call(VM_METHODS[:attach], @pe_id, disk_template) end |
#disk_detach(disk_id) ⇒ nil, OpenNebula::Error Also known as: detachdisk
Detaches a disk from a running VM
507 508 509 |
# File 'lib/opennebula/virtual_machine.rb', line 507 def disk_detach(disk_id) call(VM_METHODS[:detach], @pe_id, disk_id) end |
#disk_resize(disk_id, size) ⇒ nil, OpenNebula::Error
Changes the size of a disk
790 791 792 |
# File 'lib/opennebula/virtual_machine.rb', line 790 def disk_resize(disk_id, size) call(VM_METHODS[:diskresize], @pe_id, disk_id, size.to_s) end |
#disk_saveas(disk_id, image_name, image_type = '', snap_id = -1)) ⇒ Integer, OpenNebula::Error
Set the specified vm’s disk to be saved as a new image
current disk image state
613 614 615 616 617 618 619 620 621 622 |
# File 'lib/opennebula/virtual_machine.rb', line 613 def disk_saveas(disk_id, image_name, image_type = '', snap_id = -1) return Error.new('ID not defined') unless @pe_id @client.call(VM_METHODS[:disksaveas], @pe_id, disk_id, image_name, image_type, snap_id) end |
#disk_snapshot_create(disk_id, name) ⇒ Integer, OpenNebula::Error
Takes a new snapshot of a disk
746 747 748 |
# File 'lib/opennebula/virtual_machine.rb', line 746 def disk_snapshot_create(disk_id, name) call(VM_METHODS[:disksnapshotcreate], @pe_id, disk_id, name) end |
#disk_snapshot_delete(disk_id, snap_id) ⇒ nil, OpenNebula::Error
Deletes a disk snapshot
768 769 770 |
# File 'lib/opennebula/virtual_machine.rb', line 768 def disk_snapshot_delete(disk_id, snap_id) call(VM_METHODS[:disksnapshotdelete], @pe_id, disk_id, snap_id) end |
#disk_snapshot_rename(disk_id, snap_id, new_name) ⇒ nil, OpenNebula::Error
Renames a disk snapshot
780 781 782 |
# File 'lib/opennebula/virtual_machine.rb', line 780 def disk_snapshot_rename(disk_id, snap_id, new_name) call(VM_METHODS[:disksnapshotrename], @pe_id, disk_id, snap_id, new_name) end |
#disk_snapshot_revert(disk_id, snap_id) ⇒ nil, OpenNebula::Error
Reverts disk state to a previously taken snapshot
757 758 759 |
# File 'lib/opennebula/virtual_machine.rb', line 757 def disk_snapshot_revert(disk_id, snap_id) call(VM_METHODS[:disksnapshotrevert], @pe_id, disk_id, snap_id) end |
#exec(cmd, cmd_stdin) ⇒ nil, OpenNebula::Error
Execute a command in the VM
909 910 911 |
# File 'lib/opennebula/virtual_machine.rb', line 909 def exec(cmd, cmd_stdin) @client.call(VM_METHODS[:exec], @pe_id, cmd, cmd_stdin) end |
#exec_cancel ⇒ nil, OpenNebula::Error
Cancel the command being executed in the VM
925 926 927 |
# File 'lib/opennebula/virtual_machine.rb', line 925 def exec_cancel @client.call(VM_METHODS[:cancelexec], @pe_id) end |
#exec_retry ⇒ nil, OpenNebula::Error
Retry the last command executed in the VM
917 918 919 |
# File 'lib/opennebula/virtual_machine.rb', line 917 def exec_retry @client.call(VM_METHODS[:retryexec], @pe_id) end |
#get_history_record(seq) ⇒ Object
975 976 977 |
# File 'lib/opennebula/virtual_machine.rb', line 975 def get_history_record(seq) retrieve_xmlelements('//HISTORY')[seq].to_xml end |
#gid ⇒ Object
Returns the group identifier
- return
-
Integer the element’s group ID
966 967 968 |
# File 'lib/opennebula/virtual_machine.rb', line 966 def gid self['GID'].to_i end |
#hold ⇒ Object
Sets a VM to hold state, scheduler will not deploy it
467 468 469 |
# File 'lib/opennebula/virtual_machine.rb', line 467 def hold action('hold') end |
#info(decrypt = false) ⇒ Object Also known as: info!
Retrieves the information of the given VirtualMachine.
362 363 364 |
# File 'lib/opennebula/virtual_machine.rb', line 362 def info(decrypt = false) super(VM_METHODS[:info], 'VM', decrypt) end |
#lcm_state ⇒ Object
Returns the LCM state of the VirtualMachine (numeric value)
944 945 946 |
# File 'lib/opennebula/virtual_machine.rb', line 944 def lcm_state self['LCM_STATE'].to_i end |
#lcm_state_str ⇒ Object
Returns the LCM state of the VirtualMachine (string value)
949 950 951 |
# File 'lib/opennebula/virtual_machine.rb', line 949 def lcm_state_str LCM_STATE[lcm_state] end |
#live_migrate(host_id, enforce = false) ⇒ Object
use #migrate instead
597 598 599 |
# File 'lib/opennebula/virtual_machine.rb', line 597 def live_migrate(host_id, enforce = false) migrate(host_id, true, enforce) end |
#migrate(host_id, live = false, enforce = false, ds_id = -1,, mtype = 0) ⇒ nil, OpenNebula::Error
Moves a running VM to the specified host. With live=true the migration is done withdout downtime.
591 592 593 594 |
# File 'lib/opennebula/virtual_machine.rb', line 591 def migrate(host_id, live = false, enforce = false, ds_id = -1, mtype = 0) call(VM_METHODS[:migrate], @pe_id, host_id.to_i, live==true, enforce, ds_id.to_i, mtype) end |
#monitoring(xpath_expressions) ⇒ Hash<String, Array<Array<int>>>, OpenNebula::Error
Retrieves this VM’s monitoring data from OpenNebula
684 685 686 |
# File 'lib/opennebula/virtual_machine.rb', line 684 def monitoring(xpath_expressions) super(VM_METHODS[:monitoring], xpath_expressions) end |
#monitoring_xml ⇒ String
Retrieves this VM’s monitoring data from OpenNebula, in XML
691 692 693 694 695 |
# File 'lib/opennebula/virtual_machine.rb', line 691 def monitoring_xml return Error.new('ID not defined') unless @pe_id @client.call(VM_METHODS[:monitoring], @pe_id) end |
#nic_attach(nic_template) ⇒ nil, OpenNebula::Error
Attaches a NIC to a running VM
518 519 520 |
# File 'lib/opennebula/virtual_machine.rb', line 518 def nic_attach(nic_template) call(VM_METHODS[:attachnic], @pe_id, nic_template) end |
#nic_detach(nic_id) ⇒ nil, OpenNebula::Error
Detaches a NIC from a running VM
527 528 529 |
# File 'lib/opennebula/virtual_machine.rb', line 527 def nic_detach(nic_id) call(VM_METHODS[:detachnic], @pe_id, nic_id) end |
#nic_update(nic_id, nic_template, append = false) ⇒ nil, OpenNebula::Error
Updates a NIC for a running VM
539 540 541 |
# File 'lib/opennebula/virtual_machine.rb', line 539 def nic_update(nic_id, nic_template, append = false) call(VM_METHODS[:updatenic], @pe_id, nic_id, nic_template, append ? 1 : 0) end |
#pci_attach(pci) ⇒ nil, OpenNebula::Error
Attaches a PCI to a VM
882 883 884 |
# File 'lib/opennebula/virtual_machine.rb', line 882 def pci_attach(pci) call(VM_METHODS[:attachpci], @pe_id, pci) end |
#pci_detach(pci_id) ⇒ nil, OpenNebula::Error
Detaches a PCI from a VM
891 892 893 |
# File 'lib/opennebula/virtual_machine.rb', line 891 def pci_detach(pci_id) call(VM_METHODS[:detachpci], @pe_id, pci_id) end |
#poweroff(hard = false) ⇒ Object
Powers off a running VM
457 458 459 |
# File 'lib/opennebula/virtual_machine.rb', line 457 def poweroff(hard = false) action(hard ? 'poweroff-hard' : 'poweroff') end |
#reboot(hard = false) ⇒ Object
Reboots an already deployed VM
462 463 464 |
# File 'lib/opennebula/virtual_machine.rb', line 462 def reboot(hard = false) action(hard ? 'reboot-hard' : 'reboot') end |
#recover(result) ⇒ nil, OpenNebula::Error
Recovers an ACTIVE VM
retry (2), delete (3), delete-recreate (4), delete-db (5)
801 802 803 |
# File 'lib/opennebula/virtual_machine.rb', line 801 def recover(result) call(VM_METHODS[:recover], @pe_id, result) end |
#release ⇒ Object
Releases a VM from hold state
472 473 474 |
# File 'lib/opennebula/virtual_machine.rb', line 472 def release action('release') end |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this VM
703 704 705 |
# File 'lib/opennebula/virtual_machine.rb', line 703 def rename(name) call(VM_METHODS[:rename], @pe_id, name) end |
#replace(opts = {}) ⇒ Object
413 414 415 |
# File 'lib/opennebula/virtual_machine.rb', line 413 def replace(opts = {}) super(opts, 'USER_TEMPLATE') end |
#resched ⇒ Object
Sets the re-scheduling flag for the VM
563 564 565 |
# File 'lib/opennebula/virtual_machine.rb', line 563 def resched action('resched') end |
#resize(capacity_template, enforce) ⇒ nil, OpenNebula::Error
Resize the VM
635 636 637 |
# File 'lib/opennebula/virtual_machine.rb', line 635 def resize(capacity_template, enforce) call(VM_METHODS[:resize], @pe_id, capacity_template, enforce) end |
#restore(img_id, inc_id, disk_id) ⇒ nil, OpenNebula::Error
Restore the VM from backup Image
899 900 901 |
# File 'lib/opennebula/virtual_machine.rb', line 899 def restore(img_id, inc_id, disk_id) @client.call(VM_METHODS[:restore], @pe_id, img_id, inc_id, disk_id) end |
#resume ⇒ Object
Resumes the execution of a saved VM
487 488 489 |
# File 'lib/opennebula/virtual_machine.rb', line 487 def resume action('resume') end |
#sched_action_add(sched_template) ⇒ nil, OpenNebula::Error
Add sched actions
836 837 838 |
# File 'lib/opennebula/virtual_machine.rb', line 836 def sched_action_add(sched_template) call(VM_METHODS[:schedadd], @pe_id, sched_template) end |
#sched_action_delete(sched_id) ⇒ nil, OpenNebula::Error
Delete sched action
845 846 847 |
# File 'lib/opennebula/virtual_machine.rb', line 845 def sched_action_delete(sched_id) call(VM_METHODS[:scheddelete], @pe_id, sched_id.to_i) end |
#sched_action_update(sched_id, sched_template) ⇒ nil, OpenNebula::Error
Update sched_action
855 856 857 858 |
# File 'lib/opennebula/virtual_machine.rb', line 855 def sched_action_update(sched_id, sched_template) call(VM_METHODS[:schedupdate], @pe_id, sched_id.to_i, sched_template) end |
#sg_attach(nic_id, sg_id) ⇒ nil, OpenNebula::Error
Attaches a Security Groupt to a running VM
549 550 551 |
# File 'lib/opennebula/virtual_machine.rb', line 549 def sg_attach(nic_id, sg_id) call(VM_METHODS[:attachsg], @pe_id, nic_id, sg_id) end |
#sg_detach(nic_id, sg_id) ⇒ nil, OpenNebula::Error
Detaches a Security Group from a running VM
558 559 560 |
# File 'lib/opennebula/virtual_machine.rb', line 558 def sg_detach(nic_id, sg_id) call(VM_METHODS[:detachsg], @pe_id, nic_id, sg_id) end |
#snapshot_create(name = '') ⇒ Integer, OpenNebula::Error
Creates a new VM snapshot
713 714 715 716 717 718 |
# File 'lib/opennebula/virtual_machine.rb', line 713 def snapshot_create(name = '') return Error.new('ID not defined') unless @pe_id name ||= '' @client.call(VM_METHODS[:snapshotcreate], @pe_id, name) end |
#snapshot_delete(snap_id) ⇒ nil, OpenNebula::Error
Deletes a VM snapshot
736 737 738 |
# File 'lib/opennebula/virtual_machine.rb', line 736 def snapshot_delete(snap_id) call(VM_METHODS[:snapshotdelete], @pe_id, snap_id) end |
#snapshot_revert(snap_id) ⇒ nil, OpenNebula::Error
Reverts to a snapshot
726 727 728 |
# File 'lib/opennebula/virtual_machine.rb', line 726 def snapshot_revert(snap_id) call(VM_METHODS[:snapshotrevert], @pe_id, snap_id) end |
#state ⇒ Object
Returns the VM state of the VirtualMachine (numeric value)
934 935 936 |
# File 'lib/opennebula/virtual_machine.rb', line 934 def state self['STATE'].to_i end |
#state_str ⇒ Object
Returns the VM state of the VirtualMachine (string value)
939 940 941 |
# File 'lib/opennebula/virtual_machine.rb', line 939 def state_str VM_STATE[state] end |
#status ⇒ Object
Returns the short status string for the VirtualMachine
954 955 956 957 958 959 960 961 962 |
# File 'lib/opennebula/virtual_machine.rb', line 954 def status short_state_str=SHORT_VM_STATES[state_str] if short_state_str=='actv' short_state_str=SHORT_LCM_STATES[lcm_state_str] end short_state_str end |
#stop ⇒ Object
Stops a running VM
477 478 479 |
# File 'lib/opennebula/virtual_machine.rb', line 477 def stop action('stop') end |
#suspend ⇒ Object
Saves a running VM
482 483 484 |
# File 'lib/opennebula/virtual_machine.rb', line 482 def suspend action('suspend') end |
#terminate(hard = false) ⇒ Object Also known as: shutdown
Shutdowns an already deployed VM
445 446 447 |
# File 'lib/opennebula/virtual_machine.rb', line 445 def terminate(hard = false) action(hard ? 'terminate-hard' : 'terminate') end |
#undeploy(hard = false) ⇒ Object
Shuts down an already deployed VM, saving its state in the system DS
452 453 454 |
# File 'lib/opennebula/virtual_machine.rb', line 452 def undeploy(hard = false) action(hard ? 'undeploy-hard' : 'undeploy') end |
#unresched ⇒ Object
Unsets the re-scheduling flag for the VM
568 569 570 |
# File 'lib/opennebula/virtual_machine.rb', line 568 def unresched action('unresched') end |
#update(new_template = nil, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents
389 390 391 |
# File 'lib/opennebula/virtual_machine.rb', line 389 def update(new_template = nil, append = false) super(VM_METHODS[:update], new_template, append ? 1 : 0) end |
#updateconf(new_conf, append = false) ⇒ nil, OpenNebula::Error
Changes the attributes of a VM in power off, failure and undeploy
states
827 828 829 |
# File 'lib/opennebula/virtual_machine.rb', line 827 def updateconf(new_conf, append = false) call(VM_METHODS[:updateconf], @pe_id, new_conf, append ? 1 : 0) end |
#user_template_str(indent = true) ⇒ String
Returns the <USER_TEMPLATE> element in text form
398 399 400 |
# File 'lib/opennebula/virtual_machine.rb', line 398 def user_template_str(indent = true) template_like_str('USER_TEMPLATE', indent) end |
#user_template_xml ⇒ String
Returns the <USER_TEMPLATE> element in XML form
405 406 407 408 409 410 411 |
# File 'lib/opennebula/virtual_machine.rb', line 405 def user_template_xml if NOKOGIRI @xml.xpath('USER_TEMPLATE').to_s else @xml.elements['USER_TEMPLATE'].to_s end end |
#wait_state(state, timeout = 120) ⇒ Object
979 980 981 982 983 984 985 986 987 988 989 |
# File 'lib/opennebula/virtual_machine.rb', line 979 def wait_state(state, timeout = 120) require 'opennebula/wait_ext' extend OpenNebula::WaitExt rc = wait2(state, 'LCM_INIT', timeout) return Error.new("Timeout expired for state #{state}.") unless rc true end |
#wait_state2(state, lcm_state, timeout = 120) ⇒ Object
991 992 993 994 995 996 997 998 999 |
# File 'lib/opennebula/virtual_machine.rb', line 991 def wait_state2(state, lcm_state, timeout = 120) extend OpenNebula::WaitExt rc = wait2(state, lcm_state, timeout) return Error.new("Timeout expired for state #{state}.") unless rc true end |