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", :publish => "template.publish", :delete => "template.delete", :chown => "template.chown", :chmod => "template.chmod" }
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.
-
#delete ⇒ Object
Deletes the Template.
-
#gid ⇒ Object
Returns the group identifier [return] Integer the element’s group ID.
-
#info ⇒ Object
Retrieves the information of the given Template.
-
#initialize(xml, client) ⇒ Template
constructor
Class constructor.
-
#instantiate(name = "") ⇒ Object
Creates a VM instance from a Template.
- #owner_id ⇒ Object
- #public? ⇒ Boolean
-
#publish ⇒ Object
Publishes the Template, to be used by other users.
-
#unpublish ⇒ Object
Unplubishes the Image.
-
#update(new_template) ⇒ Object
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, #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
56 57 58 59 60 |
# File 'lib/OpenNebula/Template.rb', line 56 def initialize(xml, client) super(xml,client) @client = client end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/OpenNebula/Template.rb', line 45 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
77 78 79 |
# File 'lib/OpenNebula/Template.rb', line 77 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
140 141 142 143 144 |
# File 'lib/OpenNebula/Template.rb', line 140 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.
131 132 133 |
# File 'lib/OpenNebula/Template.rb', line 131 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
122 123 124 |
# File 'lib/OpenNebula/Template.rb', line 122 def chown(uid, gid) super(TEMPLATE_METHODS[:chown], uid, gid) end |
#delete ⇒ Object
Deletes the Template
82 83 84 |
# File 'lib/OpenNebula/Template.rb', line 82 def delete() super(TEMPLATE_METHODS[:delete]) end |
#gid ⇒ Object
Returns the group identifier
- return
-
Integer the element’s group ID
152 153 154 |
# File 'lib/OpenNebula/Template.rb', line 152 def gid self['GID'].to_i end |
#info ⇒ Object
Retrieves the information of the given Template.
67 68 69 |
# File 'lib/OpenNebula/Template.rb', line 67 def info() super(TEMPLATE_METHODS[:info], 'VMTEMPLATE') end |
#instantiate(name = "") ⇒ Object
Creates a VM instance from a Template
name
A string containing the name of the VM instance.
- return
-
The new VM Instance ID, or an Error object
90 91 92 93 94 95 96 97 |
# File 'lib/OpenNebula/Template.rb', line 90 def instantiate(name="") return Error.new('ID not defined') if !@pe_id name ||= "" rc = @client.call(TEMPLATE_METHODS[:instantiate], @pe_id, name) return rc end |
#owner_id ⇒ Object
156 157 158 |
# File 'lib/OpenNebula/Template.rb', line 156 def owner_id self['UID'].to_i end |
#public? ⇒ Boolean
160 161 162 163 164 165 166 |
# File 'lib/OpenNebula/Template.rb', line 160 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
109 110 111 |
# File 'lib/OpenNebula/Template.rb', line 109 def publish set_publish(true) end |
#unpublish ⇒ Object
Unplubishes the Image
114 115 116 |
# File 'lib/OpenNebula/Template.rb', line 114 def unpublish set_publish(false) end |
#update(new_template) ⇒ Object
Replaces the template contents
new_template
New template contents
102 103 104 105 106 |
# File 'lib/OpenNebula/Template.rb', line 102 def update(new_template) return Error.new('ID not defined') if !@pe_id super(TEMPLATE_METHODS[:update], new_template) end |