Class: OpenNebulaOcciProbe

Inherits:
OpennebulaProbe show all
Defined in:
lib/probe/opennebula_occi_probe.rb

Overview

OpenNebulaOcciProbe - OCCI client query service implementation.

Constant Summary

Constants inherited from OpennebulaProbe

OpennebulaProbe::CRIT_MSG, OpennebulaProbe::OK_MSG, OpennebulaProbe::UNKWN_MSG, OpennebulaProbe::WARN_MSG

Instance Attribute Summary

Attributes inherited from OpennebulaProbe

#logger, #message, #retval

Instance Method Summary collapse

Methods inherited from OpennebulaProbe

#crit?, #run, #warn?

Constructor Details

#initialize(opts) ⇒ OpenNebulaOcciProbe

Returns a new instance of OpenNebulaOcciProbe.



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
# File 'lib/probe/opennebula_occi_probe.rb', line 22

def initialize(opts)
  super(opts)

  if @opts.user_cred
    creds = {
        type:               'x509',
        user_cert:          @opts.user_cred,
        user_cert_password: @opts.password,
        ca_path:            @opts.ca_path,
        ca_file:            @opts.ca_file,
        voms:               @opts.voms
    }
  else
    creds = {
        username: @opts.username,
        password: @opts.password,
        type:     'basic'
    }
  end

  @client = OcciClient.new(
      endpoint: @endpoint,
      auth:     creds,
      occi:     @opts.service,
      template: @opts.template_uuid,
      vmname:   @opts.vmname,
      timeout:  @opts.timeout
  )
end

Instance Method Details

#check_critObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/probe/opennebula_occi_probe.rb', line 52

def check_crit
  @logger.info "Checking for basic connectivity at #{@endpoint}"

  begin
    # make a few simple queries just to be sure that the service is running
    @client.network.all
    # Not supported yet
    @client.compute.all unless @opts.service == 'rocci'
    @client.storage.all
  rescue StandardError => e
    @logger.error "Failed to check connectivity: #{e}"
    @logger.debug "#{e.backtrace.join("\n")}"
    return true
  end

  false
end

#check_resources(resources) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/probe/opennebula_occi_probe.rb', line 70

def check_resources(resources)
  # extract key ":resource" from hashes to new array and determine, if any of them are other than nil
  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

    begin
      @logger.info "Looking for #{resource_hash[:resource_string]}s: #{resource.inspect}"
      result = resource.map { |id| resource_hash[:resource_connection].find id }
      @logger.debug result
    end
  end

  false
end

#check_warnObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/probe/opennebula_occi_probe.rb', line 91

def check_warn
  @logger.info "Checking for resource availability at #{@endpoint}"

  resources = []

  # Not supported yet
  unless @opts.service == 'rocci'
    resources << { resource:            @opts.storage,
                   resource_string:     'image',
                   resource_connection: @client.storage
                 }
  end
  resources   << { resource:            @opts.compute,
                   resource_string:     'compute instance',
                   resource_connection: @client.compute
                 }
  resources   << { resource:            @opts.network,
                   resource_string:     'network',
                   resource_connection: @client.network
                 }

  # Additionally create VM from template when using rOCCI if needed
  if !@opts.template_uuid.nil?
    @client.compute.create_check_destroy
  else
    check_resources(resources)
  end

  false

rescue StandardError => e
  @logger.error "Failed to check resource availability: #{e.message}"
  @logger.debug "#{e.backtrace.join("\n")}"
  return true
end