Module: Fog::Proxmox

Extended by:
Provider
Defined in:
lib/fog/proxmox.rb,
lib/fog/proxmox/core.rb,
lib/fog/proxmox/hash.rb,
lib/fog/proxmox/json.rb,
lib/fog/proxmox/errors.rb,
lib/fog/proxmox/version.rb,
lib/fog/proxmox/variables.rb,
lib/fog/proxmox/models/model.rb,
lib/fog/proxmox/models/collection.rb,
lib/fog/proxmox/helpers/cpu_helper.rb,
lib/fog/proxmox/helpers/nic_helper.rb,
lib/fog/proxmox/helpers/disk_helper.rb,
lib/fog/proxmox/helpers/controller_helper.rb

Overview

Proxmox module

Defined Under Namespace

Modules: ControllerHelper, Core, CpuHelper, DiskHelper, Errors, Hash, Json, NicHelper, Variables Classes: Collection, Model

Constant Summary collapse

VERSION =
'0.5.4'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cacheObject

Returns the value of attribute cache


59
60
61
# File 'lib/fog/proxmox.rb', line 59

def cache
  @cache
end

.versionObject (readonly)

Returns the value of attribute version


60
61
62
# File 'lib/fog/proxmox.rb', line 60

def version
  @version
end

Class Method Details

.authenticate(options, connection_options = {}) ⇒ Object


67
68
69
70
# File 'lib/fog/proxmox.rb', line 67

def self.authenticate(options, connection_options = {})
  get_tokens(options, connection_options)
  @cache
end

.authenticated?Boolean

Returns:

  • (Boolean)

72
73
74
# File 'lib/fog/proxmox.rb', line 72

def self.authenticated?
  !@cache.empty?
end

.clear_cacheObject


63
64
65
# File 'lib/fog/proxmox.rb', line 63

def self.clear_cache
  Fog::Proxmox.cache = {}
end

.extract_password(options) ⇒ Object


76
77
78
79
# File 'lib/fog/proxmox.rb', line 76

def self.extract_password(options)
  ticket = options[:pve_ticket]
  options[:pve_password] = ticket unless ticket
end

.get_tokens(options, connection_options = {}) ⇒ Object


81
82
83
84
85
86
87
88
89
90
# File 'lib/fog/proxmox.rb', line 81

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) ⇒ Object


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/fog/proxmox.rb', line 92

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) ⇒ Object


118
119
120
121
122
123
124
125
126
# File 'lib/fog/proxmox.rb', line 118

def self.save_token(username, ticket, csrftoken, deadline)
  @cache = {
    username: username,
    ticket: ticket,
    csrftoken: csrftoken,
    deadline: deadline
  }
  Fog::Proxmox.cache = @cache
end