Class: VagrantPlugins::Proxmox::Action::ConnectProxmox

Inherits:
ProxmoxAction
  • Object
show all
Defined in:
lib/vagrant-proxmox/action/connect_proxmox.rb

Overview

This action connects to the Proxmox server and stores the access ticket and csrf prevention token in env and env.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ConnectProxmox

Returns a new instance of ConnectProxmox.



10
11
12
13
# File 'lib/vagrant-proxmox/action/connect_proxmox.rb', line 10

def initialize app, env
	@app = app
	@logger = Log4r::Logger.new 'vagrant_proxmox::action::connect_proxmox'
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vagrant-proxmox/action/connect_proxmox.rb', line 15

def call env
	config = env[:machine].provider_config
	response = RestClient.post "#{config.endpoint}/access/ticket",
	                           username: config.user_name, password: config.password
	begin
		json_response = JSON.parse response.to_s, symbolize_names: true
		env[:proxmox_ticket] = json_response[:data][:ticket]
		env[:proxmox_csrf_prevention_token] = json_response[:data][:CSRFPreventionToken]
	rescue => e
		raise Errors::CommunicationError, error_msg: e.message
	end
	next_action env
end