Class: OneHookHelper

Inherits:
OpenNebulaHelper::OneHelper show all
Defined in:
lib/one_helper/onehook_helper.rb

Overview

implements onehook command

Instance Attribute Summary

Attributes inherited from OpenNebulaHelper::OneHelper

#client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OpenNebulaHelper::OneHelper

#check_orphan, client, #create_resource, #filterflag_to_i, filterflag_to_i_desc, get_client, get_password, #group_name, #initialize, #list_pool, #list_pool_format, #list_pool_table, #list_pool_top, #list_pool_xml, #list_to_id, list_to_id_desc, name_to_id, #perform_action, #perform_actions, #print_page, #retrieve_resource, #set_client, set_endpoint, set_password, set_user, #show_resource, #start_pager, #stop_pager, table_conf, #to_id, to_id_desc, #user_name

Constructor Details

This class inherits a constructor from OpenNebulaHelper::OneHelper

Class Method Details

.conf_fileObject



27
28
29
# File 'lib/one_helper/onehook_helper.rb', line 27

def self.conf_file
    'onehook.yaml'
end

.rnameObject



23
24
25
# File 'lib/one_helper/onehook_helper.rb', line 23

def self.rname
    'HOOK'
end

Instance Method Details

#hook_logs(options) ⇒ Object

Get hook logs



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/one_helper/onehook_helper.rb', line 34

def hook_logs(options)
    options[:hook_id].nil? ? hook_id = -1 : hook_id = options[:hook_id]

    if options.key? :success
        rc = 1
    elsif options.key? :error
        rc = -1
    else
        rc = 0
    end

    if options[:since]
        since_date = DateTime.parse(options[:since]).to_time.to_i
    else
        since_date = -1
    end

    if options[:until]
        until_date = DateTime.parse(options[:until]).to_time.to_i
    else
        until_date = -1
    end

    hook_log = OpenNebula::HookLog.new(@client)
    log_info = hook_log.info(since_date, until_date, hook_id, rc)

    if OpenNebula.is_error?(log_info)
        STDERR.puts(log_info.message)
        exit(-1)
    end

    begin
        exerc = [hook_log.to_hash['HOOKLOG']['HOOK_EXECUTION_RECORD']]
        exerc = exerc.flatten.compact
    rescue StandardError
        exerc = nil
    end

    if !exerc.nil? && !exerc.empty? && (!options.key? :xml)
        print_execution(exerc, false)
    elsif options.key? :xml
        puts hook_log.to_xml
    end
end