class OpenNebula::Host

Constants

HOST_METHODS

Constants and Class Methods

HOST_STATES
SHORT_HOST_STATES

Public Class Methods

build_xml(pe_id=nil) click to toggle source

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

Example:

host = Host.new(Host.build_xml(3),rpc_client)
# File lib/opennebula/host.rb, line 57
def Host.build_xml(pe_id=nil)
    if pe_id
        host_xml = "<HOST><ID>#{pe_id}</ID></HOST>"
    else
        host_xml = "<HOST></HOST>"
    end

    XMLElement.build_xml(host_xml, 'HOST')
end
new(xml, client) click to toggle source

Class constructor

Calls superclass method
# File lib/opennebula/host.rb, line 68
def initialize(xml, client)
    super(xml,client)

    @client = client
    @pe_id  = self['ID'].to_i if self['ID']
end

Public Instance Methods

allocate(hostname,im,vmm,vnm,cluster_id=ClusterPool::NONE_CLUSTER_ID) click to toggle source

Allocates a new Host in OpenNebula

@param hostname [String] Name of the new Host. @param im [String] Name of the im_driver (information/monitoring) @param vmm [String] Name of the vmm_driver (hypervisor) @param vnm [String] Name of the vnm_driver (networking) @param cluster_id [String] Id of the cluster

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

success, error otherwise
Calls superclass method
# File lib/opennebula/host.rb, line 96
def allocate(hostname,im,vmm,vnm,cluster_id=ClusterPool::NONE_CLUSTER_ID)
    super(HOST_METHODS[:allocate],hostname,im,vmm,vnm,cluster_id)
end
delete() click to toggle source

Deletes the Host

Calls superclass method
# File lib/opennebula/host.rb, line 101
def delete()
    super(HOST_METHODS[:delete])
end
disable() click to toggle source

Disables the Host

# File lib/opennebula/host.rb, line 111
def disable()
    set_enabled(false)
end
enable() click to toggle source

Enables the Host

# File lib/opennebula/host.rb, line 106
def enable()
    set_enabled(true)
end
flush() click to toggle source
# File lib/opennebula/host.rb, line 115
def flush()
    self.disable

    vm_pool = OpenNebula::VirtualMachinePool.new(@client,
                                        VirtualMachinePool::INFO_ALL_VM)

    rc = vm_pool.info
    if OpenNebula.is_error?(rc)
         puts rc.message
         exit -1
    end

    vm_pool.each do |vm|
        hid = vm['HISTORY_RECORDS/HISTORY[last()]/HID']
        if hid == self['ID']
            vm.resched
        end
    end
end
info() click to toggle source

Retrieves the information of the given Host.

Calls superclass method
# File lib/opennebula/host.rb, line 80
def info()
    super(HOST_METHODS[:info], 'HOST')
end
Also aliased as: info!
info!()
Alias for: info
monitoring(xpath_expressions) click to toggle source

Retrieves this Host'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

host.monitoring( ['HOST_SHARE/FREE_CPU', 'HOST_SHARE/RUNNING_VMS'] )

{ "HOST_SHARE/RUNNING_VMS" =>
    [["1337266000", "1"],
     ["1337266044", "1"],
     ["1337266088", "3"]],
  "HOST_SHARE/FREE_CPU" =>
    [["1337266000", "800"],
     ["1337266044", "800"],
     ["1337266088", "800"]]
}
Calls superclass method
# File lib/opennebula/host.rb, line 166
def monitoring(xpath_expressions)
    return super(HOST_METHODS[:monitoring], 'HOST',
        'LAST_MON_TIME', xpath_expressions)
end
monitoring_xml() click to toggle source

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

@return [String] Monitoring data, in XML

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

    return @client.call(HOST_METHODS[:monitoring], @pe_id)
end
rename(name) click to toggle source

Renames this Host

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

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

otherwise
# File lib/opennebula/host.rb, line 186
def rename(name)
    return call(HOST_METHODS[:rename], @pe_id, name)
end
short_state_str() click to toggle source

Returns the state of the Host (string value)

# File lib/opennebula/host.rb, line 205
def short_state_str
    SHORT_HOST_STATES[state_str]
end
state() click to toggle source

Returns the state of the Host (numeric value)

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

Returns the state of the Host (string value)

# File lib/opennebula/host.rb, line 200
def state_str
    HOST_STATES[state]
end
update(new_template, 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
# File lib/opennebula/host.rb, line 143
def update(new_template, append=false)
    super(HOST_METHODS[:update], new_template, append ? 1 : 0)
end

Private Instance Methods

set_enabled(enabled) click to toggle source
# File lib/opennebula/host.rb, line 210
def set_enabled(enabled)
    return Error.new('ID not defined') if !@pe_id

    rc = @client.call(HOST_METHODS[:enable], @pe_id, enabled)
    rc = nil if !OpenNebula.is_error?(rc)

    return rc
end