Class: Proxmox::Client
- Inherits:
-
Object
- Object
- Proxmox::Client
- Defined in:
- lib/proxmox/client.rb
Overview
Proxmox SDK Http Client
Constant Summary collapse
- TOKEN_VALIDITY_SECONDS =
Konstanten für die Gültigkeit des Tokens Proxmox Tickets sind standardmäßig 2 Stunden (7200 Sekunden) gültig.
7200- RENEWAL_BUFFER_SECONDS =
Wir erneuern den Token 5 Minuten (300 Sekunden) vor Ablauf.
300
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#csrf_token ⇒ Object
readonly
Returns the value of attribute csrf_token.
-
#ticket ⇒ Object
readonly
Returns the value of attribute ticket.
Instance Method Summary collapse
- #cluster ⇒ Object
-
#initialize(base_url:, username:, password:, realm: "pam", ignore_ssl: false) ⇒ Client
constructor
A new instance of Client.
- #login ⇒ Object
- #node(name) ⇒ Object
- #nodes ⇒ Object
- #request(method, path, params = {}, body = nil) ⇒ Object
Constructor Details
#initialize(base_url:, username:, password:, realm: "pam", ignore_ssl: false) ⇒ Client
Returns a new instance of Client.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/proxmox/client.rb', line 18 def initialize(base_url:, username:, password:, realm: "pam", ignore_ssl: false) @base_url = base_url @verify_ssl = !ignore_ssl # Anmeldedaten für die automatische Erneuerung speichern @username = username @password = password @realm = realm # Initiales Login login end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
16 17 18 |
# File 'lib/proxmox/client.rb', line 16 def base_url @base_url end |
#csrf_token ⇒ Object (readonly)
Returns the value of attribute csrf_token.
16 17 18 |
# File 'lib/proxmox/client.rb', line 16 def csrf_token @csrf_token end |
#ticket ⇒ Object (readonly)
Returns the value of attribute ticket.
16 17 18 |
# File 'lib/proxmox/client.rb', line 16 def ticket @ticket end |
Instance Method Details
#cluster ⇒ Object
31 32 33 |
# File 'lib/proxmox/client.rb', line 31 def cluster @cluster ||= Proxmox::Resources::Cluster.new(self) end |
#login ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/proxmox/client.rb', line 45 def login resp = http.post("/api2/json/access/ticket", { username: "#{@username}@#{@realm}", password: @password }) raise "Login failed: #{resp.body}" unless resp.success? data = JSON.parse(resp.body)["data"] @ticket = data["ticket"] @csrf_token = data["CSRFPreventionToken"] # Zeitstempel der Ticketerstellung speichern @ticket_creation_time = Time.now end |
#node(name) ⇒ Object
35 36 37 |
# File 'lib/proxmox/client.rb', line 35 def node(name) Proxmox::Resources::Node.new(self, name) end |
#nodes ⇒ Object
39 40 41 42 43 |
# File 'lib/proxmox/client.rb', line 39 def nodes request(:get, "/nodes").map do |node_data| Proxmox::Resources::Node.new(self, node_data) end end |
#request(method, path, params = {}, body = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/proxmox/client.rb', line 58 def request(method, path, params = {}, body = nil) # Vor jeder Anfrage die Gültigkeit des Tokens prüfen und ggf. erneuern ensure_token_validity response = perform_http_call(method, path, params, body) ensure_success!(response) extract_data(response) end |