Class: OpenNebula::VNTemplate
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::VNTemplate
- Defined in:
- lib/opennebula/vntemplate.rb
Constant Summary collapse
- TEMPLATE_METHODS =
Constants and Class Methods
{ :allocate => "vntemplate.allocate", :instantiate => "vntemplate.instantiate", :info => "vntemplate.info", :update => "vntemplate.update", :delete => "vntemplate.delete", :chown => "vntemplate.chown", :chmod => "vntemplate.chmod", :clone => "vntemplate.clone", :rename => "vntemplate.rename", :lock => "vntemplate.lock", :unlock => "vntemplate.unlock" }
Instance Attribute Summary
Attributes inherited from PoolElement
Class Method Summary collapse
-
.build_xml(pe_id = nil) ⇒ Object
Creates a VNTemplate description with just its identifier this method should be used to create plain VNTemplate objects.
Instance Method Summary collapse
-
#allocate(description) ⇒ nil, OpenNebula::Error
Allocates a new VNTemplate in OpenNebula.
-
#chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a, recursive = false) ⇒ nil, OpenNebula::Error
Changes the VNTemplate permissions.
-
#chmod_octet(octet, recursive = false) ⇒ nil, OpenNebula::Error
Changes the VNTemplate permissions.
-
#chown(uid, gid) ⇒ Object
- Changes the owner/group uid
-
Integer the new owner id.
-
#clone(name) ⇒ Integer, OpenNebula::Error
Clones this VNTemplate into a new one.
-
#delete ⇒ nil, OpenNebula::Error
Deletes the Template.
-
#gid ⇒ Object
Returns the group identifier [return] Integer the element’s group ID.
-
#info(decrypt = false) ⇒ Object
(also: #info!)
Retrieves the information of the given VNTemplate.
-
#initialize(xml, client) ⇒ VNTemplate
constructor
Class constructor.
-
#instantiate(name = "", template = "") ⇒ Integer, OpenNebula::Error
Creates a VNet instance from a VNTemplate.
- #owner_id ⇒ Object
- #public? ⇒ Boolean
-
#publish ⇒ Object
Publishes the Template, to be used by other users.
-
#rename(name) ⇒ nil, OpenNebula::Error
Renames this VNTemplate.
-
#unpublish ⇒ Object
Unplubishes the Image.
-
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the vntemplate contents.
Methods inherited from PoolElement
#id, 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) ⇒ VNTemplate
Class constructor
58 59 60 61 62 63 64 |
# File 'lib/opennebula/vntemplate.rb', line 58 def initialize(xml, client) LockableExt.make_lockable(self, TEMPLATE_METHODS) super(xml,client) @client = client end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
Creates a VNTemplate description with just its identifier this method should be used to create plain VNTemplate objects. id
the id of the user
Example:
vntemplate = VNTemplate.new(VNTemplate.build_xml(3),rpc_client)
47 48 49 50 51 52 53 54 55 |
# File 'lib/opennebula/vntemplate.rb', line 47 def VNTemplate.build_xml(pe_id=nil) if pe_id obj_xml = "<VNTEMPLATE><ID>#{pe_id}</ID></VNTEMPLATE>" else obj_xml = "<VNTEMPLATE></VNTEMPLATE>" end XMLElement.build_xml(obj_xml,'VNTEMPLATE') end |
Instance Method Details
#allocate(description) ⇒ nil, OpenNebula::Error
Allocates a new VNTemplate in OpenNebula
96 97 98 |
# File 'lib/opennebula/vntemplate.rb', line 96 def allocate(description) super(TEMPLATE_METHODS[:allocate], description) end |
#chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a, recursive = false) ⇒ nil, OpenNebula::Error
Changes the VNTemplate permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
any image defined in DISK.
190 191 192 193 194 |
# File 'lib/opennebula/vntemplate.rb', line 190 def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a, recursive=false) return call(TEMPLATE_METHODS[:chmod], @pe_id, owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a, recursive) end |
#chmod_octet(octet, recursive = false) ⇒ nil, OpenNebula::Error
Changes the VNTemplate permissions.
any image defined in DISK.
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/opennebula/vntemplate.rb', line 167 def chmod_octet(octet, recursive=false) owner_u = octet[0..0].to_i & 4 != 0 ? 1 : 0 owner_m = octet[0..0].to_i & 2 != 0 ? 1 : 0 owner_a = octet[0..0].to_i & 1 != 0 ? 1 : 0 group_u = octet[1..1].to_i & 4 != 0 ? 1 : 0 group_m = octet[1..1].to_i & 2 != 0 ? 1 : 0 group_a = octet[1..1].to_i & 1 != 0 ? 1 : 0 other_u = octet[2..2].to_i & 4 != 0 ? 1 : 0 other_m = octet[2..2].to_i & 2 != 0 ? 1 : 0 other_a = octet[2..2].to_i & 1 != 0 ? 1 : 0 chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a, recursive) 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
155 156 157 |
# File 'lib/opennebula/vntemplate.rb', line 155 def chown(uid, gid) super(TEMPLATE_METHODS[:chown], uid, gid) end |
#clone(name) ⇒ Integer, OpenNebula::Error
Clones this VNTemplate into a new one
any image defined in DISK. The new IMAGE_ID is set into each DISK.
203 204 205 206 207 208 209 |
# File 'lib/opennebula/vntemplate.rb', line 203 def clone(name) return Error.new('ID not defined') if !@pe_id rc = @client.call(TEMPLATE_METHODS[:clone], @pe_id, name, false) return rc end |
#delete ⇒ nil, OpenNebula::Error
Deletes the Template
104 105 106 |
# File 'lib/opennebula/vntemplate.rb', line 104 def delete() return call(TEMPLATE_METHODS[:delete], @pe_id, false) end |
#gid ⇒ Object
Returns the group identifier
- return
-
Integer the element’s group ID
227 228 229 |
# File 'lib/opennebula/vntemplate.rb', line 227 def gid self['GID'].to_i end |
#info(decrypt = false) ⇒ Object Also known as: info!
Retrieves the information of the given VNTemplate. include extended information, such as the SIZE for each DISK
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/opennebula/vntemplate.rb', line 72 def info(decrypt = false) return Error.new('ID not defined') if !@pe_id rc = @client.call(TEMPLATE_METHODS[:info], @pe_id, decrypt) if !OpenNebula.is_error?(rc) initialize_xml(rc, 'VNTEMPLATE') rc = nil @pe_id = self['ID'].to_i if self['ID'] @name = self['NAME'] if self['NAME'] end return rc end |
#instantiate(name = "", template = "") ⇒ Integer, OpenNebula::Error
Creates a VNet instance from a VNTemplate
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/opennebula/vntemplate.rb', line 117 def instantiate(name="", template="") return Error.new('ID not defined') if !@pe_id name ||= "" template ||= "" rc = @client.call(TEMPLATE_METHODS[:instantiate], @pe_id, name, template) return rc end |
#owner_id ⇒ Object
231 232 233 |
# File 'lib/opennebula/vntemplate.rb', line 231 def owner_id self['UID'].to_i end |
#public? ⇒ Boolean
235 236 237 238 239 240 241 |
# File 'lib/opennebula/vntemplate.rb', line 235 def public? if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1" true else false end end |
#publish ⇒ Object
Publishes the Template, to be used by other users
142 143 144 |
# File 'lib/opennebula/vntemplate.rb', line 142 def publish set_publish(true) end |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this VNTemplate
217 218 219 |
# File 'lib/opennebula/vntemplate.rb', line 217 def rename(name) return call(TEMPLATE_METHODS[:rename], @pe_id, name) end |
#unpublish ⇒ Object
Unplubishes the Image
147 148 149 |
# File 'lib/opennebula/vntemplate.rb', line 147 def unpublish set_publish(false) end |
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the vntemplate contents
137 138 139 |
# File 'lib/opennebula/vntemplate.rb', line 137 def update(new_template, append=false) super(TEMPLATE_METHODS[:update], new_template, append ? 1 : 0) end |