nagios-promoo 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -0
- data/.rubocop_todo.yml +29 -0
- data/.travis.yml +27 -0
- data/README.md +8 -4
- data/Rakefile +6 -1
- data/lib/nagios/promoo.rb +12 -6
- data/lib/nagios/promoo/appdb/master.rb +52 -25
- data/lib/nagios/promoo/appdb/probes/appliances_probe.rb +50 -37
- data/lib/nagios/promoo/appdb/probes/base_probe.rb +60 -40
- data/lib/nagios/promoo/appdb/probes/sizes_probe.rb +50 -37
- data/lib/nagios/promoo/appdb/probes/sync_probe.rb +179 -0
- data/lib/nagios/promoo/appdb/version.rb +1 -1
- data/lib/nagios/promoo/master.rb +37 -19
- data/lib/nagios/promoo/occi/master.rb +58 -27
- data/lib/nagios/promoo/occi/probes/base_probe.rb +37 -24
- data/lib/nagios/promoo/occi/probes/categories_probe.rb +88 -46
- data/lib/nagios/promoo/occi/probes/compute_probe.rb +249 -202
- data/lib/nagios/promoo/occi/probes/kinds_probe.rb +83 -52
- data/lib/nagios/promoo/occi/probes/mixins_probe.rb +62 -37
- data/lib/nagios/promoo/occi/version.rb +1 -1
- data/lib/nagios/promoo/opennebula/master.rb +55 -26
- data/lib/nagios/promoo/opennebula/probes/base_probe.rb +35 -12
- data/lib/nagios/promoo/opennebula/probes/virtual_machine_probe.rb +138 -100
- data/lib/nagios/promoo/opennebula/probes/xmlrpc_health_probe.rb +34 -21
- data/lib/nagios/promoo/opennebula/version.rb +1 -1
- data/lib/nagios/promoo/utils.rb +47 -25
- data/lib/nagios/promoo/version.rb +1 -1
- data/nagios-promoo.gemspec +5 -4
- metadata +9 -6
- data/lib/nagios/promoo/appdb/probes/vmcatcher_probe.rb +0 -118
@@ -1,68 +1,99 @@
|
|
1
1
|
# Internal deps
|
2
2
|
require File.join(File.dirname(__FILE__), 'base_probe')
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module Nagios
|
5
|
+
module Promoo
|
6
|
+
module Occi
|
7
|
+
module Probes
|
8
|
+
# Probe for checking OCCI kinds declared by sites.
|
9
|
+
#
|
10
|
+
# @author Boris Parak <parak@cesnet.cz>
|
11
|
+
class KindsProbe < Nagios::Promoo::Occi::Probes::BaseProbe
|
12
|
+
class << self
|
13
|
+
def description
|
14
|
+
['kinds', 'Run a probe checking for mandatory OCCI kind definitions']
|
15
|
+
end
|
9
16
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
def options
|
18
|
+
[
|
19
|
+
[
|
20
|
+
:kinds,
|
21
|
+
{
|
22
|
+
type: :string, enum: %w[core infra all], default: 'all',
|
23
|
+
desc: 'Collection of mandatory kinds to check'
|
24
|
+
}
|
25
|
+
],
|
26
|
+
[
|
27
|
+
:optional,
|
28
|
+
{
|
29
|
+
type: :array, default: [],
|
30
|
+
desc: 'Identifiers of optional kinds (optional by force)'
|
31
|
+
}
|
32
|
+
],
|
33
|
+
[
|
34
|
+
:check_location,
|
35
|
+
{
|
36
|
+
type: :boolean, default: false,
|
37
|
+
desc: 'Verify declared REST locations for INFRA resources'
|
38
|
+
}
|
39
|
+
]
|
40
|
+
]
|
41
|
+
end
|
17
42
|
|
18
|
-
|
19
|
-
|
20
|
-
|
43
|
+
def declaration
|
44
|
+
'kinds'
|
45
|
+
end
|
21
46
|
|
22
|
-
|
23
|
-
|
47
|
+
def runnable?
|
48
|
+
true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
CORE_KINDS = %w[
|
53
|
+
http://schemas.ogf.org/occi/core#entity
|
54
|
+
http://schemas.ogf.org/occi/core#resource
|
55
|
+
http://schemas.ogf.org/occi/core#link
|
56
|
+
].freeze
|
24
57
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
58
|
+
INFRA_KINDS = %w[
|
59
|
+
http://schemas.ogf.org/occi/infrastructure#compute
|
60
|
+
http://schemas.ogf.org/occi/infrastructure#storage
|
61
|
+
http://schemas.ogf.org/occi/infrastructure#network
|
62
|
+
http://schemas.ogf.org/occi/infrastructure#storagelink
|
63
|
+
http://schemas.ogf.org/occi/infrastructure#networkinterface
|
64
|
+
].freeze
|
30
65
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
http://schemas.ogf.org/occi/infrastructure#networkinterface
|
37
|
-
)
|
66
|
+
def run(_args = [])
|
67
|
+
kinds = []
|
68
|
+
kinds += CORE_KINDS if %w[core all].include?(options[:kinds])
|
69
|
+
kinds += INFRA_KINDS if %w[infra all].include?(options[:kinds])
|
70
|
+
kinds -= options[:optional] if options[:optional]
|
38
71
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
kinds -= options[:optional] if options[:optional]
|
72
|
+
Timeout.timeout(options[:timeout]) do
|
73
|
+
kinds.each do |kind|
|
74
|
+
raise "#{kind.inspect} is missing" unless client.model.get_by_id(kind, true)
|
75
|
+
next unless options[:check_location] && INFRA_KINDS.include?(kind)
|
44
76
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
77
|
+
# Make sure declared locations are actually available as REST
|
78
|
+
# endpoints. Failure will raise an exception, no need to do
|
79
|
+
# anything here. To keep requirements reasonable, only INFRA
|
80
|
+
# kinds are considered relevant for this part of the check.
|
81
|
+
begin
|
82
|
+
client.list(kind)
|
83
|
+
rescue => err
|
84
|
+
raise "Failed to verify declared REST location for #{kind.inspect} (#{err.message})"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
49
88
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
rescue => err
|
57
|
-
fail "Failed to verify declared REST location for #{kind.inspect} (#{err.message})"
|
89
|
+
puts 'KINDS OK - All specified OCCI kinds were found'
|
90
|
+
rescue => ex
|
91
|
+
puts "KINDS CRITICAL - #{ex.message}"
|
92
|
+
puts ex.backtrace if options[:debug]
|
93
|
+
exit 2
|
94
|
+
end
|
58
95
|
end
|
59
96
|
end
|
60
97
|
end
|
61
|
-
|
62
|
-
puts 'KINDS OK - All specified OCCI kinds were found'
|
63
|
-
rescue => ex
|
64
|
-
puts "KINDS CRITICAL - #{ex.message}"
|
65
|
-
puts ex.backtrace if options[:debug]
|
66
|
-
exit 2
|
67
98
|
end
|
68
99
|
end
|
@@ -1,50 +1,75 @@
|
|
1
1
|
# Internal deps
|
2
2
|
require File.join(File.dirname(__FILE__), 'base_probe')
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module Nagios
|
5
|
+
module Promoo
|
6
|
+
module Occi
|
7
|
+
module Probes
|
8
|
+
# Probe for checking OCCI mixins declared by sites.
|
9
|
+
#
|
10
|
+
# @author Boris Parak <parak@cesnet.cz>
|
11
|
+
class MixinsProbe < Nagios::Promoo::Occi::Probes::BaseProbe
|
12
|
+
class << self
|
13
|
+
def description
|
14
|
+
['mixins', 'Run a probe checking for mandatory OCCI mixin definitions']
|
15
|
+
end
|
9
16
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
17
|
+
def options
|
18
|
+
[
|
19
|
+
[
|
20
|
+
:mixins,
|
21
|
+
{
|
22
|
+
type: :string, enum: %w[infra context all],
|
23
|
+
default: 'all', desc: 'Collection of mandatory mixins to check'
|
24
|
+
}
|
25
|
+
],
|
26
|
+
[
|
27
|
+
:optional,
|
28
|
+
{
|
29
|
+
type: :array, default: [],
|
30
|
+
desc: 'Identifiers of optional mixins (optional by force)'
|
31
|
+
}
|
32
|
+
]
|
33
|
+
]
|
34
|
+
end
|
16
35
|
|
17
|
-
|
18
|
-
|
19
|
-
|
36
|
+
def declaration
|
37
|
+
'mixins'
|
38
|
+
end
|
20
39
|
|
21
|
-
|
22
|
-
|
40
|
+
def runnable?
|
41
|
+
true
|
42
|
+
end
|
43
|
+
end
|
23
44
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
45
|
+
INFRA_MIXINS = %w[
|
46
|
+
http://schemas.ogf.org/occi/infrastructure#os_tpl
|
47
|
+
http://schemas.ogf.org/occi/infrastructure#resource_tpl
|
48
|
+
].freeze
|
28
49
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
50
|
+
CONTEXT_MIXINS = %w[
|
51
|
+
http://schemas.openstack.org/instance/credentials#public_key
|
52
|
+
http://schemas.openstack.org/compute/instance#user_data
|
53
|
+
].freeze
|
33
54
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
55
|
+
def run(_args = [])
|
56
|
+
mixins = []
|
57
|
+
mixins += INFRA_MIXINS if %w[infra all].include?(options[:mixins])
|
58
|
+
mixins += CONTEXT_MIXINS if %w[context all].include?(options[:mixins])
|
59
|
+
mixins -= options[:optional] if options[:optional]
|
39
60
|
|
40
|
-
|
41
|
-
|
42
|
-
|
61
|
+
Timeout.timeout(options[:timeout]) do
|
62
|
+
mixins.each { |mixin| raise "#{mixin.inspect} is missing" unless client.model.get_by_id(mixin, true) }
|
63
|
+
end
|
43
64
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
65
|
+
puts 'MIXINS OK - All specified OCCI mixins were found'
|
66
|
+
rescue => ex
|
67
|
+
puts "MIXINS CRITICAL - #{ex.message}"
|
68
|
+
puts ex.backtrace if options[:debug]
|
69
|
+
exit 2
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
49
74
|
end
|
50
75
|
end
|
@@ -4,41 +4,70 @@ require 'opennebula'
|
|
4
4
|
# Internal deps
|
5
5
|
require File.join(File.dirname(__FILE__), 'version')
|
6
6
|
|
7
|
-
|
8
|
-
module
|
9
|
-
|
7
|
+
module Nagios
|
8
|
+
module Promoo
|
9
|
+
# Namespace for ONe-related code.
|
10
|
+
#
|
11
|
+
# @author Boris Parak <parak@cesnet.cz>
|
12
|
+
module Opennebula
|
13
|
+
# Namespace for ONe-related probes.
|
14
|
+
#
|
15
|
+
# @author Boris Parak <parak@cesnet.cz>
|
16
|
+
module Probes; end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
10
21
|
Dir.glob(File.join(File.dirname(__FILE__), 'probes', '*.rb')) { |probe| require probe.chomp('.rb') }
|
11
22
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
23
|
+
module Nagios
|
24
|
+
module Promoo
|
25
|
+
module Opennebula
|
26
|
+
# Master class for all OpenNebula probes.
|
27
|
+
#
|
28
|
+
# @author Boris Parak <parak@cesnet.cz>
|
29
|
+
class Master < ::Thor
|
30
|
+
class << self
|
31
|
+
# Hack to override the help message produced by Thor.
|
32
|
+
# https://github.com/wycats/thor/issues/261#issuecomment-16880836
|
33
|
+
def banner(command, _namespace = nil, _subcommand = nil)
|
34
|
+
"#{basename} opennebula #{command.usage}"
|
35
|
+
end
|
19
36
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
37
|
+
def available_probes
|
38
|
+
probes = Nagios::Promoo::Opennebula::Probes.constants.collect do |probe|
|
39
|
+
Nagios::Promoo::Opennebula::Probes.const_get(probe)
|
40
|
+
end
|
41
|
+
probes.select(&:runnable?)
|
42
|
+
end
|
43
|
+
end
|
24
44
|
|
25
|
-
|
26
|
-
|
45
|
+
class_option :endpoint,
|
46
|
+
type: :string,
|
47
|
+
desc: 'OpenNebula XML-RPC endpoint',
|
48
|
+
default: 'http://localhost:2633/RPC2'
|
49
|
+
class_option :token,
|
50
|
+
type: :string,
|
51
|
+
desc: 'Authentication token',
|
52
|
+
default: "file://#{ENV['HOME']}/.one/one_auth"
|
27
53
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
54
|
+
available_probes.each do |probe|
|
55
|
+
desc(*probe.description)
|
56
|
+
probe.options.each do |opt|
|
57
|
+
option opt.first, opt.last
|
58
|
+
end
|
59
|
+
class_eval %^
|
34
60
|
def #{probe.declaration}(*args)
|
35
61
|
#{probe}.new(options).run(args)
|
36
62
|
end
|
37
63
|
^
|
38
|
-
|
64
|
+
end
|
39
65
|
|
40
|
-
|
41
|
-
|
42
|
-
|
66
|
+
desc 'version', 'Print version of the OpenNebula probe set'
|
67
|
+
def version
|
68
|
+
puts Nagios::Promoo::Opennebula::VERSION
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
43
72
|
end
|
44
73
|
end
|
@@ -1,18 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Nagios
|
2
|
+
module Promoo
|
3
|
+
module Opennebula
|
4
|
+
module Probes
|
5
|
+
# Base probe for all ONe-related probes.
|
6
|
+
#
|
7
|
+
# @author Boris Parak <parak@cesnet.cz>
|
8
|
+
class BaseProbe
|
9
|
+
class << self
|
10
|
+
def runnable?
|
11
|
+
false
|
12
|
+
end
|
13
|
+
end
|
5
14
|
|
6
|
-
|
15
|
+
attr_reader :options
|
7
16
|
|
8
|
-
|
9
|
-
|
10
|
-
|
17
|
+
def initialize(options)
|
18
|
+
@options = options
|
19
|
+
end
|
20
|
+
|
21
|
+
def client
|
22
|
+
return @_client if @_client
|
23
|
+
|
24
|
+
token = token_file? ? read_token : options[:token]
|
25
|
+
@_client = OpenNebula::Client.new(token.to_s, options[:endpoint])
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
11
29
|
|
12
|
-
|
13
|
-
|
30
|
+
def token_file?
|
31
|
+
options[:token].start_with?('file://')
|
32
|
+
end
|
14
33
|
|
15
|
-
|
16
|
-
|
34
|
+
def read_token
|
35
|
+
File.read(options[:token].gsub('file://', ''))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
17
40
|
end
|
18
41
|
end
|
@@ -1,106 +1,144 @@
|
|
1
1
|
# Internal deps
|
2
2
|
require File.join(File.dirname(__FILE__), 'base_probe')
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
4
|
+
module Nagios
|
5
|
+
module Promoo
|
6
|
+
module Opennebula
|
7
|
+
module Probes
|
8
|
+
# Probe for checking VM instantiation via ONe RPC2.
|
9
|
+
#
|
10
|
+
# @author Boris Parak <parak@cesnet.cz>
|
11
|
+
class VirtualMachineProbe < Nagios::Promoo::Opennebula::Probes::BaseProbe
|
12
|
+
class << self
|
13
|
+
def description
|
14
|
+
['virtual-machine', 'Run a probe instantiating a test instance in OpenNebula']
|
15
|
+
end
|
16
|
+
|
17
|
+
def options
|
18
|
+
[
|
19
|
+
[
|
20
|
+
:template,
|
21
|
+
{
|
22
|
+
type: :string, default: 'monitoring',
|
23
|
+
desc: 'Name referencing a template used for monitoring purposes'
|
24
|
+
}
|
25
|
+
],
|
26
|
+
[
|
27
|
+
:vm_timeout,
|
28
|
+
{
|
29
|
+
type: :numeric, default: 180,
|
30
|
+
desc: 'Timeout for VM instantiation (in seconds)'
|
31
|
+
}
|
32
|
+
],
|
33
|
+
[
|
34
|
+
:cleanup,
|
35
|
+
{
|
36
|
+
type: :boolean, default: true,
|
37
|
+
desc: 'Perform clean-up before launching a new instance'
|
38
|
+
}
|
39
|
+
]
|
40
|
+
]
|
41
|
+
end
|
42
|
+
|
43
|
+
def declaration
|
44
|
+
'virtual_machine'
|
45
|
+
end
|
46
|
+
|
47
|
+
def runnable?
|
48
|
+
true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
VM_NAME_PREFIX = 'nagios-promoo'.freeze
|
53
|
+
|
54
|
+
def run(_args = [])
|
55
|
+
if options[:timeout] <= options[:vm_timeout]
|
56
|
+
raise "Timeout (#{options[:timeout]}) must be higher than "\
|
57
|
+
"vm-timeout (#{options[:vm_timeout]}) "
|
58
|
+
end
|
59
|
+
|
60
|
+
@_virtual_machine = nil
|
61
|
+
|
62
|
+
Timeout.timeout(options[:timeout]) do
|
63
|
+
cleanup if options[:cleanup]
|
64
|
+
create
|
65
|
+
wait4running
|
66
|
+
end
|
67
|
+
|
68
|
+
puts "VirtualMachine OK - Instance #{@_virtual_machine.id.inspect} of template "\
|
69
|
+
"#{options[:template].inspect} successfully created & cleaned up"
|
70
|
+
rescue => ex
|
71
|
+
puts "VirtualMachine CRITICAL - #{ex.message}"
|
72
|
+
puts ex.backtrace if options[:debug]
|
73
|
+
exit 2
|
74
|
+
ensure
|
75
|
+
begin
|
76
|
+
cleanup @_virtual_machine unless @_virtual_machine.blank?
|
77
|
+
rescue => ex
|
78
|
+
puts "VirtualMachine CRITICAL - #{ex.message}"
|
79
|
+
puts ex.backtrace if options[:debug]
|
80
|
+
exit 2
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def cleanup(virtual_machine = nil)
|
87
|
+
virtual_machine ? shutdown_or_delete(virtual_machine) : search_and_destroy
|
88
|
+
end
|
89
|
+
|
90
|
+
def create
|
91
|
+
template_pool = OpenNebula::TemplatePool.new(client)
|
92
|
+
rc = template_pool.info_all
|
93
|
+
raise rc.message if OpenNebula.is_error?(rc)
|
94
|
+
|
95
|
+
template = template_pool.select { |tpl| tpl.name == options[:template] }.first
|
96
|
+
raise "Template #{options[:template].inspect} could not be found" unless template
|
97
|
+
|
98
|
+
vm_id = template.instantiate("#{VM_NAME_PREFIX}-#{Time.now.to_i}")
|
99
|
+
raise vm_id.message if OpenNebula.is_error?(vm_id)
|
100
|
+
|
101
|
+
virtual_machine = OpenNebula::VirtualMachine.new(OpenNebula::VirtualMachine.build_xml(vm_id), client)
|
102
|
+
rc = virtual_machine.info
|
103
|
+
raise rc.message if OpenNebula.is_error?(rc)
|
104
|
+
|
105
|
+
@_virtual_machine = virtual_machine
|
106
|
+
end
|
107
|
+
|
108
|
+
def wait4running
|
109
|
+
Timeout.timeout(options[:vm_timeout]) do
|
110
|
+
while @_virtual_machine.lcm_state_str != 'RUNNING'
|
111
|
+
if @_virtual_machine.lcm_state_str.include?('FAILURE')
|
112
|
+
raise 'Instance deployment failed (resulting state is "*_FAILED")'
|
113
|
+
end
|
114
|
+
|
115
|
+
rc = @_virtual_machine.info
|
116
|
+
raise rc.message if OpenNebula.is_error?(rc)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
rescue Timeout::Error
|
120
|
+
puts 'VirtualMachine WARNING - Execution timed out while waiting for ' \
|
121
|
+
"the instance to become active [#{options[:vm_timeout]}s]"
|
122
|
+
exit 1
|
123
|
+
end
|
124
|
+
|
125
|
+
def search_and_destroy
|
126
|
+
vm_pool = OpenNebula::VirtualMachinePool.new(client)
|
127
|
+
rc = vm_pool.info_mine
|
128
|
+
raise rc.message if OpenNebula.is_error?(rc)
|
129
|
+
|
130
|
+
candidates = vm_pool.select { |vm| vm.name.start_with?(VM_NAME_PREFIX) }
|
131
|
+
candidates.each { |vm| shutdown_or_delete(vm) }
|
132
|
+
|
133
|
+
candidates.count
|
134
|
+
end
|
135
|
+
|
136
|
+
def shutdown_or_delete(virtual_machine)
|
137
|
+
rc = virtual_machine.terminate true
|
138
|
+
raise rc.message if OpenNebula.is_error?(rc)
|
139
|
+
end
|
140
|
+
end
|
83
141
|
end
|
84
|
-
|
85
|
-
rescue Timeout::Error => ex
|
86
|
-
puts "VirtualMachine WARNING - Execution timed out while waiting for " \
|
87
|
-
"the instance to become active [#{options[:vm_timeout]}s]"
|
88
|
-
exit 1
|
89
|
-
end
|
90
|
-
|
91
|
-
def search_and_destroy
|
92
|
-
vm_pool = OpenNebula::VirtualMachinePool.new(client)
|
93
|
-
rc = vm_pool.info_mine
|
94
|
-
fail rc.message if OpenNebula.is_error?(rc)
|
95
|
-
|
96
|
-
candidates = vm_pool.select { |vm| vm.name.start_with?(VM_NAME_PREFIX) }
|
97
|
-
candidates.each { |vm| shutdown_or_delete(vm) }
|
98
|
-
|
99
|
-
candidates.count
|
100
|
-
end
|
101
|
-
|
102
|
-
def shutdown_or_delete(virtual_machine)
|
103
|
-
rc = virtual_machine.terminate true
|
104
|
-
fail rc.message if OpenNebula.is_error?(rc)
|
142
|
+
end
|
105
143
|
end
|
106
144
|
end
|