ManageIQ/manageiq-providers-red_hat_virtualization

View on GitHub
app/models/manageiq/providers/redhat/discovery.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
require 'manageiq/network_discovery/port'

module ManageIQ
  module Providers
    module Redhat
      class Discovery
        OVIRT_DEFAULT_PORT = 443

        class << self
          def probe(ost)
            if ManageIQ::NetworkDiscovery::Port.open?(ost, OVIRT_DEFAULT_PORT) &&
               ovirt_exists?(ost.ipaddr, $rhevm_log)
              ost.hypervisor << :rhevm
            end
          end

          private

          def ovirt_exists?(host, logger = nil)
            require 'ovirtsdk4'

            opts = {
              :host => host,
              :log  => logger
            }.compact
            OvirtSDK4::Probe.exists?(opts)
          rescue OvirtSDK4::Error
            false
          end
        end
      end
    end
  end
end