nagios-promoo 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1787169d8cb255b046e890de4ff5916b6d43a548
4
- data.tar.gz: 402a454be9941e1133c7ee3c65bbb973ab27623e
3
+ metadata.gz: 1e735c8510920fe9ed8dd4d200c31aca66a7771f
4
+ data.tar.gz: c7ca40aa71dbf5291d3b975860518758bce65bee
5
5
  SHA512:
6
- metadata.gz: 4fb8f36c9fa1f65a67c4360f2f50d6bf5efc956368ac55cc96d9802b7efa9496524236bbc496df393aab30ad1fa795a7291aca3cff15e1be172d456d7274b265
7
- data.tar.gz: 5ed803935e772f15a3ea1e4da16d96c3d960ac286dd0b5c05e706b60f0e7437f7fda00fc6341bd8d43c56e1810a8010690930dd90206c90e8f8267f936634204
6
+ metadata.gz: 2e1ca3d2b6a99c7a34d19b06e2feecdc49e24aecb63c6a57ce526c5ab1858a0ffcb9ec4f9272b80162c801f2002170d1faea6f3bae6cb0b4d445c1b51cc17acd
7
+ data.tar.gz: 9c15ac5874413491dcd88b478f71f681e71c796550bda663666b3ea38b0e4bd8c559f85513e8b0dbf867e7a00ffe96f4102792085b64d6c347839e56296ad71b
@@ -28,7 +28,7 @@ class Nagios::Promoo::Appdb::Master < ::Thor
28
28
  end
29
29
  class_eval %Q^
30
30
  def #{probe.declaration}(*args)
31
- #{probe}.new.run(options, args)
31
+ #{probe}.new(options).run(args)
32
32
  end
33
33
  ^
34
34
  end
@@ -18,23 +18,26 @@ class Nagios::Promoo::Appdb::Probes::AppliancesProbe < Nagios::Promoo::Appdb::Pr
18
18
  def runnable?; true; end
19
19
  end
20
20
 
21
- def run(options, args = [])
22
- count = nil
23
- begin
24
- count = Timeout::timeout(options[:timeout]) { check_appliances(options) }
25
- fail "No appliances found in AppDB" if count < 1
26
- rescue => ex
27
- puts "APPLIANCES CRITICAL - #{ex.message}"
28
- puts ex.backtrace if options[:debug]
21
+ def run(args = [])
22
+ @_count = 0
23
+
24
+ Timeout::timeout(options[:timeout]) { check_appliances }
25
+
26
+ if @_count < 1
27
+ puts "APPLIANCES CRITICAL - No appliances found in AppDB"
29
28
  exit 2
30
29
  end
31
30
 
32
- puts "APPLIANCES OK - Found #{count} appliances in AppDB"
31
+ puts "APPLIANCES OK - Found #{@_count} appliances in AppDB"
32
+ rescue => ex
33
+ puts "APPLIANCES UNKNOWN - #{ex.message}"
34
+ puts ex.backtrace if options[:debug]
35
+ exit 3
33
36
  end
34
37
 
35
38
  private
36
39
 
37
- def check_appliances(options)
38
- [appdb_provider(options)['provider:image']].flatten.compact.count
40
+ def check_appliances
41
+ @_count = [appdb_provider['provider:image']].flatten.compact.count
39
42
  end
40
43
  end
@@ -6,18 +6,37 @@ class Nagios::Promoo::Appdb::Probes::BaseProbe
6
6
  APPDB_PROXY_URL = 'https://appdb.egi.eu/api/proxy'
7
7
  APPDB_REQUEST_FORM = 'version=1.0&resource=broker&data=%3Cappdb%3Abroker%20xmlns%3Axs%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%22%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance%22%20xmlns%3Aappdb%3D%22http%3A%2F%2Fappdb.egi.eu%2Fapi%2F1.0%2Fappdb%22%3E%3Cappdb%3Arequest%20id%3D%22vaproviders%22%20method%3D%22GET%22%20resource%3D%22va_providers%22%3E%3Cappdb%3Aparam%20name%3D%22listmode%22%3Edetails%3C%2Fappdb%3Aparam%3E%3C%2Fappdb%3Arequest%3E%3C%2Fappdb%3Abroker%3E'
8
8
 
9
- def appdb_provider(options)
10
- return @provider if @provider
9
+ attr_reader :options
10
+
11
+ def initialize(options)
12
+ @options = options
13
+ end
14
+
15
+ def appdb_provider
16
+ return @_provider if @_provider
11
17
 
12
18
  response = HTTParty.post(APPDB_PROXY_URL, { :body => APPDB_REQUEST_FORM })
13
19
  fail "Could not get site"\
14
- "details from AppDB [#{response.code}]" unless response.success?
20
+ "details from AppDB [HTTP #{response.code}]" unless response.success?
21
+ fail "Response from AppDB has unexpected structure" unless valid_response?(response.parsed_response)
22
+
23
+ providers = response.parsed_response['appdb:broker']['appdb:reply']['appdb:appdb']['virtualization:provider']
24
+ providers.delete_if { |prov| prov['provider:endpoint_url'].blank? }
25
+
26
+ @_provider = providers.select do |prov|
27
+ prov['provider:endpoint_url'].chomp('/') == options[:endpoint].chomp('/')
28
+ end.first
29
+ fail "Could not locate site by endpoint #{options[:endpoint].inspect} in AppDB" unless @_provider
30
+
31
+ @_provider
32
+ end
15
33
 
16
- @provider = response.parsed_response['appdb:broker']['appdb:reply']['appdb:appdb']['virtualization:provider'].select do |prov|
17
- prov['provider:endpoint_url'] && (prov['provider:endpoint_url'].chomp('/') == options[:endpoint].chomp('/'))
18
- end.first
19
- fail "Could not locate site by endpoint #{options[:endpoint].inspect} in AppDB" unless @provider
34
+ private
20
35
 
21
- @provider
36
+ def valid_response?(response)
37
+ response['appdb:broker'] \
38
+ && response['appdb:broker']['appdb:reply'] \
39
+ && response['appdb:broker']['appdb:reply']['appdb:appdb'] \
40
+ && response['appdb:broker']['appdb:reply']['appdb:appdb']['virtualization:provider']
22
41
  end
23
42
  end
@@ -4,7 +4,7 @@ require File.join(File.dirname(__FILE__), 'base_probe')
4
4
  class Nagios::Promoo::Appdb::Probes::SizesProbe < Nagios::Promoo::Appdb::Probes::BaseProbe
5
5
  class << self
6
6
  def description
7
- ['sizes', 'Run a probe checking size templates in AppDB']
7
+ ['sizes', 'Run a probe checking size/flavor/resource templates in AppDB']
8
8
  end
9
9
 
10
10
  def options
@@ -18,23 +18,26 @@ class Nagios::Promoo::Appdb::Probes::SizesProbe < Nagios::Promoo::Appdb::Probes:
18
18
  def runnable?; true; end
19
19
  end
20
20
 
21
- def run(options, args = [])
22
- count = nil
23
- begin
24
- count = Timeout::timeout(options[:timeout]) { check_sizes(options) }
25
- fail "No size templates found in AppDB" if count < 1
26
- rescue => ex
27
- puts "SIZES CRITICAL - #{ex.message}"
28
- puts ex.backtrace if options[:debug]
21
+ def run(args = [])
22
+ @_count = 0
23
+
24
+ Timeout::timeout(options[:timeout]) { check_sizes }
25
+
26
+ if @_count < 1
27
+ puts "SIZES CRITICAL - No size/flavor/resource templates found in AppDB"
29
28
  exit 2
30
29
  end
31
30
 
32
- puts "SIZES OK - Found #{count} size templates in AppDB"
31
+ puts "SIZES OK - Found #{@_count} size/flavor/resource templates in AppDB"
32
+ rescue => ex
33
+ puts "SIZES UNKNOWN - #{ex.message}"
34
+ puts ex.backtrace if options[:debug]
35
+ exit 3
33
36
  end
34
37
 
35
38
  private
36
39
 
37
- def check_sizes(options)
38
- [appdb_provider(options)['provider:template']].flatten.compact.count
40
+ def check_sizes
41
+ @_count = [appdb_provider['provider:template']].flatten.compact.count
39
42
  end
40
43
  end
@@ -26,91 +26,79 @@ class Nagios::Promoo::Appdb::Probes::VmcatcherProbe < Nagios::Promoo::Appdb::Pro
26
26
  IMAGE_LIST_TEMPLATE = "https://$$TOKEN$$:x-oauth-basic@vmcaster.appdb.egi.eu/store/vo/$$VO$$/image.list"
27
27
  IMAGE_LIST_BOUNDARY_REGEXP = /boundary="(?<prefix>-+)(?<id>[[:alnum:]]+)"/
28
28
 
29
- def run(options, args = [])
30
- results = begin
31
- Timeout::timeout(options[:timeout]) { check_vmc_sync(options) }
32
- rescue => ex
33
- puts "VMCATCHER CRITICAL - #{ex.message}"
34
- puts ex.backtrace if options[:debug]
35
- exit 2
36
- end
37
-
38
- if results[:missing].count >= options[:missing_critical]
39
- puts "VMCATCHER CRITICAL - #{results[:missing].count} appliance(s) in #{options[:vo].inspect} missing"
29
+ def run(args = [])
30
+ @_results = { found: [], outdated: [], missing: [], expected: [] }
31
+
32
+ Timeout::timeout(options[:timeout]) { check_vmc_sync }
33
+
34
+ if @_results[:missing].count >= options[:missing_critical]
35
+ puts "VMCATCHER CRITICAL - #{@_results[:missing].count} appliance(s) in #{options[:vo].inspect} missing"
36
+ exit 2
37
+ end
38
+
39
+ if @_results[:outdated].count >= options[:outdated_critical]
40
+ puts "VMCATCHER CRITICAL - #{@_results[:outdated].count} appliance(s) in #{options[:vo].inspect} outdated"
40
41
  exit 2
41
42
  end
42
43
 
43
- ## TODO: checking for outdated appliances is not working yet
44
- ##
45
- # if results[:outdated].count >= options[:outdated_critical]
46
- # puts "VMCATCHER CRITICAL - #{results[:outdated].count} appliance(s) in #{options[:vo].inspect} outdated"
47
- # exit 2
48
- # end
49
- #
50
- # if results[:outdated].count > 0
51
- # puts "VMCATCHER WARNING - #{results[:outdated].count} appliances in #{options[:vo].inspect} outdated"
52
- # exit 1
53
- # end
54
-
55
- puts "VMCATCHER OK - All appliances registered in #{options[:vo].inspect} are available [#{results[:expected].count}]"
44
+ if @_results[:outdated].count > 0
45
+ puts "VMCATCHER WARNING - #{@_results[:outdated].count} appliances in #{options[:vo].inspect} outdated"
46
+ exit 1
47
+ end
48
+
49
+ puts "VMCATCHER OK - All appliances registered in #{options[:vo].inspect} are available [#{@_results[:expected].count}]"
50
+ rescue => ex
51
+ puts "VMCATCHER UNKNOWN - #{ex.message}"
52
+ puts ex.backtrace if options[:debug]
53
+ exit 3
56
54
  end
57
55
 
58
56
  private
59
57
 
60
- def check_vmc_sync(options)
61
- results = { found: [], outdated: [], missing: [], expected: [] }
62
-
63
- vo_list(options).each do |mpuri|
64
- mpuri_versionless = versionless_mpuri(mpuri)
65
- mpuri_normalized = normalize_mpuri(mpuri)
66
- results[:expected] << mpuri_versionless
67
-
68
- if normalized_appliances(options).include?(mpuri_normalized)
69
- results[:found] << mpuri_normalized
70
- elsif versionless_appliances(options).include?(mpuri_versionless)
71
- results[:found] << mpuri_versionless
72
- results[:outdated] << mpuri_versionless
73
- else
74
- results[:missing] << mpuri_versionless
58
+ def check_vmc_sync
59
+ vo_list.each do |hv_image|
60
+ mpuri_versionless = versionless_mpuri(hv_image['ad:mpuri'])
61
+ @_results[:expected] << mpuri_versionless
62
+
63
+ matching = provider_appliances.select { |appl| appl['mp_uri'] == mpuri_versionless }.first
64
+
65
+ unless matching
66
+ @_results[:missing] << mpuri_versionless
67
+ next
75
68
  end
76
- end
77
69
 
78
- results
70
+ @_results[:outdated] << mpuri_versionless if hv_image['hv:version'] != matching['vmiversion']
71
+ @_results[:found] << mpuri_versionless
72
+ end
79
73
  end
80
74
 
81
- def provider_appliances(options)
82
- images = [appdb_provider(options)['provider:image']].flatten.compact
83
- images.collect { |image| image['mp_uri'] }.reject { |mpuri| mpuri.blank? }
84
- end
75
+ def provider_appliances
76
+ return @_appliances if @_appliances
85
77
 
86
- def normalized_appliances(options)
87
- provider_appliances(options).collect { |mpuri| normalize_mpuri(mpuri) }
88
- end
78
+ @_appliances = [appdb_provider['provider:image']].flatten.compact
79
+ @_appliances.keep_if { |appliance| appliance['voname'] == options[:vo] }
80
+ @_appliances.reject { |appliance| appliance['mp_uri'].blank? }
89
81
 
90
- def versionless_appliances(options)
91
- provider_appliances(options).collect { |mpuri| versionless_mpuri(mpuri) }
82
+ @_appliances.each do |appliance|
83
+ appliance['mp_uri'] = versionless_mpuri(appliance['mp_uri'])
84
+ end
85
+
86
+ @_appliances
92
87
  end
93
88
 
94
- def vo_list(options)
95
- return @mpuris if @mpuris
96
-
97
- list = nil
98
- begin
99
- list_url = IMAGE_LIST_TEMPLATE.gsub('$$TOKEN$$', options[:token]).gsub('$$VO$$', options[:vo])
100
- response = HTTParty.get(list_url)
101
- fail "Could not get a VO-wide image list" \
102
- "from #{list_url.inspect} [#{response.code}]" unless response.success?
103
-
104
- list = JSON.parse(OpenSSL::PKCS7.read_smime(response.parsed_response).data) # TODO: validate the signature?
105
- fail "AppDB image list #{list_url.inspect} does " \
106
- "not contain images" unless list && list['hv:imagelist'] && list['hv:imagelist']['hv:images']
107
- rescue => ex
108
- puts "VMCATCHER UNKNOWN - #{ex.message}"
109
- puts ex.backtrace if options[:debug]
110
- exit 3
111
- end
89
+ def vo_list
90
+ return @_hv_images if @_hv_images
91
+
92
+ list_url = IMAGE_LIST_TEMPLATE.gsub('$$TOKEN$$', options[:token]).gsub('$$VO$$', options[:vo])
93
+ response = HTTParty.get list_url
94
+ fail "Could not get a VO-wide image list" \
95
+ "from #{list_url.inspect} [#{response.code}]" unless response.success?
96
+
97
+ list = JSON.parse OpenSSL::PKCS7.read_smime(response.parsed_response).data
98
+ fail "AppDB image list #{list_url.inspect} does " \
99
+ "not contain images" unless list && list['hv:imagelist'] && list['hv:imagelist']['hv:images']
112
100
 
113
- @mpuris = list['hv:imagelist']['hv:images'].collect { |im| im['hv:image']['ad:mpuri'] }.reject { |uri| uri.blank? }
101
+ @_hv_images = list['hv:imagelist']['hv:images'].collect { |im| im['hv:image'] }.reject { |im| im.blank? || im['ad:mpuri'].blank? }
114
102
  end
115
103
 
116
104
  def normalize_mpuri(mpuri)
@@ -1,7 +1,7 @@
1
1
  module Nagios
2
2
  module Promoo
3
3
  module Appdb
4
- VERSION = "0.0.1"
4
+ VERSION = "1.0.0"
5
5
  end
6
6
  end
7
7
  end
@@ -33,7 +33,7 @@ class Nagios::Promoo::Occi::Master < ::Thor
33
33
  end
34
34
  class_eval %Q^
35
35
  def #{probe.declaration}(*args)
36
- #{probe}.new.run(options, args)
36
+ #{probe}.new(options).run(args)
37
37
  end
38
38
  ^
39
39
  end
@@ -3,8 +3,14 @@ class Nagios::Promoo::Occi::Probes::BaseProbe
3
3
  def runnable?; false; end
4
4
  end
5
5
 
6
- def client(options)
7
- @client ||= Occi::Api::Client::ClientHttp.new({
6
+ attr_reader :options
7
+
8
+ def initialize(options)
9
+ @options = options
10
+ end
11
+
12
+ def client
13
+ @_client ||= Occi::Api::Client::ClientHttp.new({
8
14
  :endpoint => options[:endpoint],
9
15
  :auth => {
10
16
  :type => options[:auth].gsub('-voms', ''),
@@ -23,34 +23,32 @@ class Nagios::Promoo::Occi::Probes::CategoriesProbe < Nagios::Promoo::Occi::Prob
23
23
  def runnable?; true; end
24
24
  end
25
25
 
26
- def run(options, args = [])
26
+ def run(args = [])
27
27
  categories = all_categories
28
28
  categories -= options[:optional] if options[:optional]
29
29
 
30
- begin
31
- Timeout::timeout(options[:timeout]) do
32
- categories.each do |cat|
33
- fail "#{cat.inspect} is missing" unless client(options).model.get_by_id(cat, true)
34
- next unless options[:check_location] && Nagios::Promoo::Occi::Probes::KindsProbe::INFRA_KINDS.include?(cat)
35
-
36
- # Make sure declared locations are actually available as REST
37
- # endpoints. Failure will raise an exception, no need to do
38
- # anything here. To keep requirements reasonable, only INFRA
39
- # kinds are considered relevant for this part of the check.
40
- begin
41
- client(options).list(cat)
42
- rescue => err
43
- fail "Failed to verify declared REST location for #{cat.inspect} (#{err.message})"
44
- end
30
+ Timeout::timeout(options[:timeout]) do
31
+ categories.each do |cat|
32
+ fail "#{cat.inspect} is missing" unless client.model.get_by_id(cat, true)
33
+ next unless options[:check_location] && Nagios::Promoo::Occi::Probes::KindsProbe::INFRA_KINDS.include?(cat)
34
+
35
+ # Make sure declared locations are actually available as REST
36
+ # endpoints. Failure will raise an exception, no need to do
37
+ # anything here. To keep requirements reasonable, only INFRA
38
+ # kinds are considered relevant for this part of the check.
39
+ begin
40
+ client.list(cat)
41
+ rescue => err
42
+ fail "Failed to verify declared REST location for #{cat.inspect} (#{err.message})"
45
43
  end
46
44
  end
47
- rescue => ex
48
- puts "CATEGORIES CRITICAL - #{ex.message}"
49
- puts ex.backtrace if options[:debug]
50
- exit 2
51
45
  end
52
46
 
53
47
  puts 'CATEGORIES OK - All specified OCCI categories were found'
48
+ rescue => ex
49
+ puts "CATEGORIES CRITICAL - #{ex.message}"
50
+ puts ex.backtrace if options[:debug]
51
+ exit 2
54
52
  end
55
53
 
56
54
  private
@@ -33,127 +33,120 @@ class Nagios::Promoo::Occi::Probes::ComputeProbe < Nagios::Promoo::Occi::Probes:
33
33
  APPDB_PROXY_URL = 'https://appdb.egi.eu/api/proxy'
34
34
  APPDB_REQUEST_FORM = 'version=1.0&resource=broker&data=%3Cappdb%3Abroker%20xmlns%3Axs%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%22%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance%22%20xmlns%3Aappdb%3D%22http%3A%2F%2Fappdb.egi.eu%2Fapi%2F1.0%2Fappdb%22%3E%3Cappdb%3Arequest%20id%3D%22vaproviders%22%20method%3D%22GET%22%20resource%3D%22va_providers%22%3E%3Cappdb%3Aparam%20name%3D%22listmode%22%3Edetails%3C%2Fappdb%3Aparam%3E%3C%2Fappdb%3Arequest%3E%3C%2Fappdb%3Abroker%3E'
35
35
 
36
- def run(options, args = [])
37
- links = begin
38
- Timeout::timeout(options[:timeout]) { compute_provision(options) }
39
- rescue Timeout::Error => ex
40
- puts "COMPUTE CRITICAL - Probe execution timed out [#{options[:timeout]}s]"
41
- exit 2
42
- end
36
+ def run(args = [])
37
+ @_links = {}
43
38
 
44
- puts "COMPUTE OK - Instance(s) #{links[:compute].inspect} created & cleaned up"
39
+ Timeout::timeout(options[:timeout]) { compute_provision }
40
+ puts "COMPUTE OK - Instance(s) #{@_links[:compute].inspect} created & cleaned up"
41
+ rescue Timeout::Error => ex
42
+ puts "COMPUTE CRITICAL - Probe execution timed out [#{options[:timeout]}s]"
43
+ exit 2
45
44
  end
46
45
 
47
46
  private
48
47
 
49
- def compute_provision(options)
50
- links = {}
51
-
52
- compute_link = compute_create(options)
53
- links[:compute] = compute_link
54
- wait4ready(compute_link, options)
48
+ def compute_provision
49
+ compute_create
55
50
 
56
51
  if options[:with_storage]
57
- storage_link = storage_create(options)
58
- links[:storage] = storage_link
59
- wait4ready(storage_link, options)
60
-
61
- slink = link_instances(compute_link, storage_link, options)
62
- links[:storagelink] = slink
63
- wait4ready(slink, options)
52
+ storage_create
53
+ link_instances
64
54
  end
65
-
66
- links
67
55
  rescue => ex
68
56
  puts "COMPUTE CRITICAL - #{ex.message}"
69
57
  puts ex.backtrace if options[:debug]
70
58
  exit 2
71
59
  ensure
72
- mandatory_cleanup links, options
60
+ mandatory_cleanup @_links
73
61
  end
74
62
 
75
- def compute_create(options)
76
- client(options).delete('compute') if options[:cleanup]
63
+ def compute_create
64
+ client.delete('compute') if options[:cleanup]
77
65
 
78
- compute = client(options).get_resource('compute')
66
+ compute = client.get_resource('compute')
79
67
  compute.title = compute.hostname = "#{COMPUTE_NAME_PREFIX}-#{Time.now.to_i}"
80
68
 
81
- os_tpl, resource_tpl = appdb_information(options)
82
- compute.mixins << get_mixin(os_tpl, 'os_tpl', options)
83
- compute.mixins << get_mixin(resource_tpl, 'resource_tpl', options)
69
+ os_tpl, resource_tpl = appdb_information
70
+ compute.mixins << get_mixin(os_tpl, 'os_tpl')
71
+ compute.mixins << get_mixin(resource_tpl, 'resource_tpl')
84
72
 
85
- client(options).create compute
73
+ @_links[:compute] = client.create compute
74
+ wait4ready @_links[:compute]
86
75
  end
87
76
 
88
- def storage_create(options)
89
- client(options).delete('storage') if options[:cleanup]
77
+ def storage_create
78
+ client.delete('storage') if options[:cleanup]
90
79
 
91
- storage = client(options).get_resource('storage')
80
+ storage = client.get_resource('storage')
92
81
  storage.title = "#{COMPUTE_NAME_PREFIX}-block-#{Time.now.to_i}"
93
82
  storage.size = DEFAULT_STORAGE_SIZE # GB
94
83
 
95
- client(options).create storage
84
+ @_links[:storage] = client.create storage
85
+ wait4ready @_links[:storage]
96
86
  end
97
87
 
98
- def link_instances(compute_link, storage_link, options)
99
- slink = client(options).get_link('storagelink')
100
- slink.source = compute_link
101
- slink.target = storage_link
88
+ def link_instances
89
+ slink = client.get_link('storagelink')
90
+ slink.source = @_links[:compute]
91
+ slink.target = @_links[:storage]
102
92
 
103
- client(options).create slink
93
+ @_links[:storagelink] = client.create slink
94
+ wait4ready @_links[:storagelink]
104
95
  end
105
96
 
106
- def mandatory_cleanup(links, options)
107
- mandatory_cleanup_part links[:storagelink], true, options
108
- mandatory_cleanup_part links[:storage], false, options
109
- mandatory_cleanup_part links[:compute], false, options
97
+ def mandatory_cleanup(links)
98
+ mandatory_cleanup_part links[:storagelink], true
99
+ mandatory_cleanup_part links[:storage], false
100
+ mandatory_cleanup_part links[:compute], false
110
101
  end
111
102
 
112
- def mandatory_cleanup_part(link, wait4inactive, options)
113
- client(options).delete link
114
- wait4inactive(link, options) if wait4inactive
103
+ def mandatory_cleanup_part(link, wait4inactive)
104
+ client.delete link
105
+ wait4inactive(link) if wait4inactive
115
106
  rescue => ex
116
107
  # ignore
117
108
  end
118
109
 
119
- def get_mixin(term, type, options)
120
- mxn = client(options).get_mixin(term, type, true)
110
+ def get_mixin(term, type)
111
+ mxn = client.get_mixin(term, type, true)
121
112
  fail "Mixin #{term.inspect} of type #{type.inspect} not found at the site" unless mxn
122
113
  mxn
123
114
  end
124
115
 
125
- def wait4ready(link, options)
116
+ def wait4ready(link)
126
117
  state = nil
127
118
 
128
119
  while !READY_STATES.include?(state) do
129
- state = client(options).describe(link).first.state
120
+ state = client.describe(link).first.state
130
121
  fail "Provisioning failure on #{link.inspect}" if ERROR_STATES.include?(state)
131
122
  sleep 5
132
123
  end
133
124
  end
134
125
 
135
- def wait4inactive(link, options)
126
+ def wait4inactive(link)
136
127
  state = nil
137
128
 
138
129
  while !NONREADY_STATES.include?(state) do
139
- state = client(options).describe(link).first.state
130
+ state = client.describe(link).first.state
140
131
  fail "De-provisioning failure on #{link.inspect}" if ERROR_STATES.include?(state)
141
132
  sleep 5
142
133
  end
143
134
  end
144
135
 
145
- def appdb_information(options)
146
- [appdb_appliance(options), appdb_smallest_size(options)]
136
+ def appdb_information
137
+ [appdb_appliance, appdb_smallest_size]
147
138
  rescue => ex
148
139
  puts "COMPUTE UNKNOWN - #{ex.message}"
149
140
  puts ex.backtrace if options[:debug]
150
141
  exit 3
151
142
  end
152
143
 
153
- def appdb_appliance(options)
154
- appliance = nil
155
- appliance = [appdb_provider(options)['provider:image']].flatten.compact.select do |image|
156
- image['mp_uri'] && (normalize_mpuri(image['mp_uri']) == normalize_mpuri(options[:mpuri]))
144
+ def appdb_appliance
145
+ appliances = [appdb_provider['provider:image']].flatten.compact
146
+ appliances.delete_if { |appl| appl['mp_uri'].blank? }
147
+
148
+ appliance = appliances.select do |appl|
149
+ normalize_mpuri(appl['mp_uri']) == normalize_mpuri(options[:mpuri])
157
150
  end.first
158
151
  fail "Site does not have an appliance with MPURI "\
159
152
  "#{normalize_mpuri(options[:mpuri]).inspect} published in AppDB" if appliance.blank?
@@ -161,41 +154,55 @@ class Nagios::Promoo::Occi::Probes::ComputeProbe < Nagios::Promoo::Occi::Probes:
161
154
  appliance['va_provider_image_id'].split('#').last
162
155
  end
163
156
 
164
- def appdb_smallest_size(options)
157
+ def appdb_smallest_size
165
158
  sizes = []
166
- [appdb_provider(options)['provider:template']].flatten.compact.each do |template|
159
+ templates = [appdb_provider['provider:template']].flatten.compact
160
+
161
+ templates.each do |template|
167
162
  sizes << [
168
163
  template['provider_template:resource_name'].split('#').last,
169
164
  template['provider_template:main_memory_size'].to_i + (template['provider_template:physical_cpus'].to_i * CPU_SUM_WEIGHT)
170
165
  ]
171
166
  end
172
167
  fail "No appliance sizes available in AppDB" if sizes.blank?
173
- sizes.sort! { |x,y| x.last <=> y.last }
174
168
 
169
+ sizes.sort! { |x,y| x.last <=> y.last }
175
170
  sizes.first.first
176
171
  end
177
172
 
178
- def appdb_provider(options)
179
- return @provider if @provider
173
+ def appdb_provider
174
+ return @_provider if @_provider
180
175
 
181
176
  parsed_response = cache_fetch('appdb-sites', options[:cache_expiration]) do
182
177
  response = HTTParty.post(APPDB_PROXY_URL, { :body => APPDB_REQUEST_FORM })
183
178
  fail "Could not get appliance "\
184
179
  "details from AppDB [#{response.code}]" unless response.success?
180
+ fail "Response from AppDB has unexpected structure" unless valid_response?(response.parsed_response)
181
+
185
182
  response.parsed_response
186
183
  end
187
184
 
188
- @provider = parsed_response['appdb:broker']['appdb:reply']['appdb:appdb']['virtualization:provider'].select do |prov|
189
- prov['provider:endpoint_url'] && (prov['provider:endpoint_url'].chomp('/') == options[:endpoint].chomp('/'))
185
+ providers = parsed_response['appdb:broker']['appdb:reply']['appdb:appdb']['virtualization:provider']
186
+ providers.delete_if { |prov| prov['provider:endpoint_url'].blank? }
187
+
188
+ @_provider = providers.select do |prov|
189
+ prov['provider:endpoint_url'].chomp('/') == options[:endpoint].chomp('/')
190
190
  end.first
191
- fail "Could not locate site by endpoint #{options[:endpoint].inspect} in AppDB" unless @provider
191
+ fail "Could not locate site by endpoint #{options[:endpoint].inspect} in AppDB" unless @_provider
192
192
 
193
- @provider
193
+ @_provider
194
194
  end
195
195
 
196
196
  def normalize_mpuri(mpuri)
197
197
  mpuri.gsub(/\/+$/, '').gsub(/:\d+$/, '')
198
198
  end
199
199
 
200
+ def valid_response?(response)
201
+ response['appdb:broker'] \
202
+ && response['appdb:broker']['appdb:reply'] \
203
+ && response['appdb:broker']['appdb:reply']['appdb:appdb'] \
204
+ && response['appdb:broker']['appdb:reply']['appdb:appdb']['virtualization:provider']
205
+ end
206
+
200
207
  include Nagios::Promoo::Utils::Cache
201
208
  end