class OpenNebula::VirtualNetwork
Constants
- SHORT_VN_STATES
- VN_METHODS
-
Constants and Class Methods
- VN_STATES
Public Class Methods
Source
# File lib/opennebula/virtual_network.rb, line 66 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
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)
Source
# File lib/opennebula/virtual_network.rb, line 77 def initialize(xml, client) LockableExt.make_lockable(self, VN_METHODS) super(xml,client) end
Class constructor
OpenNebula::PoolElement::new
Public Instance Methods
Source
# File lib/opennebula/virtual_network.rb, line 133 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
Adds Address Ranges to the VirtualNetwork
Source
# File lib/opennebula/virtual_network.rb, line 144 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
Simulates old addleases call @deprecated use {#add_ar}
Source
# File lib/opennebula/virtual_network.rb, line 101 def allocate(description,cluster_id=ClusterPool::NONE_CLUSTER_ID) super(VN_METHODS[:allocate], description, cluster_id) end
Allocates a new VirtualNetwork
in OpenNebula
@param description [String] The template of the VirtualNetwork
. @param cluster_id [Integer] Id of the cluster, -1 to use default
@return [Integer, OpenNebula::Error
] the new ID in case of
success, error otherwise
OpenNebula::PoolElement#allocate
Source
# File lib/opennebula/virtual_network.rb, line 311 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
Changes the virtual network permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
OpenNebula::PoolElement#chmod
Source
# File lib/opennebula/virtual_network.rb, line 302 def chmod_octet(octet) super(VN_METHODS[:chmod], octet) end
Changes the virtual network permissions.
@param octet [String] Permissions octed , e.g. 640 @return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
OpenNebula::PoolElement#chmod_octet
Source
# File lib/opennebula/virtual_network.rb, line 293 def chown(uid, gid) super(VN_METHODS[:chown], uid, gid) end
Changes the owner/group
@param uid [Integer] the new owner id. Set to -1 to leave the current one @param gid [Integer] the new group id. Set to -1 to leave the current one
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
OpenNebula::PoolElement#chown
Source
# File lib/opennebula/virtual_network.rb, line 128 def delete() super(VN_METHODS[:delete]) end
Deletes the VirtualNetwork
OpenNebula::PoolElement#delete
Source
# File lib/opennebula/virtual_network.rb, line 277 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
Removes an Address Range from the VirtualNetwork
Source
# File lib/opennebula/virtual_network.rb, line 343 def gid self['GID'].to_i end
Returns the group identifier
- return
-
Integer the element’s group ID
Source
# File lib/opennebula/virtual_network.rb, line 202 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
Holds a virtual network address @param ip [String] address to hold, if contains “:” a MAC address is assumed @param ar_id [Integer] The address range to hold the lease. If not set
the lease will be held from all possible address ranges
Source
# File lib/opennebula/virtual_network.rb, line 88 def info(decrypt = false) super(VN_METHODS[:info], 'VNET', decrypt) end
Retrieves the information of the given VirtualNetwork
.
OpenNebula::PoolElement#info
Source
# File lib/opennebula/virtual_network.rb, line 347 def public? if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1" true else false end end
Source
# File lib/opennebula/virtual_network.rb, line 118 def publish set_publish(true) end
Publishes the VirtualNetwork
, to be used by other users
Source
# File lib/opennebula/virtual_network.rb, line 333 def recover(result) return call(VN_METHODS[:recover], @pe_id, result) end
Recovers an stuck Virtual Network
@param result [Integer] Recover with failure (0), success (1), delete (2), retry (3) @return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
Source
# File lib/opennebula/virtual_network.rb, line 223 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
Releases an address on hold @param ip [String] IP to release, if contains “:” a MAC address is assumed @param ar_id [Integer] The address range to release the lease. If not
set the lease will be freed from all possible address ranges
Source
# File lib/opennebula/virtual_network.rb, line 323 def rename(name) return call(VN_METHODS[:rename], @pe_id, name) end
Renames this virtual network
@param name [String] New name for the virtual network.
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
Source
# File lib/opennebula/virtual_network.rb, line 251 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 a set of addresses from this virtual network @param rname [String] of the reservation @param rsize number of addresses to reserve @param ar_id the ar_id to make the reservation. If set to nil
any address range will be used
@param addr [String] the first address in the reservation. If set to
nil the first free address will be used
@param vnet [String] ID of the VNET to add the reservation to. If not
set a new VNET will be created.
@return [Integer, OpenNebula::Error
] The reservation vnet id on
success, Error otherwise
Source
# File lib/opennebula/virtual_network.rb, line 270 def reserve_with_extra(extra) return Error.new('ID not defined') unless @pe_id @client.call(VN_METHODS[:reserve], @pe_id, extra) end
Source
# File lib/opennebula/virtual_network.rb, line 163 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
Removes an Address Range from the VirtualNetwork
Source
# File lib/opennebula/virtual_network.rb, line 174 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
Simulates old rmleases call @deprecated use #{rm_ar}
Source
# File lib/opennebula/virtual_network.rb, line 377 def short_state_str SHORT_VN_STATES[state_str] end
Returns the state of the Virtual Network (string value)
Source
# File lib/opennebula/virtual_network.rb, line 367 def state self['STATE'].to_i end
Returns the state of the Virtual Network (numeric value)
Source
# File lib/opennebula/virtual_network.rb, line 372 def state_str VN_STATES[state] end
Returns the state of the Virtual Network (string value)
Source
# File lib/opennebula/virtual_network.rb, line 123 def unpublish set_publish(false) end
Unplubishes the VirtualNetwork
Source
# File lib/opennebula/virtual_network.rb, line 113 def update(new_template=nil, append=false) super(VN_METHODS[:update], new_template, append ? 1 : 0) end
Replaces the template contents
@param new_template [String] New template contents @param append [true, false] True to append new attributes instead of
replace the whole template
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
OpenNebula::PoolElement#update
Source
# File lib/opennebula/virtual_network.rb, line 189 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
Updates Address Ranges from the VirtualNetwork
Source
# File lib/opennebula/virtual_network.rb, line 383 def vm_ids updated = Array.new self.each('UPDATED_VMS/ID') do |id| updated << id.text.to_i end outdated = Array.new self.each('OUTDATED_VMS/ID') do |id| outdated << id.text.to_i end self.each('UPDATING_VMS/ID') do |id| outdated << id.text.to_i end error = Array.new self.each('ERROR_VMS/ID') do |id| error << id.text.to_i end [updated, outdated, error] end
Returns three arrays with the numeric VM IDs for VMs updated, outdated (include updating) and error
Source
# File lib/opennebula/virtual_network.rb, line 356 def vrouter_ids array = Array.new self.each("VROUTERS/ID") do |id| array << id.text.to_i end return array end
Returns an array with the numeric virtual router ids
Private Instance Methods
Source
# File lib/opennebula/virtual_network.rb, line 419 def address_type(addr) begin ipaddr = IPAddr.new addr if ipaddr.ipv4? return "IP" elsif ipaddr.ipv6? return "IP6" else return Error.new('Unknown IP type') end rescue if /^(\h{2}:){5}\h{2}$/ =~ addr return "MAC" else return Error.new('Unknown address type') end end end
Returns the OpenNebula
name of the address to use it in LEASE attributes. MAC, IP or IP6 is returned for MAC addresses in colon notation, ipv4 and ipv6 respectively
Source
# File lib/opennebula/virtual_network.rb, line 410 def set_publish(published) group_u = published ? 1 : 0 chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1) end