class OpenNebula::Hook

Class for representing a Hook object.

Constants

HOOK_METHODS

Constants and Class Methods

Public Class Methods

build_xml(pe_id = nil) click to toggle source

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)
# 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
new(xml, client) click to toggle source

Class constructor

Calls superclass method
# File lib/opennebula/hook.rb, line 56
def initialize(xml, client)
    super(xml, client)

    @client = client
end

Public Instance Methods

allocate(template) click to toggle source

Allocates a new Hook in OpenNebula

@param template [String] The contents of the Hook template.

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
Calls superclass method
# File lib/opennebula/hook.rb, line 91
def allocate(template)
    super(HOOK_METHODS[:allocate], template)
end
delete() click to toggle source

Deletes the Hook

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/hook.rb, line 99
def delete
    call(HOOK_METHODS[:delete], @pe_id)
end
gid() click to toggle source

Returns the group identifier

return

Integer the element's group ID

# File lib/opennebula/hook.rb, line 141
def gid
    self['GID'].to_i
end
info() click to toggle source

Retrieves the information of the given Hook.

# 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
Also aliased as: info!
info!()
Alias for: info
lock(level) click to toggle source

Lock a Hook

# File lib/opennebula/hook.rb, line 150
def lock(level)
    call(HOOK_METHODS[:lock], @pe_id, level)
end
owner_id() click to toggle source
# File lib/opennebula/hook.rb, line 145
def owner_id
    self['UID'].to_i
end
rename(name) click to toggle source

Renames this Hook

@param name [String] New name for the Hook.

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/hook.rb, line 121
def rename(name)
    call(HOOK_METHODS[:rename], @pe_id, name)
end
retry(exec_id) click to toggle source

Retry a previous execution of the hook.

@param exec_id [int] Hook execution id.

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/hook.rb, line 131
def retry(exec_id)
    call(HOOK_METHODS[:retry], @pe_id, exec_id)
end
unlock() click to toggle source

Unlock a Hook

# File lib/opennebula/hook.rb, line 155
def unlock
    call(HOOK_METHODS[:unlock], @pe_id)
end
update(new_template, append = false) click to toggle source

Replaces the Hook contents

@param new_template [String] New Hook 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
Calls superclass method
# File lib/opennebula/hook.rb, line 111
def update(new_template, append = false)
    super(HOOK_METHODS[:update], new_template, append ? 1 : 0)
end