Class: OpenNebula::VirtualNetwork
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::VirtualNetwork
- Defined in:
- lib/OpenNebula/VirtualNetwork.rb
Constant Summary collapse
- VN_METHODS =
Constants and Class Methods
{ :info => "vn.info", :allocate => "vn.allocate", :publish => "vn.publish", :delete => "vn.delete", :addleases => "vn.addleases", :rmleases => "vn.rmleases", :chown => "vn.chown" }
- 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) ⇒ Object
Allocates a new VirtualNetwork in OpenNebula.
-
#chown(uid, gid) ⇒ Object
- Changes the owner/group uid
-
Integer the new owner id.
-
#delete ⇒ Object
Deletes the VirtualNetwork.
-
#gid ⇒ Object
Returns the group identifier [return] Integer the element’s group ID.
-
#info ⇒ Object
Retrieves the information of the given VirtualNetwork.
-
#initialize(xml, client) ⇒ VirtualNetwork
constructor
Class constructor.
-
#publish ⇒ Object
Publishes the VirtualNetwork, to be used by other users.
-
#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.
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
#initialize(xml, client) ⇒ VirtualNetwork
Class constructor
59 60 61 62 63 |
# File 'lib/OpenNebula/VirtualNetwork.rb', line 59 def initialize(xml, client) super(xml,client) @client = 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)
48 49 50 51 52 53 54 55 56 |
# File 'lib/OpenNebula/VirtualNetwork.rb', line 48 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
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/OpenNebula/VirtualNetwork.rb', line 97 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) ⇒ Object
Allocates a new VirtualNetwork in OpenNebula
description A string containing the template of the VirtualNetwork.
77 78 79 |
# File 'lib/OpenNebula/VirtualNetwork.rb', line 77 def allocate(description) super(VN_METHODS[:allocate],description) end |
#chown(uid, gid) ⇒ Object
Changes the owner/group
- uid
-
Integer the new owner id. Set to -1 to leave the current one
- gid
-
Integer the new group id. Set to -1 to leave the current one
- return
-
nil in case of success or an Error object
126 127 128 |
# File 'lib/OpenNebula/VirtualNetwork.rb', line 126 def chown(uid, gid) super(VN_METHODS[:chown], uid, gid) end |
#delete ⇒ Object
Deletes the VirtualNetwork
92 93 94 |
# File 'lib/OpenNebula/VirtualNetwork.rb', line 92 def delete() super(VN_METHODS[:delete]) end |
#gid ⇒ Object
Returns the group identifier
- return
-
Integer the element’s group ID
136 137 138 |
# File 'lib/OpenNebula/VirtualNetwork.rb', line 136 def gid self['GID'].to_i end |
#info ⇒ Object
Retrieves the information of the given VirtualNetwork.
70 71 72 |
# File 'lib/OpenNebula/VirtualNetwork.rb', line 70 def info() super(VN_METHODS[:info], 'VNET') end |
#publish ⇒ Object
Publishes the VirtualNetwork, to be used by other users
82 83 84 |
# File 'lib/OpenNebula/VirtualNetwork.rb', line 82 def publish set_publish(true) end |
#rmleases(ip) ⇒ Object
Removes a lease from the VirtualNetwork
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/OpenNebula/VirtualNetwork.rb', line 111 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)
151 152 153 |
# File 'lib/OpenNebula/VirtualNetwork.rb', line 151 def short_type_str SHORT_VN_TYPES[type_str] end |
#type ⇒ Object
Returns the type of the Virtual Network (numeric value)
141 142 143 |
# File 'lib/OpenNebula/VirtualNetwork.rb', line 141 def type self['TYPE'].to_i end |
#type_str ⇒ Object
Returns the type of the Virtual Network (string value)
146 147 148 |
# File 'lib/OpenNebula/VirtualNetwork.rb', line 146 def type_str VN_TYPES[type] end |
#unpublish ⇒ Object
Unplubishes the VirtualNetwork
87 88 89 |
# File 'lib/OpenNebula/VirtualNetwork.rb', line 87 def unpublish set_publish(false) end |