Class: OpenNebula::Document
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::Document
- Defined in:
- lib/opennebula/document.rb
Overview
All subclasses must define the DOCUMENT_TYPE constant.
Direct Known Subclasses
Constant Summary collapse
- DOCUMENT_METHODS =
Constants and Class Methods
{ :allocate => "document.allocate", :delete => "document.delete", :info => "document.info", :update => "document.update", :chown => "document.chown", :chmod => "document.chmod", :clone => "document.clone", :rename => "document.rename" }
Class Method Summary collapse
-
.build_xml(pe_id = nil) ⇒ Nokogiri::XML::Node, REXML::Element
Creates a Document Object description with just its identifier this method should be used to create plain Document objects.
Instance Method Summary collapse
-
#allocate(description) ⇒ nil, OpenNebula::Error
Allocates a new Document 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 Document permissions.
-
#chmod_octet(octet) ⇒ nil, OpenNebula::Error
Changes the Document permissions.
-
#chown(uid, gid) ⇒ nil, OpenNebula::Error
Changes the owner/group.
-
#clone(name) ⇒ Integer, OpenNebula::Error
Clones this Document into a new one.
-
#delete ⇒ nil, OpenNebula::Error
Deletes the Document.
- #document_type ⇒ Object
-
#gid ⇒ Integer
Returns the group identifier.
-
#info ⇒ nil, OpenNebula::Error
(also: #info!)
Retrieves the information of the given Document.
-
#initialize(xml, client) ⇒ Document
constructor
Class constructor.
-
#owner_id ⇒ Integer
Returns the owner user ID.
-
#public? ⇒ true, false
Returns true if the GROUP_U permission bit is set.
-
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Document.
-
#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) ⇒ Document
Class constructor
75 76 77 |
# File 'lib/opennebula/document.rb', line 75 def initialize(xml, client) super(xml,client) end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Nokogiri::XML::Node, REXML::Element
Creates a Document Object description with just its identifier this method should be used to create plain Document objects.
55 56 57 58 59 60 61 62 63 |
# File 'lib/opennebula/document.rb', line 55 def Document.build_xml(pe_id=nil) if pe_id obj_xml = "<DOCUMENT><ID>#{pe_id}</ID></DOCUMENT>" else obj_xml = "<DOCUMENT></DOCUMENT>" end XMLElement.build_xml(obj_xml,'DOCUMENT') end |
Instance Method Details
#allocate(description) ⇒ nil, OpenNebula::Error
Allocates a new Document in OpenNebula
105 106 107 |
# File 'lib/opennebula/document.rb', line 105 def allocate(description) super(DOCUMENT_METHODS[:allocate], description, document_type) 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 Document permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
167 168 169 170 171 172 173 174 |
# File 'lib/opennebula/document.rb', line 167 def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) rc = check_type() return rc if OpenNebula.is_error?(rc) super(DOCUMENT_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 Document permissions.
155 156 157 158 159 160 |
# File 'lib/opennebula/document.rb', line 155 def chmod_octet(octet) rc = check_type() return rc if OpenNebula.is_error?(rc) super(DOCUMENT_METHODS[:chmod], octet) end |
#chown(uid, gid) ⇒ nil, OpenNebula::Error
Changes the owner/group
142 143 144 145 146 147 |
# File 'lib/opennebula/document.rb', line 142 def chown(uid, gid) rc = check_type() return rc if OpenNebula.is_error?(rc) super(DOCUMENT_METHODS[:chown], uid, gid) end |
#clone(name) ⇒ Integer, OpenNebula::Error
Clones this Document into a new one
182 183 184 185 186 187 188 189 190 191 |
# File 'lib/opennebula/document.rb', line 182 def clone(name) rc = check_type() return rc if OpenNebula.is_error?(rc) return Error.new('ID not defined') if !@pe_id rc = @client.call(DOCUMENT_METHODS[:clone], @pe_id, name) return rc end |
#delete ⇒ nil, OpenNebula::Error
Deletes the Document
113 114 115 116 117 118 |
# File 'lib/opennebula/document.rb', line 113 def delete() rc = check_type() return rc if OpenNebula.is_error?(rc) return call(DOCUMENT_METHODS[:delete], @pe_id) end |
#document_type ⇒ Object
229 230 231 |
# File 'lib/opennebula/document.rb', line 229 def document_type self.class::DOCUMENT_TYPE end |
#gid ⇒ Integer
Returns the group identifier
209 210 211 |
# File 'lib/opennebula/document.rb', line 209 def gid self['GID'].to_i end |
#info ⇒ nil, OpenNebula::Error Also known as: info!
Retrieves the information of the given Document.
87 88 89 90 91 92 93 94 95 |
# File 'lib/opennebula/document.rb', line 87 def info() rc = super(DOCUMENT_METHODS[:info], 'DOCUMENT') if !OpenNebula.is_error?(rc) && self['TYPE'].to_i != document_type return OpenNebula::Error.new("[DocumentInfo] Error getting document [#{@pe_id}].") end return rc end |
#owner_id ⇒ Integer
Returns the owner user ID
215 216 217 |
# File 'lib/opennebula/document.rb', line 215 def owner_id self['UID'].to_i end |
#public? ⇒ true, false
Returns true if the GROUP_U permission bit is set
221 222 223 224 225 226 227 |
# File 'lib/opennebula/document.rb', line 221 def public? if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1" true else false end end |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Document
199 200 201 |
# File 'lib/opennebula/document.rb', line 199 def rename(name) return call(DOCUMENT_METHODS[:rename], @pe_id, name) end |
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents
128 129 130 131 132 133 |
# File 'lib/opennebula/document.rb', line 128 def update(new_template, append=false) rc = check_type() return rc if OpenNebula.is_error?(rc) super(DOCUMENT_METHODS[:update], new_template, append ? 1 : 0) end |