Class: OpenNebula::Hook

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

Overview

Class for representing a Hook object.

Constant Summary collapse

HOOK_METHODS =

Constants and Class Methods

{
    :allocate => 'hook.allocate',
    :delete   => 'hook.delete',
    :update   => 'hook.update',
    :rename   => 'hook.rename',
    :info     => 'hook.info',
    :lock     => 'hook.lock',
    :unlock   => 'hook.unlock',
    :retry    => 'hook.retry'
}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PoolElement

#id, #name, new_with_id, #replace, #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, #set_content, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml, #xml_nil?

Constructor Details

#initialize(xml, client) ⇒ Hook

Class constructor



56
57
58
59
60
# File 'lib/opennebula/hook.rb', line 56

def initialize(xml, client)
    super(xml, client)

    @client = client
end

Class Method Details

.build_xml(pe_id = nil) ⇒ Object

Creates a Hook description with just its identifier this method should be used to create plain Hook objects. id the id of the user

Example:

hook = Hook.new(Hook.build_xml(3),rpc_client)


45
46
47
48
49
50
51
52
53
# File 'lib/opennebula/hook.rb', line 45

def self.build_xml(pe_id = nil)
    if pe_id
        obj_xml = "<HOOK><ID>#{pe_id}</ID></HOOK>"
    else
        obj_xml = '<HOOK></HOOK>'
    end

    XMLElement.build_xml(obj_xml, 'HOOK')
end

Instance Method Details

#allocate(template) ⇒ nil, OpenNebula::Error

Allocates a new Hook in OpenNebula

Parameters:

  • template (String)

    The contents of the Hook template.

Returns:



91
92
93
# File 'lib/opennebula/hook.rb', line 91

def allocate(template)
    super(HOOK_METHODS[:allocate], template)
end

#deletenil, OpenNebula::Error

Deletes the Hook

Returns:



99
100
101
# File 'lib/opennebula/hook.rb', line 99

def delete
    call(HOOK_METHODS[:delete], @pe_id)
end

#gidObject

Returns the group identifier

return

Integer the element’s group ID



141
142
143
# File 'lib/opennebula/hook.rb', line 141

def gid
    self['GID'].to_i
end

#infoObject Also known as: info!

Retrieves the information of the given Hook.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/opennebula/hook.rb', line 67

def info
    return Error.new('ID not defined') unless @pe_id

    rc = @client.call(HOOK_METHODS[:info], @pe_id, false)

    if !OpenNebula.is_error?(rc)
        initialize_xml(rc, 'HOOK')
        rc = nil

        @pe_id = self['ID'].to_i if self['ID']
        @name  = self['NAME'] if self['NAME']
    end

    rc
end

#lock(level) ⇒ Object

Lock a Hook



150
151
152
# File 'lib/opennebula/hook.rb', line 150

def lock(level)
    call(HOOK_METHODS[:lock], @pe_id, level)
end

#owner_idObject



145
146
147
# File 'lib/opennebula/hook.rb', line 145

def owner_id
    self['UID'].to_i
end

#rename(name) ⇒ nil, OpenNebula::Error

Renames this Hook

Parameters:

  • name (String)

    New name for the Hook.

Returns:



121
122
123
# File 'lib/opennebula/hook.rb', line 121

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

#retry(exec_id) ⇒ nil, OpenNebula::Error

Retry a previous execution of the hook.

Parameters:

  • exec_id (int)

    Hook execution id.

Returns:



131
132
133
# File 'lib/opennebula/hook.rb', line 131

def retry(exec_id)
    call(HOOK_METHODS[:retry], @pe_id, exec_id)
end

#unlockObject

Unlock a Hook



155
156
157
# File 'lib/opennebula/hook.rb', line 155

def unlock
    call(HOOK_METHODS[:unlock], @pe_id)
end

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

Replaces the Hook contents

Parameters:

  • new_template (String)

    New Hook contents

  • append (true, false) (defaults to: false)

    True to append new attributes instead of replace the whole template

Returns:



111
112
113
# File 'lib/opennebula/hook.rb', line 111

def update(new_template, append = false)
    super(HOOK_METHODS[:update], new_template, append ? 1 : 0)
end