Class: OpenNebula::Host

Inherits:
PoolElement show all
Defined in:
opennebula/host.rb

Constant Summary

HOST_METHODS =
{
    :info       => "host.info",
    :allocate   => "host.allocate",
    :delete     => "host.delete",
    :enable     => "host.enable",
    :update     => "host.update",
    :monitoring => "host.monitoring"
}
HOST_STATES =
%w{INIT MONITORING_MONITORED MONITORED ERROR DISABLED MONITORING_ERROR MONITORING_INIT MONITORING_DISABLED}
SHORT_HOST_STATES =
{
    "INIT"                 => "init",
    "MONITORING_MONITORED" => "update",
    "MONITORED"            => "on",
    "ERROR"                => "err",
    "DISABLED"             => "off",
    "MONITORING_ERROR"     => "retry",
    "MONITORING_INIT"      => "init",
    "MONITORING_DISABLED"  => "off"
}

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from PoolElement

#id, #name, new_with_id, #to_str

Methods inherited from XMLElement

#[], #add_element, #attr, #delete_element, #each, #each_xpath, #element_xml, #has_elements?, #initialize_xml, #name, #retrieve_elements, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml

Constructor Details

- (Host) initialize(xml, client)

Class constructor



67
68
69
70
71
72
# File 'opennebula/host.rb', line 67

def initialize(xml, client)
    super(xml,client)

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

Class Method Details

+ (Object) build_xml(pe_id = nil)

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)


56
57
58
59
60
61
62
63
64
# File 'opennebula/host.rb', line 56

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

Instance Method Details

- (Integer, OpenNebula::Error) allocate(hostname, im, vmm, vnm, cluster_id = ClusterPool::NONE_CLUSTER_ID)

Allocates a new Host in OpenNebula

Parameters:

  • hostname (String)

    Name of the new Host.

  • im (String)

    Name of the im_driver (information/monitoring)

  • vmm (String)

    Name of the vmm_driver (hypervisor)

  • vnm (String)

    Name of the vnm_driver (networking)

  • cluster_id (String) (defaults to: ClusterPool::NONE_CLUSTER_ID)

    Id of the cluster

Returns:



95
96
97
# File 'opennebula/host.rb', line 95

def allocate(hostname,im,vmm,vnm,cluster_id=ClusterPool::NONE_CLUSTER_ID)
    super(HOST_METHODS[:allocate],hostname,im,vmm,vnm,cluster_id)
end

- (Object) delete

Deletes the Host



100
101
102
# File 'opennebula/host.rb', line 100

def delete()
    super(HOST_METHODS[:delete])
end

- (Object) disable

Disables the Host



110
111
112
# File 'opennebula/host.rb', line 110

def disable()
    set_enabled(false)
end

- (Object) enable

Enables the Host



105
106
107
# File 'opennebula/host.rb', line 105

def enable()
    set_enabled(true)
end

- (Object) flush



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'opennebula/host.rb', line 114

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

- (Object) info Also known as: info!

Retrieves the information of the given Host.



79
80
81
# File 'opennebula/host.rb', line 79

def info()
    super(HOST_METHODS[:info], 'HOST')
end

- (Hash<String, Array<Array<int>>>, OpenNebula::Error) monitoring(xpath_expressions)

Retrieves this Host's monitoring data from OpenNebula

Examples:

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"]]
}

Parameters:

  • xpath_expressions (Array<String>)

    Elements to retrieve.

Returns:

  • (Hash<String, Array<Array<int>>>, OpenNebula::Error)

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



165
166
167
168
# File 'opennebula/host.rb', line 165

def monitoring(xpath_expressions)
    return super(HOST_METHODS[:monitoring], 'HOST',
        'LAST_MON_TIME', xpath_expressions)
end

- (String) monitoring_xml

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

Returns:

  • (String)

    Monitoring data, in XML



173
174
175
176
177
# File 'opennebula/host.rb', line 173

def monitoring_xml()
    return Error.new('ID not defined') if !@pe_id

    return @client.call(HOST_METHODS[:monitoring], @pe_id)
end

- (Object) short_state_str

Returns the state of the Host (string value)



194
195
196
# File 'opennebula/host.rb', line 194

def short_state_str
    SHORT_HOST_STATES[state_str]
end

- (Object) state

Returns the state of the Host (numeric value)



184
185
186
# File 'opennebula/host.rb', line 184

def state
    self['STATE'].to_i
end

- (Object) state_str

Returns the state of the Host (string value)



189
190
191
# File 'opennebula/host.rb', line 189

def state_str
    HOST_STATES[state]
end

- (nil, OpenNebula::Error) update(new_template, append = false)

Replaces the template contents

Parameters:

  • new_template (String)

    New template contents

  • append (true, false) (defaults to: false)

    True to append new attributes instead of replace the whole template

Returns:



142
143
144
# File 'opennebula/host.rb', line 142

def update(new_template, append=false)
    super(HOST_METHODS[:update], new_template, append ? 1 : 0)
end