Class: Connection
- Inherits:
-
Object
- Object
- Connection
- Defined in:
- lib/chef/knife/connection.rb
Overview
This class should be a singleton with all the logic to use proxmox
Instance Method Summary collapse
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize ⇒ Connection
Returns a new instance of Connection.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/chef/knife/connection.rb', line 10 def initialize() @site = RestClient::Resource.new(Chef::Config[:knife][:pve_cluster_url]) @auth_params ||= begin ticket = nil csrf_prevention_token = nil @site['access/ticket'].post :username=>Chef::Config[:knife][:pve_user_name], :realm=>Chef::Config[:knife][:pve_user_realm], :password=>Chef::Config[:knife][:pve_user_password] do |response, request, result, &block| if response.code == 200 then data = JSON.parse(response.body) ticket = data['data']['ticket'] csrf_prevention_token = data['data']['CSRFPreventionToken'] if !ticket.nil? then token = 'PVEAuthCookie=' + ticket.gsub!(/:/,'%3A').gsub!(/=/,'%3D') end end end {:CSRFPreventionToken => csrf_prevention_token, :cookie => token} end end |