Class: Proxmox::Resources::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/proxmox/resources/node.rb

Overview

Proxmox Node Class

Constant Summary collapse

STATS_ATTRIBUTES =

Define the attributes we expect from the API

%i[id cpu maxcpu mem maxmem uptime].freeze

Instance Method Summary collapse

Constructor Details

#initialize(client, name_or_data) ⇒ Node

Returns a new instance of Node.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/proxmox/resources/node.rb', line 12

def initialize(client, name_or_data)
  @client = client
  if name_or_data.is_a?(Hash)
    @node = name_or_data["node"]
    @raw_status = name_or_data["status"]

    # Dynamically set known attributes to avoid boilerplate
    STATS_ATTRIBUTES.each do |attr|
      instance_variable_set("@#{attr}", name_or_data[attr.to_s])
    end
  else
    @node = name_or_data
  end
end

Instance Method Details

#clusterObject

Access the Cluster resource



36
37
38
# File 'lib/proxmox/resources/node.rb', line 36

def cluster
  @client.cluster
end

#create_vm(params) ⇒ Object

Creating Resources



51
52
53
# File 'lib/proxmox/resources/node.rb', line 51

def create_vm(params)
  @client.request(:post, "/nodes/#{@node}/qemu", {}, params)
end

#inspectObject



27
28
29
# File 'lib/proxmox/resources/node.rb', line 27

def inspect
  "#<Proxmox::Resources::Node name=#{@node} status=#{@raw_status}>"
end

#online?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/proxmox/resources/node.rb', line 31

def online?
  @raw_status == "online"
end

#statusObject

Getting status of the Node



41
42
43
# File 'lib/proxmox/resources/node.rb', line 41

def status
  @client.request(:get, "/nodes/#{@node}/status")
end

#updatesObject

Getting a list of updates for the Node



46
47
48
# File 'lib/proxmox/resources/node.rb', line 46

def updates
  @client.request(:get, "/nodes/#{@node}/apt/update")
end