class OpenNebula::VirtualMachine

Constants

EXTERNAL_IP_ATTRS
HISTORY_ACTION
LCM_STATE
REMOVE_IMAGE_ATTRS
REMOVE_VNET_ATTRS

Clones the VM's source Template, replacing the disks with live snapshots of the current disks. The VM capacity and NICs are also preserved

@param name [String] Name for the new Template @param name [true,false,nil] Optional, true to make the saved images persistent, false make them non-persistent

@return [Integer, OpenNebula::Error] the new Template ID in case of

success, error otherwise
SHORT_LCM_STATES
SHORT_VM_STATES
VM_METHODS

Constants and Class Methods

VM_STATE

Public Class Methods

build_xml(pe_id=nil) click to toggle source

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 lib/opennebula/virtual_machine.rb, line 256
def VirtualMachine.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) click to toggle source
# File lib/opennebula/virtual_machine.rb, line 266
def VirtualMachine.get_history_action(action)
    return HISTORY_ACTION[action.to_i]
end
new(xml, client) click to toggle source

Class constructor

Calls superclass method OpenNebula::PoolElement::new
# File lib/opennebula/virtual_machine.rb, line 271
def initialize(xml, client)
    super(xml,client)
end

Public Instance Methods

allocate(description, hold=false) click to toggle source

Allocates a new VirtualMachine in OpenNebula

@param description [String] A string containing the template of

the VirtualMachine.

@param hold [true,false] false to create the VM in pending state,

true to create it on hold

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
Calls superclass method OpenNebula::PoolElement#allocate
# File lib/opennebula/virtual_machine.rb, line 295
def allocate(description, hold=false)
    super(VM_METHODS[:allocate], description, hold)
end
attachdisk(disk_template)
Alias for: disk_attach
chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) click to toggle source

Changes the permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
Calls superclass method OpenNebula::PoolElement#chmod
# File lib/opennebula/virtual_machine.rb, line 549
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) click to toggle source

Changes the permissions.

@param octet [String] Permissions octed , e.g. 640 @return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
Calls superclass method OpenNebula::PoolElement#chmod_octet
# File lib/opennebula/virtual_machine.rb, line 540
def chmod_octet(octet)
    super(VM_METHODS[:chmod], octet)
end
chown(uid, gid) click to toggle source

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

Calls superclass method OpenNebula::PoolElement#chown
# File lib/opennebula/virtual_machine.rb, line 531
def chown(uid, gid)
    super(VM_METHODS[:chown], uid, gid)
end
delete(recreate=false) click to toggle source

Deletes a VM from the pool

# File lib/opennebula/virtual_machine.rb, line 695
def delete(recreate=false)
    if recreate
        recover(4)
    else
        recover(3)
    end
end
deploy(host_id, enforce=false, ds_id=-1, extra_template="") click to toggle source

Initiates the instance of the VM on the target host.

@param host_id [Interger] The host id (hid) of the target host where

the VM will be instantiated.

@param enforce [true|false] If it is set to true, the host capacity

will be checked, and the deployment will fail if the host is
overcommited. Defaults to false

@param ds_id [Integer] The System Datastore where to deploy the VM. To

use the default, set it to -1

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/virtual_machine.rb, line 347
def deploy(host_id, enforce=false, ds_id=-1, extra_template="")
    enforce ||= false
    ds_id ||= -1
    extra_template ||= ""

    self.info

    return call(VM_METHODS[:deploy],
                @pe_id,
                host_id.to_i,
                enforce,
                ds_id.to_i,
                extra_template)
end
deploy_id() click to toggle source

Returns the deploy_id of the VirtualMachine (numeric value)

# File lib/opennebula/virtual_machine.rb, line 769
def deploy_id
    self['DEPLOY_ID']
end
detachdisk(disk_id)
Alias for: disk_detach
disk_attach(disk_template) click to toggle source

Attaches a disk to a running VM

@param disk_template [String] Template containing a DISK element @return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/virtual_machine.rb, line 414
def disk_attach(disk_template)
    return call(VM_METHODS[:attach], @pe_id, disk_template)
end
Also aliased as: attachdisk
disk_detach(disk_id) click to toggle source

Detaches a disk from a running VM

@param disk_id [Integer] Id of the disk to be detached @return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/virtual_machine.rb, line 425
def disk_detach(disk_id)
    return call(VM_METHODS[:detach], @pe_id, disk_id)
end
Also aliased as: detachdisk
disk_resize(disk_id, size) click to toggle source

Changes the size of a disk

@param disk_id [Integer] Id of the disk @param size [Integer] new size in MiB

@return [nil, OpenNebula::Error] nil in case of success or error

# File lib/opennebula/virtual_machine.rb, line 679
def disk_resize(disk_id, size)
    return call(VM_METHODS[:diskresize], @pe_id, disk_id, size.to_s)
end
disk_saveas(disk_id, image_name, image_type="", snap_id=-1) click to toggle source

Set the specified vm's disk to be saved as a new image

@param disk_id [Integer] ID of the disk to be saved @param image_name [String] Name for the new image where the

disk will be saved

@param image_type [String] Type of the new image. Set to empty string

to use the default type

@param snap_id [Integer] ID of the snapshot to save, -1 to use the current disk image state

@return [Integer, OpenNebula::Error] the new Image ID in case of

success, error otherwise
# File lib/opennebula/virtual_machine.rb, line 500
def disk_saveas(disk_id, image_name, image_type="", snap_id=-1)
    return Error.new('ID not defined') if !@pe_id

    rc = @client.call(VM_METHODS[:disksaveas],
                      @pe_id,
                      disk_id,
                      image_name,
                      image_type,
                      snap_id)
    return rc
end
disk_snapshot_create(disk_id, name) click to toggle source

Takes a new snapshot of a disk

@param disk_id [Integer] Id of the disk @param name [String] description for the snapshot

@return [Integer, OpenNebula::Error] The new snapshot ID or error

# File lib/opennebula/virtual_machine.rb, line 635
def disk_snapshot_create(disk_id, name)
  return call(VM_METHODS[:disksnapshotcreate], @pe_id, disk_id, name)
end
disk_snapshot_delete(disk_id, snap_id) click to toggle source

Deletes a disk snapshot

@param disk_id [Integer] Id of the disk @param snap_id [Integer] Id of the snapshot

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/virtual_machine.rb, line 657
def disk_snapshot_delete(disk_id, snap_id)
  return call(VM_METHODS[:disksnapshotdelete], @pe_id, disk_id, snap_id)
end
disk_snapshot_rename(disk_id, snap_id, new_name) click to toggle source

Renames a disk snapshot

@param disk_id [Integer] Id of the disk @param snap_id [Integer] Id of the snapshot @param new_name [String] New name for the snapshot

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/virtual_machine.rb, line 669
def disk_snapshot_rename(disk_id, snap_id, new_name)
    return call(VM_METHODS[:disksnapshotrename], @pe_id, disk_id, snap_id, new_name)
end
disk_snapshot_revert(disk_id, snap_id) click to toggle source

Reverts disk state to a previously taken snapshot

@param disk_id [Integer] Id of the disk @param snap_id [Integer] Id of the snapshot

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/virtual_machine.rb, line 646
def disk_snapshot_revert(disk_id, snap_id)
  return call(VM_METHODS[:disksnapshotrevert], @pe_id, disk_id, snap_id)
end
gid() click to toggle source

Returns the group identifier

return

Integer the element's group ID

# File lib/opennebula/virtual_machine.rb, line 764
def gid
    self['GID'].to_i
end
hold() click to toggle source

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

# File lib/opennebula/virtual_machine.rb, line 385
def hold
    action('hold')
end
info() click to toggle source

Retrieves the information of the given VirtualMachine.

Calls superclass method OpenNebula::PoolElement#info
# File lib/opennebula/virtual_machine.rb, line 280
def info()
    super(VM_METHODS[:info], 'VM')
end
Also aliased as: info!
info!()
Alias for: info
lcm_state() click to toggle source

Returns the LCM state of the VirtualMachine (numeric value)

# File lib/opennebula/virtual_machine.rb, line 742
def lcm_state
    self['LCM_STATE'].to_i
end
lcm_state_str() click to toggle source

Returns the LCM state of the VirtualMachine (string value)

# File lib/opennebula/virtual_machine.rb, line 747
def lcm_state_str
    LCM_STATE[lcm_state]
end
live_migrate(host_id, enforce=false) click to toggle source

@deprecated use {#migrate} instead

# File lib/opennebula/virtual_machine.rb, line 484
def live_migrate(host_id, enforce=false)
    migrate(host_id, true, enforce)
end
lock(level) click to toggle source

Lock a VM

# File lib/opennebula/virtual_machine.rb, line 718
def lock(level)
    return call(VM_METHODS[:lock], @pe_id, level)
end
migrate(host_id, live=false, enforce=false, ds_id=-1, mtype=0) click to toggle source

Moves a running VM to the specified host. With live=true the migration is done withdout downtime.

@param host_id [Interger] The host id (hid) of the target host where

the VM will be migrated.

@param live [true|false] If true the migration is done without

downtime. Defaults to false

@param enforce [true|false] If it is set to true, the host capacity

will be checked, and the deployment will fail if the host is
overcommited. Defaults to false

@param ds_id [Integer] The System Datastore where to migrate the VM.

To use the current one, set it to -1

@param mtype [Integer] How to perform the cold migration:

- 0: save - restore,
- 1: power off - boot
- 2: power off hard - boot

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/virtual_machine.rb, line 478
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) click to toggle source

Retrieves this VM's monitoring data from OpenNebula

@param [Array<String>] xpath_expressions Elements to retrieve.

@return [Hash<String, Array<Array<int>>>, OpenNebula::Error] Hash with

the requested xpath expressions, and an Array of 'timestamp, value'.

@example

vm.monitoring( ['MONITORING/CPU', 'MONITORING/NETTX'] )

{
 "MONITORING/CPU"=>[["1435085098", "47"], ["1435085253", "5"],
   ["1435085410", "48"], ["1435085566", "3"], ["1435088136", "2"]],
 "MONITORING/NETTX"=>[["1435085098", "0"], ["1435085253", "50"],
   ["1435085410", "50"], ["1435085566", "50"], ["1435085723", "50"]]
}
Calls superclass method OpenNebula::PoolElement#monitoring
# File lib/opennebula/virtual_machine.rb, line 572
def monitoring(xpath_expressions)
    return super(VM_METHODS[:monitoring], 'VM',
        'LAST_POLL', xpath_expressions)
end
monitoring_xml() click to toggle source

Retrieves this VM's monitoring data from OpenNebula, in XML

@return [String] VM monitoring data, in XML

# File lib/opennebula/virtual_machine.rb, line 580
def monitoring_xml()
    return Error.new('ID not defined') if !@pe_id

    return @client.call(VM_METHODS[:monitoring], @pe_id)
end
nic_attach(nic_template) click to toggle source

Attaches a NIC to a running VM

@param nic_template [String] Template containing a NIC element @return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/virtual_machine.rb, line 436
def nic_attach(nic_template)
    return call(VM_METHODS[:attachnic], @pe_id, nic_template)
end
nic_detach(nic_id) click to toggle source

Detaches a NIC from a running VM

@param nic_id [Integer] Id of the NIC to be detached @return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/virtual_machine.rb, line 445
def nic_detach(nic_id)
    return call(VM_METHODS[:detachnic], @pe_id, nic_id)
end
poweroff(hard=false) click to toggle source

Powers off a running VM

# File lib/opennebula/virtual_machine.rb, line 375
def poweroff(hard=false)
    action(hard ? 'poweroff-hard' : 'poweroff')
end
reboot(hard=false) click to toggle source

Reboots an already deployed VM

# File lib/opennebula/virtual_machine.rb, line 380
def reboot(hard=false)
    action(hard ? 'reboot-hard' : 'reboot')
end
recover(result) click to toggle source

Recovers an ACTIVE VM

@param result [Integer] Recover with failure (0), success (1), retry (2), delete (3), delete-recreate (4), delete-db (5) @param result [info] Additional information needed to recover the VM @return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/virtual_machine.rb, line 690
def recover(result)
    return call(VM_METHODS[:recover], @pe_id, result)
end
release() click to toggle source

Releases a VM from hold state

# File lib/opennebula/virtual_machine.rb, line 390
def release
    action('release')
end
rename(name) click to toggle source

Renames this VM

@param name [String] New name for the VM.

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/virtual_machine.rb, line 592
def rename(name)
    return call(VM_METHODS[:rename], @pe_id, name)
end
replace(opts = {}) click to toggle source
Calls superclass method OpenNebula::PoolElement#replace
# File lib/opennebula/virtual_machine.rb, line 331
def replace(opts = {})
    super(opts, "USER_TEMPLATE")
end
resched() click to toggle source

Sets the re-scheduling flag for the VM

# File lib/opennebula/virtual_machine.rb, line 450
def resched
    action('resched')
end
resize(capacity_template, enforce) click to toggle source

Resize the VM

@param capacity_template [String] Template containing the new capacity

elements CPU, VCPU, MEMORY. If one of them is not present, or its
value is 0, it will not be resized

@param enforce [true|false] If it is set to true, the host capacity

will be checked. This will only affect oneadmin requests, regular users
resize requests will always be enforced

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/virtual_machine.rb, line 523
def resize(capacity_template, enforce)
    return call(VM_METHODS[:resize], @pe_id, capacity_template, enforce)
end
resume() click to toggle source

Resumes the execution of a saved VM

# File lib/opennebula/virtual_machine.rb, line 405
def resume
    action('resume')
end
save_as_template(name,description, persistent=nil) click to toggle source
# File lib/opennebula/virtual_machine.rb, line 791
def save_as_template(name,description, persistent=nil)
    img_ids = []
    new_tid = nil
    begin
        rc = info()
        raise if OpenNebula.is_error?(rc)

        tid = self['TEMPLATE/TEMPLATE_ID']
        if tid.nil? || tid.empty?
            rc = Error.new('VM has no template to be saved')
            raise
        end

        if state_str() != "POWEROFF"
            rc = Error.new("VM state must be POWEROFF, "<<
                "current state is #{state_str()}, #{lcm_state_str()}")
            raise
        end

        # Clone the source template
        rc = OpenNebula::Template.new_with_id(tid, @client).clone(name)
        raise if OpenNebula.is_error?(rc)

        new_tid = rc

        # Replace the original template's capacity with the actual VM values
        replace = ""
        if !description.nil?
            replace << "DESCRIPTION = #{description}\n"
        end
        cpu = self['TEMPLATE/CPU']
        if !cpu.nil? && !cpu.empty?
            replace << "CPU = #{cpu}\n"
        end

        vcpu = self['TEMPLATE/VCPU']
        if !vcpu.nil? && !vcpu.empty?
            replace << "VCPU = #{vcpu}\n"
        end

        mem = self['TEMPLATE/MEMORY']
        if !mem.nil? && !mem.empty?
            replace << "MEMORY = #{mem}\n"
        end

        self.each('TEMPLATE/DISK') do |disk|
            # While the previous snapshot is still in progress, we wait
            # indefinitely
            rc = info()
            raise if OpenNebula.is_error?(rc)

            steps = 0
            while lcm_state_str() == "HOTPLUG_SAVEAS_POWEROFF"
                if steps < 30
                    sleep 1
                else
                    sleep 15
                end

                rc = info()
                raise if OpenNebula.is_error?(rc)

                steps += 1
            end

            # If the VM is not busy with a previous disk snapshot, we wait
            # but this time with a timeout
            rc = wait_state("POWEROFF")
            raise if OpenNebula.is_error?(rc)

            disk_id = disk["DISK_ID"]
            if disk_id.nil? || disk_id.empty?
                rc = Error.new('The DISK_ID is missing from the VM template')
                raise
            end

            image_id           = disk["IMAGE_ID"]
            opennebula_managed = disk["OPENNEBULA_MANAGED"]
            type               = disk["TYPE"]

            REMOVE_IMAGE_ATTRS.each do |attr|
                disk.delete_element(attr)
            end

            if !image_id.nil? && !image_id.empty?
                if type == 'CDROM'
                    replace << "DISK = [ IMAGE_ID = #{image_id}"
                    if opennebula_managed
                        replace << ", OPENNEBULA_MANAGED=#{opennebula_managed}"
                    end
                    replace << " ]\n"
                else
                    rc = disk_saveas(disk_id.to_i,"#{name}-disk-#{disk_id}","",-1)

                    raise if OpenNebula.is_error?(rc)

                    if persistent == true
                        OpenNebula::Image.new_with_id(rc.to_i, @client).persistent()
                    end

                    img_ids << rc.to_i

                    disk_template = disk.template_like_str(".").tr("\n", ",\n")

                    if disk_template.empty?
                        replace << "DISK = [ IMAGE_ID = #{rc} ] \n"
                    else
                        replace << "DISK = [ IMAGE_ID = #{rc}, " <<
                            disk_template << " ] \n"
                    end
                end
            else
                # Volatile disks cannot be saved, so the definition is copied
                replace << self.template_like_str(
                    "TEMPLATE", true, "DISK[DISK_ID=#{disk_id}]") << "\n"
            end
        end

        self.each('TEMPLATE/NIC') do |nic|
            nic_id = nic["NIC_ID"]

            if nic_id.nil? || nic_id.empty?
                rc = Error.new('The NIC_ID is missing from the VM template')
                raise
            end

            REMOVE_VNET_ATTRS.each do |attr|
                nic.delete_element(attr)
            end

            replace << "NIC = [ " << nic.template_like_str(".").tr("\n", ",\n") << " ] \n"
        end

        # Required by the Sunstone Cloud View
        replace << "SAVED_TEMPLATE_ID = #{tid}\n"

        new_tmpl = OpenNebula::Template.new_with_id(new_tid, @client)

        rc = new_tmpl.update(replace, true)
        raise if OpenNebula.is_error?(rc)

        return new_tid

    rescue
        # Rollback. Delete the template and the images created
        if !new_tid.nil?
            new_tmpl = OpenNebula::Template.new_with_id(new_tid, @client)
            new_tmpl.delete()
        end

        img_ids.each do |id|
            img = OpenNebula::Image.new_with_id(id, @client)
            img.delete()
        end

        return rc
    end
end
shutdown(hard=false)
Alias for: terminate
snapshot_create(name="") click to toggle source

Creates a new VM snapshot

@param name [String] Name for the snapshot.

@return [Integer, OpenNebula::Error] The new snaphost ID in case

of success, Error otherwise
# File lib/opennebula/virtual_machine.rb, line 602
def snapshot_create(name="")
    return Error.new('ID not defined') if !@pe_id

    name ||= ""
    return @client.call(VM_METHODS[:snapshotcreate], @pe_id, name)
end
snapshot_delete(snap_id) click to toggle source

Deletes a VM snapshot

@param snap_id [Integer] Id of the snapshot

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/virtual_machine.rb, line 625
def snapshot_delete(snap_id)
    return call(VM_METHODS[:snapshotdelete], @pe_id, snap_id)
end
snapshot_revert(snap_id) click to toggle source

Reverts to a snapshot

@param snap_id [Integer] Id of the snapshot

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/virtual_machine.rb, line 615
def snapshot_revert(snap_id)
    return call(VM_METHODS[:snapshotrevert], @pe_id, snap_id)
end
state() click to toggle source

Returns the VM state of the VirtualMachine (numeric value)

# File lib/opennebula/virtual_machine.rb, line 732
def state
    self['STATE'].to_i
end
state_str() click to toggle source

Returns the VM state of the VirtualMachine (string value)

# File lib/opennebula/virtual_machine.rb, line 737
def state_str
    VM_STATE[state]
end
status() click to toggle source

Returns the short status string for the VirtualMachine

# File lib/opennebula/virtual_machine.rb, line 752
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() click to toggle source

Stops a running VM

# File lib/opennebula/virtual_machine.rb, line 395
def stop
    action('stop')
end
suspend() click to toggle source

Saves a running VM

# File lib/opennebula/virtual_machine.rb, line 400
def suspend
    action('suspend')
end
terminate(hard=false) click to toggle source

Shutdowns an already deployed VM

# File lib/opennebula/virtual_machine.rb, line 363
def terminate(hard=false)
    action(hard ? 'terminate-hard' : 'terminate')
end
Also aliased as: shutdown
undeploy(hard=false) click to toggle source

Shuts down an already deployed VM, saving its state in the system DS

# File lib/opennebula/virtual_machine.rb, line 370
def undeploy(hard=false)
    action(hard ? 'undeploy-hard' : 'undeploy')
end
unlock() click to toggle source

Unlock a VM

# File lib/opennebula/virtual_machine.rb, line 723
def unlock()
    return call(VM_METHODS[:unlock], @pe_id)
end
unresched() click to toggle source

Unsets the re-scheduling flag for the VM

# File lib/opennebula/virtual_machine.rb, line 455
def unresched
    action('unresched')
end
update(new_template=nil, append=false) click to toggle source

Replaces the template contents

@param new_template [String] New template contents @param append [true, false] True to append new attributes instead of

replace the whole template

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
Calls superclass method OpenNebula::PoolElement#update
# File lib/opennebula/virtual_machine.rb, line 307
def update(new_template=nil, append=false)
    super(VM_METHODS[:update], new_template, append ? 1 : 0)
end
updateconf(new_conf) click to toggle source
Changes the attributes of a VM in power off, failure and undeploy
states
@param new_conf, string describing the new attributes. Each attribute
will replace the existing ones or delete it if empty. Attributes that
can be updated are: INPUT/{TYPE, BUS}; RAW/{TYPE, DATA, DATA_VMX},
OS/{BOOT, BOOTLOADER, ARCH, MACHINE, KERNEL, INITRD},
FEATURES/{ACPI, APIC, PAE, LOCALTIME, HYPERV, GUEST_AGENT},
and GRAPHICS/{TYPE, LISTEN, PASSWD, KEYMAP}

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/virtual_machine.rb, line 713
        def updateconf(new_conf)
    return call(VM_METHODS[:updateconf], @pe_id, new_conf)
end
user_template_str(indent=true) click to toggle source

Returns the <USER_TEMPLATE> element in text form

@param indent [true,false] indents the resulting string, defaults to true

@return [String] The USER_TEMPLATE

# File lib/opennebula/virtual_machine.rb, line 316
def user_template_str(indent=true)
    template_like_str('USER_TEMPLATE', indent)
end
user_template_xml() click to toggle source

Returns the <USER_TEMPLATE> element in XML form

@return [String] The USER_TEMPLATE

# File lib/opennebula/virtual_machine.rb, line 323
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=10) click to toggle source
# File lib/opennebula/virtual_machine.rb, line 950
def wait_state(state, timeout=10)
    vm_state = ""
    lcm_state = ""

    timeout.times do
        rc = info()
        return rc if OpenNebula.is_error?(rc)

        vm_state = state_str()
        lcm_state = lcm_state_str()

        if vm_state == state
            return true
        end

        sleep 1
    end

    return Error.new("Timeout expired for state #{state}. "<<
        "VM is in state #{vm_state}, #{lcm_state}")
end

Private Instance Methods

action(name) click to toggle source
# File lib/opennebula/virtual_machine.rb, line 973
def action(name)
    return Error.new('ID not defined') if !@pe_id

    rc = @client.call(VM_METHODS[:action], name, @pe_id)
    rc = nil if !OpenNebula.is_error?(rc)

    return rc
end
wait_lcm_state(state, timeout=10) click to toggle source
# File lib/opennebula/virtual_machine.rb, line 982
def wait_lcm_state(state, timeout=10)
    vm_state = ""
    lcm_state = ""

    timeout.times do
        rc = info()
        return rc if OpenNebula.is_error?(rc)

        vm_state = state_str()
        lcm_state = lcm_state_str()

        if lcm_state == state
            return true
        end

        sleep 1
    end

    return Error.new("Timeout expired for state #{state}. "<<
        "VM is in state #{vm_state}, #{lcm_state}")
end