Class: OpenNebula::Template
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::Template
- Defined in:
- lib/opennebula/template.rb
Constant Summary collapse
- TEMPLATE_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" }
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) ⇒ nil, OpenNebula::Error
Changes the Template permissions.
-
#chmod_octet(octet) ⇒ nil, OpenNebula::Error
Changes the Template permissions.
-
#chown(uid, gid) ⇒ Object
- Changes the owner/group uid
-
Integer the new owner id.
-
#clone(name) ⇒ Integer, OpenNebula::Error
Clones this Template into a new one.
-
#delete ⇒ Object
Deletes the Template.
-
#gid ⇒ Object
Returns the group identifier [return] Integer the element’s group ID.
-
#info(extended = false) ⇒ Object
(also: #info!)
Retrieves the information of the given Template.
-
#initialize(xml, client) ⇒ Template
constructor
Class constructor.
-
#instantiate(name = "", hold = false, template = "") ⇒ 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, #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) ⇒ Template
Class constructor
57 58 59 60 61 |
# File 'lib/opennebula/template.rb', line 57 def initialize(xml, client) super(xml,client) @client = client end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/opennebula/template.rb', line 46 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
94 95 96 |
# File 'lib/opennebula/template.rb', line 94 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) ⇒ nil, OpenNebula::Error
Changes the Template permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
171 172 173 174 175 |
# File 'lib/opennebula/template.rb', line 171 def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) super(TEMPLATE_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 Template permissions.
162 163 164 |
# File 'lib/opennebula/template.rb', line 162 def chmod_octet(octet) super(TEMPLATE_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
153 154 155 |
# File 'lib/opennebula/template.rb', line 153 def chown(uid, gid) super(TEMPLATE_METHODS[:chown], uid, gid) end |
#clone(name) ⇒ Integer, OpenNebula::Error
Clones this Template into a new one
183 184 185 186 187 188 189 |
# File 'lib/opennebula/template.rb', line 183 def clone(name) return Error.new('ID not defined') if !@pe_id rc = @client.call(TEMPLATE_METHODS[:clone], @pe_id, name) return rc end |
#delete ⇒ Object
Deletes the Template
99 100 101 |
# File 'lib/opennebula/template.rb', line 99 def delete() super(TEMPLATE_METHODS[:delete]) end |
#gid ⇒ Object
Returns the group identifier
- return
-
Integer the element’s group ID
207 208 209 |
# File 'lib/opennebula/template.rb', line 207 def gid self['GID'].to_i end |
#info(extended = false) ⇒ Object Also known as: info!
Retrieves the information of the given Template. include extended information, such as the SIZE for each DISK
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/opennebula/template.rb', line 70 def info(extended=false) return Error.new('ID not defined') if !@pe_id rc = @client.call(TEMPLATE_METHODS[:info], @pe_id, extended) 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 = "") ⇒ Integer, OpenNebula::Error
Creates a VM instance from a Template
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/opennebula/template.rb', line 114 def instantiate(name="", hold=false, template="") return Error.new('ID not defined') if !@pe_id name ||= "" hold = false if hold.nil? template ||= "" rc = @client.call( TEMPLATE_METHODS[:instantiate], @pe_id, name, hold, template) return rc end |
#owner_id ⇒ Object
211 212 213 |
# File 'lib/opennebula/template.rb', line 211 def owner_id self['UID'].to_i end |
#public? ⇒ Boolean
215 216 217 218 219 220 221 |
# File 'lib/opennebula/template.rb', line 215 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
140 141 142 |
# File 'lib/opennebula/template.rb', line 140 def publish set_publish(true) end |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Template
197 198 199 |
# File 'lib/opennebula/template.rb', line 197 def rename(name) return call(TEMPLATE_METHODS[:rename], @pe_id, name) end |
#unpublish ⇒ Object
Unplubishes the Image
145 146 147 |
# File 'lib/opennebula/template.rb', line 145 def unpublish set_publish(false) end |
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents
135 136 137 |
# File 'lib/opennebula/template.rb', line 135 def update(new_template, append=false) super(TEMPLATE_METHODS[:update], new_template, append ? 1 : 0) end |