Module: XenAPI::HypervisorConnection

Defined in:
lib/xenapi/hypervisor_connection.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.close_hypervisor_session!Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/xenapi/hypervisor_connection.rb', line 23

def close_hypervisor_session!
  sessions.each do |host, session|
    begin
      session.close unless session.nil?
    rescue Exception => error
      Rails.logger.error("Error while trying to close connection to #{host}")
      Rails.logger.error(error)
    end
  end
  @sessions = {}
end

.hypervisor_session(host) ⇒ Object



5
6
7
# File 'lib/xenapi/hypervisor_connection.rb', line 5

def hypervisor_session(host)
  sessions[host.ip] ||= hypervisor_session!(host)
end

.hypervisor_session!(host) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/xenapi/hypervisor_connection.rb', line 9

def hypervisor_session!(host)
  Rails.logger.info "Connecting to hypervisor on #{host.ip} with user #{host.username}"
  session = SessionFactory.create(host.ip, host.username, host.password) do |error, &called_method|
    Rails.logger.error(error)
    session = HypervisorErrorHandler.new(host.pool, error).handle_error

    if called_method
      called_method.call(session)
    else
      session
    end
  end
end

Instance Method Details

#hypervisor_sessionObject



41
42
43
44
# File 'lib/xenapi/hypervisor_connection.rb', line 41

def hypervisor_session
  raise "Pool not found for #{self.inspect}" unless self.pool
  HypervisorConnection.hypervisor_session(self.pool.master)
end