Class: OpenNebulaOnedProbe
Overview
OpenNebulaOnedProbe - XML-RPC ONED client query service implementation.
Constant Summary
collapse
- FAILED_CONNECTIVITY =
'Failed to check connectivity: '
- FAILED_RESOURCE =
'Failed to check resource availability: '
OpennebulaProbe::CRIT_MSG, OpennebulaProbe::OK_MSG, OpennebulaProbe::UNKWN_MSG, OpennebulaProbe::WARN_MSG
Instance Attribute Summary
#logger, #message, #retval
Instance Method Summary
collapse
#crit?, #run, #warn?
Constructor Details
Returns a new instance of OpenNebulaOnedProbe.
27
28
29
30
31
32
33
|
# File 'lib/probe/opennebula_oned_probe.rb', line 27
def initialize(opts)
super(opts)
@credentials = "#{@opts.username}:#{@opts.password}"
@client = Client.new(@credentials, @endpoint)
end
|
Instance Method Details
#check_crit ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/probe/opennebula_oned_probe.rb', line 40
def check_crit
@logger.info "Checking for basic connectivity at #{@endpoint}"
pool_class_array = [VirtualNetworkPool, ImagePool, VirtualMachinePool]
pool_class_array.each do |pool_class|
pool = pool_class.new(@client, -1)
check_pool(pool, FAILED_CONNECTIVITY)
end
false
rescue StandardError => e
@logger.error "Failed to check basic connectivity: #{e.message}"
@logger.debug "#{e.backtrace.join("\n")}"
return true
end
|
#check_pool(pool, msg) ⇒ Object
35
36
37
38
|
# File 'lib/probe/opennebula_oned_probe.rb', line 35
def check_pool(pool, msg)
rc = pool.info
fail "#{msg} #{rc.message}" if OpenNebula.is_error?(rc)
end
|
#check_resources(resources) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/probe/opennebula_oned_probe.rb', line 57
def check_resources(resources)
if resources.map { |x| x[:resource] }.reduce(true) { |product, resource| product && resource.nil? }
@logger.info 'There are no resources to check, for details on how to specify resources see --help'
return false
end
resources.each do |resource_hash|
resource = resource_hash[:resource]
next unless resource
@logger.info "Looking for #{resource_hash[:resource_string]}s: #{resource.inspect}"
pool = resource_hash[:resource_pool].new(@client, -1)
check_pool(pool, FAILED_RESOURCE)
resource.each do |resource_to_look_for|
found = false
pool.each do |res|
check_pool(res, FAILED_RESOURCE)
found = true if res.id.to_s == resource_to_look_for
end
fail "#{resource_hash[:resource_string].capitalize} #{resource_to_look_for} not found" unless found
end
end
false
end
|
#check_warn ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/probe/opennebula_oned_probe.rb', line 86
def check_warn
@logger.info "Checking for resource availability at #{@endpoint}"
resources = []
resources << { resource: @opts.storage, resource_string: 'image', resource_pool: ImagePool }
resources << { resource: @opts.compute, resource_string: 'compute instance', resource_pool: VirtualMachinePool }
resources << { resource: @opts.network, resource_string: 'network', resource_pool: VirtualNetworkPool }
check_resources(resources)
rescue StandardError => e
@logger.error "Failed to check resource availability: #{e.message}"
@logger.debug "#{e.backtrace.join("\n")}"
return true
end
|