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 ⇒ 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
80 81 82 |
# File 'lib/opennebula/template.rb', line 80 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
157 158 159 160 161 |
# File 'lib/opennebula/template.rb', line 157 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.
148 149 150 |
# File 'lib/opennebula/template.rb', line 148 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
139 140 141 |
# File 'lib/opennebula/template.rb', line 139 def chown(uid, gid) super(TEMPLATE_METHODS[:chown], uid, gid) end |
#clone(name) ⇒ Integer, OpenNebula::Error
Clones this Template into a new one
169 170 171 172 173 174 175 |
# File 'lib/opennebula/template.rb', line 169 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
85 86 87 |
# File 'lib/opennebula/template.rb', line 85 def delete() super(TEMPLATE_METHODS[:delete]) end |
#gid ⇒ Object
Returns the group identifier
- return
-
Integer the element’s group ID
193 194 195 |
# File 'lib/opennebula/template.rb', line 193 def gid self['GID'].to_i end |
#info ⇒ Object Also known as: info!
Retrieves the information of the given Template.
68 69 70 |
# File 'lib/opennebula/template.rb', line 68 def info() super(TEMPLATE_METHODS[:info], 'VMTEMPLATE') end |
#instantiate(name = "", hold = false, template = "") ⇒ Integer, OpenNebula::Error
Creates a VM instance from a Template
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/opennebula/template.rb', line 100 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
197 198 199 |
# File 'lib/opennebula/template.rb', line 197 def owner_id self['UID'].to_i end |
#public? ⇒ Boolean
201 202 203 204 205 206 207 |
# File 'lib/opennebula/template.rb', line 201 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
126 127 128 |
# File 'lib/opennebula/template.rb', line 126 def publish set_publish(true) end |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Template
183 184 185 |
# File 'lib/opennebula/template.rb', line 183 def rename(name) return call(TEMPLATE_METHODS[:rename], @pe_id, name) end |
#unpublish ⇒ Object
Unplubishes the Image
131 132 133 |
# File 'lib/opennebula/template.rb', line 131 def unpublish set_publish(false) end |
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents
121 122 123 |
# File 'lib/opennebula/template.rb', line 121 def update(new_template, append=false) super(TEMPLATE_METHODS[:update], new_template, append ? 1 : 0) end |