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'
}

Instance Attribute Summary

Attributes inherited from PoolElement

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PoolElement

#id, 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



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

def initialize(xml, client)
    LockableExt.make_lockable(self, HOOK_METHODS)

    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)


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

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:



94
95
96
# File 'lib/opennebula/hook.rb', line 94

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

#deletenil, OpenNebula::Error

Deletes the Hook

Returns:



102
103
104
# File 'lib/opennebula/hook.rb', line 102

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

#gidObject

Returns the group identifier

return

Integer the element’s group ID



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

def gid
    self['GID'].to_i
end

#infoObject Also known as: info!

Retrieves the information of the given Hook.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/opennebula/hook.rb', line 70

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

#owner_idObject



148
149
150
# File 'lib/opennebula/hook.rb', line 148

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:



124
125
126
# File 'lib/opennebula/hook.rb', line 124

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:



134
135
136
# File 'lib/opennebula/hook.rb', line 134

def retry(exec_id)
    call(HOOK_METHODS[:retry], @pe_id, exec_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:



114
115
116
# File 'lib/opennebula/hook.rb', line 114

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