Module: ForemanFogProxmox::ProxmoxConnection

Included in:
Proxmox
Defined in:
app/models/foreman_fog_proxmox/proxmox_connection.rb

Instance Method Summary collapse

Instance Method Details

#connection_optionsObject



24
25
26
27
28
29
# File 'app/models/foreman_fog_proxmox/proxmox_connection.rb', line 24

def connection_options
  opts = super
  opts.store(:ssl_verify_peer, ssl_verify_peer)
  opts.store(:ssl_cert_store, certs_to_store) if Foreman::Cast.to_bool(ssl_verify_peer)
  opts
end

#credentials_valid?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/foreman_fog_proxmox/proxmox_connection.rb', line 41

def credentials_valid?
  errors[:url].empty? && errors[:user].empty? && errors[:user].include?('@') && errors[:password].empty? && errors[:node_id].empty?
end

#disconnectObject



58
59
60
61
62
63
64
65
# File 'app/models/foreman_fog_proxmox/proxmox_connection.rb', line 58

def disconnect
  client.terminate if @client
  @client = nil
  identity_client.terminate if @identity_client
  @identity_client = nil
  network_client.terminate if @network_client
  @network_client = nil
end

#fog_credentialsObject



31
32
33
34
35
36
37
38
39
# File 'app/models/foreman_fog_proxmox/proxmox_connection.rb', line 31

def fog_credentials
  credentials = { pve_url: url,
                  pve_username: user,
                  pve_password: password,
                  connection_options: connection_options }
  ticket = Fog::Proxmox.credentials[:ticket]
  credentials.store(:pve_ticket, ticket) if renew
  credentials
end

#test_connection(options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/foreman_fog_proxmox/proxmox_connection.rb', line 45

def test_connection(options = {})
  super
  credentials_valid?
  version_suitable?
rescue StandardError => e
  errors[:base] << e.message
  if e.message.include?('SSL')
    errors[:ssl_certs] << e.message
  else
    errors[:url] << e.message
  end
end