Class: OpenNebula::Document

Inherits:
PoolElement show all
Defined in:
lib/opennebula/document.rb

Overview

All subclasses must define the DOCUMENT_TYPE constant.

Examples:

require 'opennebula/document'

module OpenNebula
    class CustomObject < Document

        DOCUMENT_TYPE = 400

    end
end

Direct Known Subclasses

DocumentJSON

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",
    :lock       => "document.lock",
    :unlock     => "document.unlock"
}

Class Method Summary collapse

Instance Method Summary collapse

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, #retrieve_xmlelements, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml, #xml_nil?

Constructor Details

#initialize(xml, client) ⇒ Document

Class constructor

Examples:

doc = Document.new(Document.build_xml(3),rpc_client)


77
78
79
# File 'lib/opennebula/document.rb', line 77

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.



57
58
59
60
61
62
63
64
65
# File 'lib/opennebula/document.rb', line 57

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



107
108
109
# File 'lib/opennebula/document.rb', line 107

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



184
185
186
187
188
189
190
191
# File 'lib/opennebula/document.rb', line 184

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.



172
173
174
175
176
177
# File 'lib/opennebula/document.rb', line 172

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



159
160
161
162
163
164
# File 'lib/opennebula/document.rb', line 159

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



199
200
201
202
203
204
205
206
207
208
# File 'lib/opennebula/document.rb', line 199

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

#deletenil, OpenNebula::Error

Deletes the Document



115
116
117
118
119
120
# File 'lib/opennebula/document.rb', line 115

def delete()
    rc = check_type()
    return rc if OpenNebula.is_error?(rc)

    return call(DOCUMENT_METHODS[:delete], @pe_id)
end

#document_typeObject



272
273
274
# File 'lib/opennebula/document.rb', line 272

def document_type
    self.class::DOCUMENT_TYPE
end

#gidInteger

Returns the group identifier



252
253
254
# File 'lib/opennebula/document.rb', line 252

def gid
    self['GID'].to_i
end

#infonil, OpenNebula::Error Also known as: info!

Retrieves the information of the given Document.



89
90
91
92
93
94
95
96
97
# File 'lib/opennebula/document.rb', line 89

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

#lock(owner = "") ⇒ Bool, OpenNebula::Error

Locks this object



227
228
229
230
231
232
233
# File 'lib/opennebula/document.rb', line 227

def lock(owner="")
    return Error.new('ID not defined') if !@pe_id

    rc = @client.call(DOCUMENT_METHODS[:lock], @pe_id, owner)

    return rc
end

#owner_idInteger

Returns the owner user ID



258
259
260
# File 'lib/opennebula/document.rb', line 258

def owner_id
    self['UID'].to_i
end

#public?true, false

Returns true if the GROUP_U permission bit is set



264
265
266
267
268
269
270
# File 'lib/opennebula/document.rb', line 264

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



216
217
218
# File 'lib/opennebula/document.rb', line 216

def rename(name)
    return call(DOCUMENT_METHODS[:rename], @pe_id, name)
end

#unlock(owner = "") ⇒ nil, OpenNebula::Error

Unlocks this object



242
243
244
# File 'lib/opennebula/document.rb', line 242

def unlock(owner="")
    return call(DOCUMENT_METHODS[:unlock], @pe_id, owner)
end

#update(new_template, append = false) ⇒ nil, OpenNebula::Error

Replaces the template contents



130
131
132
133
134
135
# File 'lib/opennebula/document.rb', line 130

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

#update_raw(template_raw, append = false) ⇒ nil, OpenNebula::Error

Replaces the raw template contents



145
146
147
148
149
150
# File 'lib/opennebula/document.rb', line 145

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