Class: OpenNebula::VirtualNetwork
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::VirtualNetwork
- Defined in:
- lib/opennebula/virtual_network.rb
Constant Summary collapse
- VN_METHODS =
Constants and Class Methods
{ :info => "vn.info", :allocate => "vn.allocate", :delete => "vn.delete", :add_ar => "vn.add_ar", :rm_ar => "vn.rm_ar", :update_ar => "vn.update_ar", :chown => "vn.chown", :chmod => "vn.chmod", :update => "vn.update", :hold => "vn.hold", :release => "vn.release", :rename => "vn.rename", :reserve => "vn.reserve", :free_ar => "vn.free_ar", :lock => "vn.lock", :unlock => "vn.unlock", :recover => "vn.recover" }
- VN_STATES =
%w{INIT READY LOCK_CREATE LOCK_DELETE DONE ERROR}
- SHORT_VN_STATES =
{ "INIT" => "init", "READY" => "rdy", "LOCK_CREATE" => "lock", "LOCK_DELETE" => "lock", "DONE" => "done", "ERROR" => "err" }
Class Method Summary collapse
-
.build_xml(pe_id = nil) ⇒ Object
Creates a VirtualNetwork description with just its identifier this method should be used to create plain VirtualNetwork objects.
Instance Method Summary collapse
-
#add_ar(ar_template) ⇒ Object
Adds Address Ranges to the VirtualNetwork.
-
#addleases(ip, mac = nil) ⇒ Object
deprecated
Deprecated.
use #add_ar
-
#allocate(description, cluster_id = ClusterPool::NONE_CLUSTER_ID) ⇒ Integer, OpenNebula::Error
Allocates a new VirtualNetwork in OpenNebula.
-
#chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) ⇒ nil, OpenNebula::Error
Changes the virtual network permissions.
-
#chmod_octet(octet) ⇒ nil, OpenNebula::Error
Changes the virtual network permissions.
-
#chown(uid, gid) ⇒ nil, OpenNebula::Error
Changes the owner/group.
-
#delete ⇒ Object
Deletes the VirtualNetwork.
-
#free(ar_id) ⇒ Object
Removes an Address Range from the VirtualNetwork.
-
#gid ⇒ Object
Returns the group identifier [return] Integer the element’s group ID.
-
#hold(ip, ar_id = -1)) ⇒ Object
Holds a virtual network address.
-
#info(decrypt = false) ⇒ Object
(also: #info!)
Retrieves the information of the given VirtualNetwork.
-
#initialize(xml, client) ⇒ VirtualNetwork
constructor
Class constructor.
- #public? ⇒ Boolean
-
#publish ⇒ Object
Publishes the VirtualNetwork, to be used by other users.
-
#recover(result) ⇒ nil, OpenNebula::Error
Recovers an stuck Virtual Network.
-
#release(ip, ar_id = -1)) ⇒ Object
Releases an address on hold.
-
#rename(name) ⇒ nil, OpenNebula::Error
Renames this virtual network.
-
#reserve(rname, rsize, ar_id, addr, vnet) ⇒ Integer, OpenNebula::Error
Reserve a set of addresses from this virtual network.
- #reserve_with_extra(extra) ⇒ Object
-
#rm_ar(ar_id, force = false) ⇒ Object
Removes an Address Range from the VirtualNetwork.
-
#rmleases(ip) ⇒ Object
deprecated
Deprecated.
use ##rm_ar
-
#short_state_str ⇒ Object
Returns the state of the Virtual Network (string value).
-
#state ⇒ Object
Returns the state of the Virtual Network (numeric value).
-
#state_str ⇒ Object
Returns the state of the Virtual Network (string value).
-
#unpublish ⇒ Object
Unplubishes the VirtualNetwork.
-
#update(new_template = nil, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents.
-
#update_ar(ar_template) ⇒ Object
Updates Address Ranges from the VirtualNetwork.
-
#vrouter_ids ⇒ Object
Returns an array with the numeric virtual router ids.
Methods inherited from PoolElement
#id, #name, new_with_id, #replace, #to_str
Methods inherited from XMLElement
#[], #add_element, #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) ⇒ VirtualNetwork
Class constructor
76 77 78 79 80 |
# File 'lib/opennebula/virtual_network.rb', line 76 def initialize(xml, client) LockableExt.make_lockable(self, VN_METHODS) super(xml,client) end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
Creates a VirtualNetwork description with just its identifier this method should be used to create plain VirtualNetwork objects. id
the id of the network
Example:
vnet = VirtualNetwork.new(VirtualNetwork.build_xml(3),rpc_client)
65 66 67 68 69 70 71 72 73 |
# File 'lib/opennebula/virtual_network.rb', line 65 def VirtualNetwork.build_xml(pe_id=nil) if pe_id vn_xml = "<VNET><ID>#{pe_id}</ID></VNET>" else vn_xml = "<VNET></VNET>" end XMLElement.build_xml(vn_xml, 'VNET') end |
Instance Method Details
#add_ar(ar_template) ⇒ Object
Adds Address Ranges to the VirtualNetwork
132 133 134 135 136 137 138 139 |
# File 'lib/opennebula/virtual_network.rb', line 132 def add_ar(ar_template) return Error.new('ID not defined') if !@pe_id rc = @client.call(VN_METHODS[:add_ar], @pe_id, ar_template) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#addleases(ip, mac = nil) ⇒ Object
use #add_ar
Simulates old addleases call
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/opennebula/virtual_network.rb', line 143 def addleases(ip, mac=nil) self.info ar_id = self.retrieve_elements("AR_POOL/AR[IP='#{ip}' and SIZE='1']/AR_ID") if !ar_id.nil? return Error.new("IP Address Range found with IP #{ip}") end template = 'AR = [ ' template << 'TYPE = "IP4"' template << ', IP = "' << ip << '"' if ip template << ', MAC = "' << mac << '"' if mac template << ', SIZE = 1 ]' add_ar(template) end |
#allocate(description, cluster_id = ClusterPool::NONE_CLUSTER_ID) ⇒ Integer, OpenNebula::Error
Allocates a new VirtualNetwork in OpenNebula
100 101 102 |
# File 'lib/opennebula/virtual_network.rb', line 100 def allocate(description,cluster_id=ClusterPool::NONE_CLUSTER_ID) super(VN_METHODS[:allocate], description, cluster_id) end |
#chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) ⇒ nil, OpenNebula::Error
Changes the virtual network permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
310 311 312 313 314 |
# File 'lib/opennebula/virtual_network.rb', line 310 def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) super(VN_METHODS[:chmod], owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) end |
#chmod_octet(octet) ⇒ nil, OpenNebula::Error
Changes the virtual network permissions.
301 302 303 |
# File 'lib/opennebula/virtual_network.rb', line 301 def chmod_octet(octet) super(VN_METHODS[:chmod], octet) end |
#chown(uid, gid) ⇒ nil, OpenNebula::Error
Changes the owner/group
292 293 294 |
# File 'lib/opennebula/virtual_network.rb', line 292 def chown(uid, gid) super(VN_METHODS[:chown], uid, gid) end |
#delete ⇒ Object
Deletes the VirtualNetwork
127 128 129 |
# File 'lib/opennebula/virtual_network.rb', line 127 def delete() super(VN_METHODS[:delete]) end |
#free(ar_id) ⇒ Object
Removes an Address Range from the VirtualNetwork
276 277 278 279 280 281 282 283 |
# File 'lib/opennebula/virtual_network.rb', line 276 def free(ar_id) return Error.new('ID not defined') if !@pe_id rc = @client.call(VN_METHODS[:free_ar], @pe_id, ar_id.to_i) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#gid ⇒ Object
Returns the group identifier
- return
-
Integer the element’s group ID
342 343 344 |
# File 'lib/opennebula/virtual_network.rb', line 342 def gid self['GID'].to_i end |
#hold(ip, ar_id = -1)) ⇒ Object
Holds a virtual network address
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/opennebula/virtual_network.rb', line 201 def hold(ip, ar_id=-1) return Error.new('ID not defined') if !@pe_id addr_name = address_type(ip) return addr_name if OpenNebula.is_error?(addr_name) lease_template = "LEASES = [ #{addr_name} = #{ip}" lease_template << ", AR_ID = #{ar_id}" if ar_id != -1 lease_template << "]" rc = @client.call(VN_METHODS[:hold], @pe_id, lease_template) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#info(decrypt = false) ⇒ Object Also known as: info!
Retrieves the information of the given VirtualNetwork.
87 88 89 |
# File 'lib/opennebula/virtual_network.rb', line 87 def info(decrypt = false) super(VN_METHODS[:info], 'VNET', decrypt) end |
#public? ⇒ Boolean
346 347 348 349 350 351 352 |
# File 'lib/opennebula/virtual_network.rb', line 346 def public? if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1" true else false end end |
#publish ⇒ Object
Publishes the VirtualNetwork, to be used by other users
117 118 119 |
# File 'lib/opennebula/virtual_network.rb', line 117 def publish set_publish(true) end |
#recover(result) ⇒ nil, OpenNebula::Error
Recovers an stuck Virtual Network
delete (2)
332 333 334 |
# File 'lib/opennebula/virtual_network.rb', line 332 def recover(result) return call(VN_METHODS[:recover], @pe_id, result) end |
#release(ip, ar_id = -1)) ⇒ Object
Releases an address on hold
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/opennebula/virtual_network.rb', line 222 def release(ip, ar_id=-1) return Error.new('ID not defined') if !@pe_id addr_name = address_type(ip) return addr_name if OpenNebula.is_error?(addr_name) lease_template = "LEASES = [ #{addr_name} = #{ip}" lease_template << ", AR_ID = #{ar_id}" if ar_id != -1 lease_template << "]" rc = @client.call(VN_METHODS[:release], @pe_id, lease_template) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this virtual network
322 323 324 |
# File 'lib/opennebula/virtual_network.rb', line 322 def rename(name) return call(VN_METHODS[:rename], @pe_id, name) end |
#reserve(rname, rsize, ar_id, addr, vnet) ⇒ Integer, OpenNebula::Error
Reserve a set of addresses from this virtual network
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/opennebula/virtual_network.rb', line 250 def reserve(rname, rsize, ar_id, addr, vnet) return Error.new('ID not defined') if !@pe_id rtmpl = "SIZE = #{rsize}\n" rtmpl << "NAME = \"#{rname}\"\n" if !rname.nil? rtmpl << "AR_ID = #{ar_id}\n" if !ar_id.nil? rtmpl << "NETWORK_ID = #{vnet}\n" if !vnet.nil? if !addr.nil? addr_name = address_type(addr) return addr_name if OpenNebula.is_error?(addr_name) rtmpl << "#{addr_name} = #{addr}\n" end return @client.call(VN_METHODS[:reserve], @pe_id, rtmpl) end |
#reserve_with_extra(extra) ⇒ Object
269 270 271 272 273 |
# File 'lib/opennebula/virtual_network.rb', line 269 def reserve_with_extra(extra) return Error.new('ID not defined') unless @pe_id @client.call(VN_METHODS[:reserve], @pe_id, extra) end |
#rm_ar(ar_id, force = false) ⇒ Object
Removes an Address Range from the VirtualNetwork
162 163 164 165 166 167 168 169 |
# File 'lib/opennebula/virtual_network.rb', line 162 def rm_ar(ar_id, force = false) return Error.new('ID not defined') if !@pe_id rc = @client.call(VN_METHODS[:rm_ar], @pe_id, ar_id.to_i, force) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#rmleases(ip) ⇒ Object
use ##rm_ar
Simulates old rmleases call
173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/opennebula/virtual_network.rb', line 173 def rmleases(ip) self.info ar_id = self.retrieve_elements("AR_POOL/AR[IP='#{ip}' and SIZE='1']/AR_ID") if !ar_id Error.new("No single IP Address Range found with IP #{ip}") elsif ar_id.size > 1 Error.new("More than one Address Range found with IP #{ip} use rmar") else rm_ar(ar_id[0]) end end |
#short_state_str ⇒ Object
Returns the state of the Virtual Network (string value)
376 377 378 |
# File 'lib/opennebula/virtual_network.rb', line 376 def short_state_str SHORT_VN_STATES[state_str] end |
#state ⇒ Object
Returns the state of the Virtual Network (numeric value)
366 367 368 |
# File 'lib/opennebula/virtual_network.rb', line 366 def state self['STATE'].to_i end |
#state_str ⇒ Object
Returns the state of the Virtual Network (string value)
371 372 373 |
# File 'lib/opennebula/virtual_network.rb', line 371 def state_str VN_STATES[state] end |
#unpublish ⇒ Object
Unplubishes the VirtualNetwork
122 123 124 |
# File 'lib/opennebula/virtual_network.rb', line 122 def unpublish set_publish(false) end |
#update(new_template = nil, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents
112 113 114 |
# File 'lib/opennebula/virtual_network.rb', line 112 def update(new_template=nil, append=false) super(VN_METHODS[:update], new_template, append ? 1 : 0) end |
#update_ar(ar_template) ⇒ Object
Updates Address Ranges from the VirtualNetwork
188 189 190 191 192 193 194 195 |
# File 'lib/opennebula/virtual_network.rb', line 188 def update_ar(ar_template) return Error.new('ID not defined') if !@pe_id rc = @client.call(VN_METHODS[:update_ar], @pe_id, ar_template) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#vrouter_ids ⇒ Object
Returns an array with the numeric virtual router ids
355 356 357 358 359 360 361 362 363 |
# File 'lib/opennebula/virtual_network.rb', line 355 def vrouter_ids array = Array.new self.each("VROUTERS/ID") do |id| array << id.text.to_i end return array end |