Class: OpenNebula::Host

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

Constant Summary collapse

HOST_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

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

Constructor Details

#initialize(xml, client) ⇒ Host

Class constructor



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

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)


52
53
54
55
56
57
58
59
60
# File 'lib/OpenNebula/Host.rb', line 52

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, vnm, cluster_id = ClusterPool::NONE_CLUSTER_ID) ⇒ Integer, OpenNebula::Error

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)

  • tm (String)

    Name of the vnm_driver (networking)

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

    Id of the cluster

Returns:



89
90
91
# File 'lib/OpenNebula/Host.rb', line 89

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

#deleteObject

Deletes the Host



94
95
96
# File 'lib/OpenNebula/Host.rb', line 94

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

#disableObject

Disables the Host



104
105
106
# File 'lib/OpenNebula/Host.rb', line 104

def disable()
    set_enabled(false)
end

#enableObject

Enables the Host



99
100
101
# File 'lib/OpenNebula/Host.rb', line 99

def enable()
    set_enabled(true)
end

#infoObject

Retrieves the information of the given Host.



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

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

#short_state_strObject

Returns the state of the Host (string value)



130
131
132
# File 'lib/OpenNebula/Host.rb', line 130

def short_state_str
    SHORT_HOST_STATES[state_str]
end

#stateObject

Returns the state of the Host (numeric value)



120
121
122
# File 'lib/OpenNebula/Host.rb', line 120

def state
    self['STATE'].to_i
end

#state_strObject

Returns the state of the Host (string value)



125
126
127
# File 'lib/OpenNebula/Host.rb', line 125

def state_str
    HOST_STATES[state]
end

#update(new_template) ⇒ Object

Replaces the template contents

new_template New template contents



111
112
113
# File 'lib/OpenNebula/Host.rb', line 111

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