Class: OpenNebula::Template
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::Template
- Defined in:
- lib/opennebula/template.rb
Constant Summary collapse
- TEMPLATE_METHODS =
Constants and Class Methods
{ :allocate => "template.allocate", :instantiate => "template.instantiate", :info => "template.info", :update => "template.update", :delete => "template.delete", :chown => "template.chown", :chmod => "template.chmod", :clone => "template.clone", :rename => "template.rename", :lock => "template.lock", :unlock => "template.unlock" }
Instance Attribute Summary
Attributes inherited from PoolElement
Class Method Summary collapse
-
.build_xml(pe_id = nil) ⇒ Object
Creates a Template description with just its identifier this method should be used to create plain Template objects.
Instance Method Summary collapse
-
#allocate(description) ⇒ nil, OpenNebula::Error
Allocates a new Template 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 Template permissions.
-
#chmod_octet(octet, recursive = false) ⇒ nil, OpenNebula::Error
Changes the Template permissions.
-
#chown(uid, gid) ⇒ Object
- Changes the owner/group uid
-
Integer the new owner id.
-
#clone(name, recursive = false) ⇒ Integer, OpenNebula::Error
Clones this Template into a new one.
-
#delete(recursive = false) ⇒ nil, OpenNebula::Error
Deletes the Template.
-
#gid ⇒ Object
Returns the group identifier [return] Integer the element’s group ID.
-
#info(extended = false, decrypt = false) ⇒ Object
(also: #info!)
Retrieves the information of the given Template.
-
#initialize(xml, client) ⇒ Template
constructor
Class constructor.
-
#instantiate(name = "", hold = false, template = "", persistent = false) ⇒ Integer, OpenNebula::Error
Creates a VM instance from a Template.
- #owner_id ⇒ Object
- #public? ⇒ Boolean
-
#publish ⇒ Object
Publishes the Template, to be used by other users.
-
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Template.
-
#unpublish ⇒ Object
Unplubishes the Image.
-
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the template 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) ⇒ Template
Class constructor
58 59 60 61 62 63 64 |
# File 'lib/opennebula/template.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
47 48 49 50 51 52 53 54 55 |
# File 'lib/opennebula/template.rb', line 47 def Template.build_xml(pe_id=nil) if pe_id obj_xml = "<VMTEMPLATE><ID>#{pe_id}</ID></VMTEMPLATE>" else obj_xml = "<VMTEMPLATE></VMTEMPLATE>" end XMLElement.build_xml(obj_xml,'VMTEMPLATE') end |
Instance Method Details
#allocate(description) ⇒ nil, OpenNebula::Error
Allocates a new Template in OpenNebula
97 98 99 |
# File 'lib/opennebula/template.rb', line 97 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 Template permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
any image defined in DISK.
201 202 203 204 205 |
# File 'lib/opennebula/template.rb', line 201 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 Template permissions.
any image defined in DISK.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/opennebula/template.rb', line 178 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
166 167 168 |
# File 'lib/opennebula/template.rb', line 166 def chown(uid, gid) super(TEMPLATE_METHODS[:chown], uid, gid) end |
#clone(name, recursive = false) ⇒ Integer, OpenNebula::Error
Clones this Template into a new one
any image defined in DISK. The new IMAGE_ID is set into each DISK.
215 216 217 218 219 220 221 |
# File 'lib/opennebula/template.rb', line 215 def clone(name, recursive=false) return Error.new('ID not defined') if !@pe_id rc = @client.call(TEMPLATE_METHODS[:clone], @pe_id, name, recursive) return rc end |
#delete(recursive = false) ⇒ nil, OpenNebula::Error
Deletes the Template
any image defined in DISK.
108 109 110 |
# File 'lib/opennebula/template.rb', line 108 def delete(recursive=false) return call(TEMPLATE_METHODS[:delete], @pe_id, recursive) end |
#gid ⇒ Object
Returns the group identifier
- return
-
Integer the element’s group ID
239 240 241 |
# File 'lib/opennebula/template.rb', line 239 def gid self['GID'].to_i end |
#info(extended = false, decrypt = false) ⇒ Object Also known as: info!
Retrieves the information of the given Template. include extended information, such as the SIZE for each DISK
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/opennebula/template.rb', line 73 def info(extended=false, decrypt=false) return Error.new('ID not defined') if !@pe_id rc = @client.call(TEMPLATE_METHODS[:info], @pe_id, extended, decrypt) if !OpenNebula.is_error?(rc) initialize_xml(rc, 'VMTEMPLATE') rc = nil @pe_id = self['ID'].to_i if self['ID'] @name = self['NAME'] if self['NAME'] end return rc end |
#instantiate(name = "", hold = false, template = "", persistent = false) ⇒ Integer, OpenNebula::Error
Creates a VM instance from a Template
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/opennebula/template.rb', line 126 def instantiate(name="", hold=false, template="", persistent=false) return Error.new('ID not defined') if !@pe_id name ||= "" hold = false if hold.nil? template ||= "" persistent = false if persistent.nil? rc = @client.call(TEMPLATE_METHODS[:instantiate], @pe_id, name, hold, template, persistent) return rc end |
#owner_id ⇒ Object
243 244 245 |
# File 'lib/opennebula/template.rb', line 243 def owner_id self['UID'].to_i end |
#public? ⇒ Boolean
247 248 249 250 251 252 253 |
# File 'lib/opennebula/template.rb', line 247 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
153 154 155 |
# File 'lib/opennebula/template.rb', line 153 def publish set_publish(true) end |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Template
229 230 231 |
# File 'lib/opennebula/template.rb', line 229 def rename(name) return call(TEMPLATE_METHODS[:rename], @pe_id, name) end |
#unpublish ⇒ Object
Unplubishes the Image
158 159 160 |
# File 'lib/opennebula/template.rb', line 158 def unpublish set_publish(false) end |
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents
148 149 150 |
# File 'lib/opennebula/template.rb', line 148 def update(new_template, append=false) super(TEMPLATE_METHODS[:update], new_template, append ? 1 : 0) end |