Class: OpenNebula::Zone

Inherits:
PoolElement show all
Defined in:
lib/opennebula/zone.rb

Constant Summary collapse

ZONE_METHODS =

Constants and Class Methods

{
    :info           => "zone.info",
    :allocate       => "zone.allocate",
    :update         => "zone.update",
    :rename         => "zone.rename",
    :delete         => "zone.delete",
    :addserver      => "zone.addserver",
    :delserver      => "zone.delserver",
    :resetserver    => "zone.resetserver",
    :enable         => "zone.enable"
}
ZONE_STATES =
%w{ENABLED DISABLED}
SHORT_ZONE_STATES =
{
    "ENABLED"              => "on",
    "DISABLED"             => "off"
}

Instance Attribute Summary

Attributes inherited from PoolElement

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PoolElement

#id, new_with_id, #replace, #to_str

Methods inherited from XMLElement

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

Constructor Details

#initialize(xml, client) ⇒ Zone

Class constructor



63
64
65
# File 'lib/opennebula/zone.rb', line 63

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

Class Method Details

.build_xml(pe_id = nil) ⇒ Object

Creates a Zone description with just its identifier this method should be used to create plain Zone objects. Example:

zone = Zone.new(Zone.build_xml(3),rpc_client)

Parameters:

  • id (Integer)

    the id of the Zone



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

def Zone.build_xml(pe_id=nil)
    if pe_id
        zone_xml = "<ZONE><ID>#{pe_id}</ID></ZONE>"
    else
        zone_xml = "<ZONE></ZONE>"
    end

    XMLElement.build_xml(zone_xml,'ZONE')
end

Instance Method Details

#add_servers(servers) ⇒ nil, OpenNebula::Error

Adds servers to this Zone

Parameters:

  • name (String)

    Template with zone servers SERVER = [ NAME = “<server_name>”, ENDPOINT = “<rpc_ep>” ]

Returns:



166
167
168
# File 'lib/opennebula/zone.rb', line 166

def add_servers(servers)
    return call(ZONE_METHODS[:addserver], @pe_id, servers)
end

#allocate(description) ⇒ nil, OpenNebula::Error

Allocates a new Zone in OpenNebula

Parameters:

  • description (String)

    The template of the Zone.

Returns:



126
127
128
# File 'lib/opennebula/zone.rb', line 126

def allocate(description)
    super(ZONE_METHODS[:allocate], description)
end

#deletenil, OpenNebula::Error

Deletes the Zone

Returns:



145
146
147
# File 'lib/opennebula/zone.rb', line 145

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

#delete_servers(server_id) ⇒ nil, OpenNebula::Error

Delete servers from this Zone

Parameters:

  • id (Int)

    Server ID

Returns:



176
177
178
# File 'lib/opennebula/zone.rb', line 176

def delete_servers(server_id)
    return call(ZONE_METHODS[:delserver], @pe_id, server_id)
end

#disablenil, OpenNebula::Error

Disable zone, only readonly commands can be executed in disabled state

Returns:



203
204
205
# File 'lib/opennebula/zone.rb', line 203

def disable()
    return call(ZONE_METHODS[:enable], @pe_id, false)
end

#enablenil, OpenNebula::Error

Enable zone

Returns:



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

def enable()
    return call(ZONE_METHODS[:enable], @pe_id, true)
end

#infonil, OpenNebula::Error Also known as: info!

Retrieves the information of the given Zone.

Returns:



74
75
76
# File 'lib/opennebula/zone.rb', line 74

def info()
    super(ZONE_METHODS[:info], 'ZONE')
end

#info_extendednil, OpenNebula::Error Also known as: info_extended!

Retrieves the information extended of the given Zone.

Returns:



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/opennebula/zone.rb', line 81

def info_extended()
    rc = info()

    return rc if OpenNebula.is_error?(rc)

    @xml.xpath("SERVER_POOL/SERVER").each do |server|
        endpoint = server.xpath("ENDPOINT")
        endpoint = endpoint.text if endpoint

        next if endpoint.nil?

        client = OpenNebula::Client.new(nil, endpoint, {:timeout => 5})

        xml = client.call("zone.raftstatus")

        if OpenNebula.is_error?(xml)
            add_element(server, "STATE", "-")
            add_element(server, "TERM", "-")
            add_element(server, "VOTEDFOR", "-")
            add_element(server, "COMMIT", "-")
            add_element(server, "LOG_INDEX", "-")
            add_element(server, "FEDLOG_INDEX", "-")

            next
        end

        xml = Nokogiri::XML(xml)

        add_element_xml(server, xml, "STATE", "RAFT/STATE")
        add_element_xml(server, xml, "TERM", "RAFT/TERM")
        add_element_xml(server, xml, "VOTEDFOR", "RAFT/VOTEDFOR")
        add_element_xml(server, xml, "COMMIT", "RAFT/COMMIT")
        add_element_xml(server, xml, "LOG_INDEX", "RAFT/LOG_INDEX")
        add_element_xml(server, xml, "FEDLOG_INDEX","RAFT/FEDLOG_INDEX")
    end
end

#rename(name) ⇒ nil, OpenNebula::Error

Renames this Zone

Parameters:

  • name (String)

    New name for the Zone.

Returns:



155
156
157
# File 'lib/opennebula/zone.rb', line 155

def rename(name)
    return call(ZONE_METHODS[:rename], @pe_id, name)
end

#reset_server(server_id) ⇒ nil, OpenNebula::Error

Reset index for a follower

Parameters:

  • id (Int)

    Server ID

Returns:



186
187
188
# File 'lib/opennebula/zone.rb', line 186

def reset_server(server_id)
    return call(ZONE_METHODS[:resetserver], @pe_id, server_id)
end

#stateObject

Returns the state of the Zone (numeric value)



212
213
214
# File 'lib/opennebula/zone.rb', line 212

def state
    self['STATE'].to_i
end

#state_strObject

Returns the state of the Zone (string value)



217
218
219
# File 'lib/opennebula/zone.rb', line 217

def state_str
    ZONE_STATES[state]
end

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

Replaces the template contents

Parameters:

  • new_template (String) (defaults to: nil)

    New template contents

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

    True to append new attributes instead of replace the whole template

Returns:



138
139
140
# File 'lib/opennebula/zone.rb', line 138

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