module Fog::Proxmox

Proxmox module

Constants

VERSION

Attributes

cache[RW]
version[R]

Public Class Methods

authenticate(options, connection_options = {}) click to toggle source
# File lib/fog/proxmox.rb, line 66
def self.authenticate(options, connection_options = {})
  get_tokens(options, connection_options)
  @cache
end
authenticated?() click to toggle source
# File lib/fog/proxmox.rb, line 71
def self.authenticated?
  !@cache.empty?
end
clear_cache() click to toggle source
# File lib/fog/proxmox.rb, line 62
def self.clear_cache
  Fog::Proxmox.cache = {}
end
extract_password(options) click to toggle source
# File lib/fog/proxmox.rb, line 75
def self.extract_password(options)
  ticket = options[:pve_ticket]
  options[:pve_password] = ticket unless ticket
end
get_tokens(options, connection_options = {}) click to toggle source
# File lib/fog/proxmox.rb, line 80
def self.get_tokens(options, connection_options = {})
  username          = options[:pve_username].to_s
  password          = options[:pve_password].to_s
  url               = options[:pve_url]
  extract_password(options)
  uri = URI.parse(url)
  @api_path = uri.path
  connection_options = connection_options.merge(path_prefix: @api_path)
  retrieve_tokens(uri, connection_options, username, password) unless authenticated?
end
retrieve_tokens(uri, connection_options, username, password) click to toggle source
# File lib/fog/proxmox.rb, line 91
def self.retrieve_tokens(uri, connection_options, username, password)
  request = {
    expects: [200, 204],
    headers: { 'Accept' => 'application/json' },
    body: "username=#{username}&password=#{password}",
    method: 'POST',
    path: 'access/ticket'
  }

  connection = Fog::Core::Connection.new(
    uri.to_s,
    false,
    connection_options
  )

  response  = connection.request(request)
  data      = Json.get_data(response)
  ticket    = data['ticket']
  username  = data['username']
  csrftoken = data['CSRFPreventionToken']

  now = Time.now
  deadline = Time.at(now.to_i + @ticket_lifetime)
  save_token(username, ticket, csrftoken, deadline)
end
save_token(username, ticket, csrftoken, deadline) click to toggle source
# File lib/fog/proxmox.rb, line 117
def self.save_token(username, ticket, csrftoken, deadline)
  @cache = {
    username: username,
    ticket: ticket,
    csrftoken: csrftoken,
    deadline: deadline
  }
  Fog::Proxmox.cache = @cache
end