Class: OpenNebula::Host

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

Constant Summary

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

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

Constructor Details

- (Host) initialize(xml, client)

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

+ (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)



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

- (Integer, OpenNebula::Error) allocate(hostname, im, vmm, vnm, tm)

Allocates a new Host in OpenNebula

Parameters:

  • hostname (String)

    Name of the new Host.

  • im (String)

    Name of the im_driver

  • vmm (String)

    Name of the vmm_driver

  • tm (String)

    Name of the tm_driver

Returns:



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

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

- (Object) delete

Deletes the Host



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

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

- (Object) disable

Disables the Host



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

def disable()
    set_enabled(false)
end

- (Object) enable

Enables the Host



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

def enable()
    set_enabled(true)
end

- (Object) info

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

- (Object) short_state_str

Returns the state of the Host (string value)



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

def short_state_str
    SHORT_HOST_STATES[state_str]
end

- (Object) state

Returns the state of the Host (numeric value)



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

def state
    self['STATE'].to_i
end

- (Object) state_str

Returns the state of the Host (string value)



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

def state_str
    HOST_STATES[state]
end

- (Object) update(new_template)

Replaces the template contents

+new_template+ New template contents



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

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