Class: OpenNebula::VirtualNetwork
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::VirtualNetwork
- Defined in:
- lib/opennebula/virtual_network.rb
Constant Summary collapse
- VN_METHODS =
{ :info => "vn.info", :allocate => "vn.allocate", :delete => "vn.delete", :addleases => "vn.addleases", :rmleases => "vn.rmleases", :chown => "vn.chown", :chmod => "vn.chmod", :update => "vn.update", :hold => "vn.hold", :release => "vn.release", :rename => "vn.rename" }
- VN_TYPES =
%w{RANGED FIXED}
- SHORT_VN_TYPES =
{ "RANGED" => "R", "FIXED" => "F" }
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
-
#addleases(ip, mac = nil) ⇒ Object
Adds a lease to the VirtualNetwork.
-
#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.
-
#gid ⇒ Object
Returns the group identifier [return] Integer the element’s group ID.
-
#hold(ip) ⇒ Object
Holds a virtual network Lease as used.
-
#info ⇒ 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.
-
#release(ip) ⇒ Object
Releases a virtual network Lease on hold.
-
#rename(name) ⇒ nil, OpenNebula::Error
Renames this virtual network.
-
#rmleases(ip) ⇒ Object
Removes a lease from the VirtualNetwork.
-
#short_type_str ⇒ Object
Returns the state of the Virtual Network (string value).
-
#type ⇒ Object
Returns the type of the Virtual Network (numeric value).
-
#type_str ⇒ Object
Returns the type of the Virtual Network (string value).
-
#unpublish ⇒ Object
Unplubishes the VirtualNetwork.
-
#update(new_template = nil, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents.
Methods inherited from PoolElement
#id, #name, new_with_id, #to_str
Methods inherited from XMLElement
#[], #add_element, #attr, #delete_element, #each, #each_xpath, #element_xml, #has_elements?, #initialize_xml, #name, #retrieve_elements, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml
Constructor Details
#initialize(xml, client) ⇒ VirtualNetwork
Class constructor
66 67 68 |
# File 'lib/opennebula/virtual_network.rb', line 66 def initialize(xml, client) 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)
55 56 57 58 59 60 61 62 63 |
# File 'lib/opennebula/virtual_network.rb', line 55 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
#addleases(ip, mac = nil) ⇒ Object
Adds a lease to the VirtualNetwork
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/opennebula/virtual_network.rb', line 120 def addleases(ip, mac = nil) return Error.new('ID not defined') if !@pe_id lease_template = "LEASES = [ IP = #{ip}" lease_template << ", MAC = #{mac}" if mac lease_template << " ]" rc = @client.call(VN_METHODS[:addleases], @pe_id, lease_template) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#allocate(description, cluster_id = ClusterPool::NONE_CLUSTER_ID) ⇒ Integer, OpenNebula::Error
Allocates a new VirtualNetwork in OpenNebula
88 89 90 |
# File 'lib/opennebula/virtual_network.rb', line 88 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
196 197 198 199 200 |
# File 'lib/opennebula/virtual_network.rb', line 196 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.
187 188 189 |
# File 'lib/opennebula/virtual_network.rb', line 187 def chmod_octet(octet) super(VN_METHODS[:chmod], octet) end |
#chown(uid, gid) ⇒ nil, OpenNebula::Error
Changes the owner/group
178 179 180 |
# File 'lib/opennebula/virtual_network.rb', line 178 def chown(uid, gid) super(VN_METHODS[:chown], uid, gid) end |
#delete ⇒ Object
Deletes the VirtualNetwork
115 116 117 |
# File 'lib/opennebula/virtual_network.rb', line 115 def delete() super(VN_METHODS[:delete]) end |
#gid ⇒ Object
Returns the group identifier
- return
-
Integer the element’s group ID
218 219 220 |
# File 'lib/opennebula/virtual_network.rb', line 218 def gid self['GID'].to_i end |
#hold(ip) ⇒ Object
Holds a virtual network Lease as used
147 148 149 150 151 152 153 154 155 156 |
# File 'lib/opennebula/virtual_network.rb', line 147 def hold(ip) return Error.new('ID not defined') if !@pe_id lease_template = "LEASES = [ IP = #{ip} ]" rc = @client.call(VN_METHODS[:hold], @pe_id, lease_template) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#info ⇒ Object Also known as: info!
Retrieves the information of the given VirtualNetwork.
75 76 77 |
# File 'lib/opennebula/virtual_network.rb', line 75 def info() super(VN_METHODS[:info], 'VNET') end |
#public? ⇒ Boolean
237 238 239 240 241 242 243 |
# File 'lib/opennebula/virtual_network.rb', line 237 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
105 106 107 |
# File 'lib/opennebula/virtual_network.rb', line 105 def publish set_publish(true) end |
#release(ip) ⇒ Object
Releases a virtual network Lease on hold
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/opennebula/virtual_network.rb', line 160 def release(ip) return Error.new('ID not defined') if !@pe_id lease_template = "LEASES = [ IP = #{ip} ]" 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
208 209 210 |
# File 'lib/opennebula/virtual_network.rb', line 208 def rename(name) return call(VN_METHODS[:rename], @pe_id, name) end |
#rmleases(ip) ⇒ Object
Removes a lease from the VirtualNetwork
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/opennebula/virtual_network.rb', line 134 def rmleases(ip) return Error.new('ID not defined') if !@pe_id lease_template = "LEASES = [ IP = #{ip} ]" rc = @client.call(VN_METHODS[:rmleases], @pe_id, lease_template) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#short_type_str ⇒ Object
Returns the state of the Virtual Network (string value)
233 234 235 |
# File 'lib/opennebula/virtual_network.rb', line 233 def short_type_str SHORT_VN_TYPES[type_str] end |
#type ⇒ Object
Returns the type of the Virtual Network (numeric value)
223 224 225 |
# File 'lib/opennebula/virtual_network.rb', line 223 def type self['TYPE'].to_i end |
#type_str ⇒ Object
Returns the type of the Virtual Network (string value)
228 229 230 |
# File 'lib/opennebula/virtual_network.rb', line 228 def type_str VN_TYPES[type] end |
#unpublish ⇒ Object
Unplubishes the VirtualNetwork
110 111 112 |
# File 'lib/opennebula/virtual_network.rb', line 110 def unpublish set_publish(false) end |
#update(new_template = nil, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents
100 101 102 |
# File 'lib/opennebula/virtual_network.rb', line 100 def update(new_template=nil, append=false) super(VN_METHODS[:update], new_template, append ? 1 : 0) end |