Class: OpenNebula::Host

Inherits:
PoolElement show all
Defined in:
lib/OpenNebula/Host.rb

Constant Summary collapse

HOST_METHODS =

Constants and Class Methods

{
    :info     => "host.info",
    :allocate => "host.allocate",
    :delete   => "host.delete",
    :enable   => "host.enable",
    :update   => "host.update"
}
HOST_STATES =
%w{INIT MONITORING MONITORED ERROR DISABLED}
SHORT_HOST_STATES =
{
    "INIT"          => "on",
    "MONITORING"    => "on",
    "MONITORED"     => "on",
    "ERROR"         => "err",
    "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

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

Constructor Details

#initialize(xml, client) ⇒ Host

Class constructor



62
63
64
65
66
67
# File 'lib/OpenNebula/Host.rb', line 62

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

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

Class Method Details

.build_xml(pe_id = nil) ⇒ Object

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)


49
50
51
52
53
54
55
56
57
# File 'lib/OpenNebula/Host.rb', line 49

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

#allocate(hostname, im, vmm, tm) ⇒ Object

Allocates a new Host in OpenNebula

hostname A string containing the name of the new Host.

im A string containing the name of the im_driver

vmm A string containing the name of the vmm_driver

tm A string containing the name of the tm_driver



87
88
89
# File 'lib/OpenNebula/Host.rb', line 87

def allocate(hostname,im,vmm,tm)
    super(HOST_METHODS[:allocate],hostname,im,vmm,tm)
end

#deleteObject

Deletes the Host



92
93
94
# File 'lib/OpenNebula/Host.rb', line 92

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

#disableObject

Disables the Host



102
103
104
# File 'lib/OpenNebula/Host.rb', line 102

def disable()
    set_enabled(false)
end

#enableObject

Enables the Host



97
98
99
# File 'lib/OpenNebula/Host.rb', line 97

def enable()
    set_enabled(true)
end

#infoObject

Retrieves the information of the given Host.



74
75
76
# File 'lib/OpenNebula/Host.rb', line 74

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

#short_state_strObject

Returns the state of the Host (string value)



128
129
130
# File 'lib/OpenNebula/Host.rb', line 128

def short_state_str
    SHORT_HOST_STATES[state_str]
end

#stateObject

Returns the state of the Host (numeric value)



118
119
120
# File 'lib/OpenNebula/Host.rb', line 118

def state
    self['STATE'].to_i
end

#state_strObject

Returns the state of the Host (string value)



123
124
125
# File 'lib/OpenNebula/Host.rb', line 123

def state_str
    HOST_STATES[state]
end

#update(new_template) ⇒ Object

Replaces the template contents

new_template New template contents



109
110
111
# File 'lib/OpenNebula/Host.rb', line 109

def update(new_template)
    super(HOST_METHODS[:update], new_template)
end