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 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
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 75 def initialize(xml, client) 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 105 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 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
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 155 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 142 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 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
# File lib/opennebula/document.rb, line 229 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 209 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 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
Returns the owner user ID @return [Integer] the element's owner user ID
# File lib/opennebula/document.rb, line 215 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 221 def public? if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1" true else false end 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 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
Private Instance Methods
# File lib/opennebula/document.rb, line 241 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 235 def set_publish(published) group_u = published ? 1 : 0 chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1) end