Module: ForemanFogProxmox::ProxmoxConnection

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

Instance Method Summary collapse

Instance Method Details

#access_ticket?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/models/foreman_fog_proxmox/proxmox_connection.rb', line 31

def access_ticket?
  auth_method == 'access_ticket'
end

#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)


39
40
41
42
43
44
45
46
47
# File 'app/models/foreman_fog_proxmox/proxmox_connection.rb', line 39

def credentials_valid?
  errors[:url].empty? && errors[:auth_method].empty?
  if access_ticket?
    errors[:user].empty? && errors[:user].include?('@') && errors[:password].empty? && errors[:node_id].empty?
  end
  if user_token?
    errors[:user].empty? && errors[:user].include?('@') && errors[:token_id].empty? && errors[:token].empty? && errors[:node_id].empty?
  end
end

#current_user_token_expireObject



49
50
51
# File 'app/models/foreman_fog_proxmox/proxmox_connection.rb', line 49

def current_user_token_expire
  identity_client ? identity_client.expires : 0
end

#disconnectObject



67
68
69
70
71
72
73
74
# File 'app/models/foreman_fog_proxmox/proxmox_connection.rb', line 67

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

#test_connection(options = {}) ⇒ Object



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

def test_connection(options = {})
  super
  credentials_valid?
  identity_client
  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

#user_token?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/models/foreman_fog_proxmox/proxmox_connection.rb', line 35

def user_token?
  auth_method == 'user_token'
end