Class: OpenNebula::VirtualNetwork

Inherits:
PoolElement show all
Defined in:
lib/OpenNebula/VirtualNetwork.rb

Constant Summary

VN_METHODS =
{
    :info       => "vn.info",
    :allocate   => "vn.allocate",
    :publish    => "vn.publish",
    :delete     => "vn.delete",
    :addleases  => "vn.addleases",
    :rmleases   => "vn.rmleases",
    :chown      => "vn.chown",
    :chmod      => "vn.chmod",
    :update     => "vn.update",
    :hold       => "vn.hold",
    :release    => "vn.release"
}
VN_TYPES =
%w{RANGED FIXED}
SHORT_VN_TYPES =
{
    "RANGED" => "R",
    "FIXED"  => "F"
}

Class Method Summary collapse

Instance Method Summary collapse

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



66
67
68
# File 'lib/OpenNebula/VirtualNetwork.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/VirtualNetwork.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



109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/OpenNebula/VirtualNetwork.rb', line 109

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.



82
83
84
# File 'lib/OpenNebula/VirtualNetwork.rb', line 82

def allocate(description)
    super(VN_METHODS[:allocate],description)
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

Returns:



182
183
184
185
186
# File 'lib/OpenNebula/VirtualNetwork.rb', line 182

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.

Parameters:

  • octet (String)

    Permissions octed , e.g. 640

Returns:



173
174
175
# File 'lib/OpenNebula/VirtualNetwork.rb', line 173

def chmod_octet(octet)
    super(VN_METHODS[:chmod], octet)
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



164
165
166
# File 'lib/OpenNebula/VirtualNetwork.rb', line 164

def chown(uid, gid)
    super(VN_METHODS[:chown], uid, gid)
end

#deleteObject

Deletes the VirtualNetwork



104
105
106
# File 'lib/OpenNebula/VirtualNetwork.rb', line 104

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

#gidObject

Returns the group identifier [return] Integer the element's group ID



194
195
196
# File 'lib/OpenNebula/VirtualNetwork.rb', line 194

def gid
    self['GID'].to_i
end

#hold(ip) ⇒ Object

Holds a virtual network Lease as used

Parameters:

  • ip (String)

    IP to hold



136
137
138
139
140
141
142
143
144
145
# File 'lib/OpenNebula/VirtualNetwork.rb', line 136

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

#infoObject

Retrieves the information of the given VirtualNetwork.



75
76
77
# File 'lib/OpenNebula/VirtualNetwork.rb', line 75

def info()
    super(VN_METHODS[:info], 'VNET')
end

#public?Boolean

Returns:

  • (Boolean)


213
214
215
216
217
218
219
# File 'lib/OpenNebula/VirtualNetwork.rb', line 213

def public?
    if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
        true
    else
        false
    end
end

#publishObject

Publishes the VirtualNetwork, to be used by other users



94
95
96
# File 'lib/OpenNebula/VirtualNetwork.rb', line 94

def publish
    set_publish(true)
end

#release(ip) ⇒ Object

Releases a virtual network Lease on hold

Parameters:

  • ip (String)

    IP to release



149
150
151
152
153
154
155
156
157
158
# File 'lib/OpenNebula/VirtualNetwork.rb', line 149

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

#rmleases(ip) ⇒ Object

Removes a lease from the VirtualNetwork



123
124
125
126
127
128
129
130
131
132
# File 'lib/OpenNebula/VirtualNetwork.rb', line 123

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_strObject

Returns the state of the Virtual Network (string value)



209
210
211
# File 'lib/OpenNebula/VirtualNetwork.rb', line 209

def short_type_str
    SHORT_VN_TYPES[type_str]
end

#typeObject

Returns the type of the Virtual Network (numeric value)



199
200
201
# File 'lib/OpenNebula/VirtualNetwork.rb', line 199

def type
    self['TYPE'].to_i
end

#type_strObject

Returns the type of the Virtual Network (string value)



204
205
206
# File 'lib/OpenNebula/VirtualNetwork.rb', line 204

def type_str
    VN_TYPES[type]
end

#unpublishObject

Unplubishes the VirtualNetwork



99
100
101
# File 'lib/OpenNebula/VirtualNetwork.rb', line 99

def unpublish
    set_publish(false)
end

#update(new_template) ⇒ Object

Replaces the template contents

+new_template+ New template contents



89
90
91
# File 'lib/OpenNebula/VirtualNetwork.rb', line 89

def update(new_template)
    super(VN_METHODS[:update], new_template)
end