class OpenNebula::Document
All subclasses must define the DOCUMENT_TYPE constant.
@example
require 'opennebula/document' module OpenNebula class CustomObject < Document DOCUMENT_TYPE = 400 end end
Constants
- DOCUMENT_METHODS
Constants and Class Methods
Public Class Methods
Creates a Document
Object
description with just its identifier this method should be used to create plain Document
objects. @param [Integer] pe_id the id of the object
@return [Nokogiri::XML::Node, REXML::Element] the empty xml
# File lib/opennebula/document.rb, line 58 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
Class constructor
@param [Nokogiri::XML::Node, REXML::Element] xml string
created by the build_xml() method
@param [OpenNebula::Client] client the xml-rpc client
@return [Document] the new object
@example
doc = Document.new(Document.build_xml(3),rpc_client)
# File lib/opennebula/document.rb, line 78 def initialize(xml, client) LockableExt.make_lockable(self, DOCUMENT_METHODS) super(xml,client) end
Public Instance Methods
Allocates a new Document
in OpenNebula
@param description [String] The contents of the Document
.
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
# File lib/opennebula/document.rb, line 110 def allocate(description) super(DOCUMENT_METHODS[:allocate], description, document_type) end
Changes the Document
permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
# File lib/opennebula/document.rb, line 189 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
Changes the Document
permissions.
@param octet [String] Permissions octed , e.g. 640
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
# File lib/opennebula/document.rb, line 177 def chmod_octet(octet) rc = check_type() return rc if OpenNebula.is_error?(rc) super(DOCUMENT_METHODS[:chmod], octet) end
Changes the owner/group
@param [Integer] uid the new owner id. Set to -1 to leave the current one @param [Integer] gid the new group id. Set to -1 to leave the current one
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
# File lib/opennebula/document.rb, line 164 def chown(uid, gid) rc = check_type() return rc if OpenNebula.is_error?(rc) super(DOCUMENT_METHODS[:chown], uid, gid) end
Clones this Document
into a new one
@param name [String] Name for the new Document
.
@return [Integer, OpenNebula::Error
] The new Document
ID in case
of success, Error otherwise
# File lib/opennebula/document.rb, line 204 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
Deletes the Document
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
# File lib/opennebula/document.rb, line 120 def delete() rc = check_type() return rc if OpenNebula.is_error?(rc) return call(DOCUMENT_METHODS[:delete], @pe_id) end
# File lib/opennebula/document.rb, line 251 def document_type self.class::DOCUMENT_TYPE end
Returns the group identifier @return [Integer] the element’s group ID
# File lib/opennebula/document.rb, line 231 def gid self['GID'].to_i end
Retrieves the information of the given Document
.
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
# File lib/opennebula/document.rb, line 92 def info(decrypt = false) rc = super(DOCUMENT_METHODS[:info], 'DOCUMENT', decrypt) 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
Returns the owner user ID @return [Integer] the element’s owner user ID
# File lib/opennebula/document.rb, line 237 def owner_id self['UID'].to_i end
Returns true if the GROUP_U permission bit is set @return [true, false] true if the GROUP_U permission bit is set
# File lib/opennebula/document.rb, line 243 def public? if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1" true else false end end
Renames this Document
@param name [String] New name for the Document
.
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
# File lib/opennebula/document.rb, line 221 def rename(name) return call(DOCUMENT_METHODS[:rename], @pe_id, name) end
Replaces the template contents
@param [String] new_template new template contents @param append [true, false] True to append new attributes instead of
replace the whole template
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
# File lib/opennebula/document.rb, line 135 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
Replaces the raw template contents
@param template [String] New template contents, in the form KEY = VAL @param append [true, false] True to append new attributes instead of
replace the whole template
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
# File lib/opennebula/document.rb, line 150 def update_raw(template_raw, append=false) rc = check_type() return rc if OpenNebula.is_error?(rc) return call(DOCUMENT_METHODS[:update], @pe_id, template_raw, append ? 1 : 0) end
Private Instance Methods
# File lib/opennebula/document.rb, line 263 def check_type() type = self['TYPE'] if type.nil? && @pe_id rc = @client.call(DOCUMENT_METHODS[:info], @pe_id) return rc if OpenNebula.is_error?(rc) xmldoc = XMLElement.new xmldoc.initialize_xml(rc, 'DOCUMENT') type = xmldoc['TYPE'] end if !type.nil? && type.to_i != document_type return OpenNebula::Error.new( "[DocumentInfo] Error getting document [#{@pe_id}].") end return nil end
# File lib/opennebula/document.rb, line 257 def set_publish(published) group_u = published ? 1 : 0 chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1) end