Class: Pvectl::Models::Node

Inherits:
Base
  • Object
show all
Defined in:
lib/pvectl/models/node.rb

Overview

Represents a node in the Proxmox cluster.

Immutable domain model containing node attributes and domain predicates. Display formatting is handled by Presenters::Node. Created by Repositories::Node from API data.

Examples:

Creating a Node model

node = Node.new(name: "pve1", status: "online", cpu: 0.23)
node.online? #=> true
node.guests_total #=> 42

From API response

data = { "node" => "pve1", "status" => "online", "cpu" => 0.23 }
node = Node.new(data)

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Node

Creates a new Node model from attributes.

Parameters:

  • attrs (Hash) (defaults to: {})

    Node attributes from API (string or symbol keys)



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/pvectl/models/node.rb', line 133

def initialize(attrs = {})
  super(attrs)
  @name = @attributes[:name] || @attributes[:node]
  @status = @attributes[:status]
  @cpu = @attributes[:cpu]
  @maxcpu = @attributes[:maxcpu]
  @mem = @attributes[:mem]
  @maxmem = @attributes[:maxmem]
  @disk = @attributes[:disk]
  @maxdisk = @attributes[:maxdisk]
  @uptime = @attributes[:uptime]
  @level = @attributes[:level]
  @version = @attributes[:version]
  @kernel = @attributes[:kernel]
  @loadavg = @attributes[:loadavg]
  @swap_used = @attributes[:swap_used]
  @swap_total = @attributes[:swap_total]
  @guests_vms = @attributes[:guests_vms] || 0
  @guests_cts = @attributes[:guests_cts] || 0
  @ip = @attributes[:ip]
  # Extended attributes for describe
  @cpuinfo = @attributes[:cpuinfo]
  @boot_info = @attributes[:boot_info]
  @rootfs = @attributes[:rootfs]
  @subscription = @attributes[:subscription]
  @dns = @attributes[:dns]
  @time_info = @attributes[:time_info]
  @network_interfaces = @attributes[:network_interfaces] || []
  @services = @attributes[:services] || []
  @storage_pools = @attributes[:storage_pools] || []
  @physical_disks = @attributes[:physical_disks] || []
  @qemu_cpu_models = @attributes[:qemu_cpu_models] || []
  @qemu_machines = @attributes[:qemu_machines] || []
  @updates_available = @attributes[:updates_available] || 0
  @updates = @attributes[:updates] || []
  @offline_note = @attributes[:offline_note]
  @firewall = @attributes[:firewall]
  @tasks = @attributes[:tasks] || []
end

Instance Attribute Details

#boot_infoHash? (readonly)

Returns boot info (mode: efi/bios).

Returns:

  • (Hash, nil)

    boot info (mode: efi/bios)



83
84
85
# File 'lib/pvectl/models/node.rb', line 83

def boot_info
  @boot_info
end

#cpuFloat? (readonly)

Returns CPU usage (0-1 scale).

Returns:

  • (Float, nil)

    CPU usage (0-1 scale)



31
32
33
# File 'lib/pvectl/models/node.rb', line 31

def cpu
  @cpu
end

#cpuinfoHash? (readonly)

Extended attributes for describe command

Returns:

  • (Hash, nil)

    CPU info (model, cores, sockets)



80
81
82
# File 'lib/pvectl/models/node.rb', line 80

def cpuinfo
  @cpuinfo
end

#diskInteger? (readonly)

Returns local disk used in bytes.

Returns:

  • (Integer, nil)

    local disk used in bytes



43
44
45
# File 'lib/pvectl/models/node.rb', line 43

def disk
  @disk
end

#dnsHash? (readonly)

Returns DNS configuration (search, dns1, dns2, dns3).

Returns:

  • (Hash, nil)

    DNS configuration (search, dns1, dns2, dns3)



92
93
94
# File 'lib/pvectl/models/node.rb', line 92

def dns
  @dns
end

#firewallHash? (readonly)

Returns firewall configuration data.

Returns:

  • (Hash, nil)

    firewall configuration data



125
126
127
# File 'lib/pvectl/models/node.rb', line 125

def firewall
  @firewall
end

#guests_ctsInteger (readonly)

Returns number of containers on this node.

Returns:

  • (Integer)

    number of containers on this node



73
74
75
# File 'lib/pvectl/models/node.rb', line 73

def guests_cts
  @guests_cts
end

#guests_vmsInteger (readonly)

Returns number of VMs on this node.

Returns:

  • (Integer)

    number of VMs on this node



70
71
72
# File 'lib/pvectl/models/node.rb', line 70

def guests_vms
  @guests_vms
end

#ipString? (readonly)

Returns node IP address (from interface with gateway).

Returns:

  • (String, nil)

    node IP address (from interface with gateway)



76
77
78
# File 'lib/pvectl/models/node.rb', line 76

def ip
  @ip
end

#kernelString? (readonly)

Returns kernel version (e.g., “6.8.12-1-pve”).

Returns:

  • (String, nil)

    kernel version (e.g., “6.8.12-1-pve”)



58
59
60
# File 'lib/pvectl/models/node.rb', line 58

def kernel
  @kernel
end

#levelString? (readonly)

Returns subscription level (c=community, b=basic, etc.).

Returns:

  • (String, nil)

    subscription level (c=community, b=basic, etc.)



52
53
54
# File 'lib/pvectl/models/node.rb', line 52

def level
  @level
end

#loadavgArray<Float>? (readonly)

Returns load averages [1min, 5min, 15min].

Returns:

  • (Array<Float>, nil)

    load averages [1min, 5min, 15min]



61
62
63
# File 'lib/pvectl/models/node.rb', line 61

def loadavg
  @loadavg
end

#maxcpuInteger? (readonly)

Returns total CPU cores.

Returns:

  • (Integer, nil)

    total CPU cores



34
35
36
# File 'lib/pvectl/models/node.rb', line 34

def maxcpu
  @maxcpu
end

#maxdiskInteger? (readonly)

Returns total local disk in bytes.

Returns:

  • (Integer, nil)

    total local disk in bytes



46
47
48
# File 'lib/pvectl/models/node.rb', line 46

def maxdisk
  @maxdisk
end

#maxmemInteger? (readonly)

Returns total memory in bytes.

Returns:

  • (Integer, nil)

    total memory in bytes



40
41
42
# File 'lib/pvectl/models/node.rb', line 40

def maxmem
  @maxmem
end

#memInteger? (readonly)

Returns memory used in bytes.

Returns:

  • (Integer, nil)

    memory used in bytes



37
38
39
# File 'lib/pvectl/models/node.rb', line 37

def mem
  @mem
end

#nameString (readonly)

Returns node name.

Returns:

  • (String)

    node name



25
26
27
# File 'lib/pvectl/models/node.rb', line 25

def name
  @name
end

#network_interfacesArray<Hash> (readonly)

Returns network interfaces.

Returns:

  • (Array<Hash>)

    network interfaces



98
99
100
# File 'lib/pvectl/models/node.rb', line 98

def network_interfaces
  @network_interfaces
end

#offline_noteString? (readonly)

Returns offline note message.

Returns:

  • (String, nil)

    offline note message



122
123
124
# File 'lib/pvectl/models/node.rb', line 122

def offline_note
  @offline_note
end

#physical_disksArray<Hash> (readonly)

Returns physical disks.

Returns:

  • (Array<Hash>)

    physical disks



107
108
109
# File 'lib/pvectl/models/node.rb', line 107

def physical_disks
  @physical_disks
end

#qemu_cpu_modelsArray<Hash> (readonly)

Returns QEMU CPU models.

Returns:

  • (Array<Hash>)

    QEMU CPU models



110
111
112
# File 'lib/pvectl/models/node.rb', line 110

def qemu_cpu_models
  @qemu_cpu_models
end

#qemu_machinesArray<Hash> (readonly)

Returns QEMU machine types.

Returns:

  • (Array<Hash>)

    QEMU machine types



113
114
115
# File 'lib/pvectl/models/node.rb', line 113

def qemu_machines
  @qemu_machines
end

#rootfsHash? (readonly)

Returns root filesystem (used, total, free).

Returns:

  • (Hash, nil)

    root filesystem (used, total, free)



86
87
88
# File 'lib/pvectl/models/node.rb', line 86

def rootfs
  @rootfs
end

#servicesArray<Hash> (readonly)

Returns system services.

Returns:

  • (Array<Hash>)

    system services



101
102
103
# File 'lib/pvectl/models/node.rb', line 101

def services
  @services
end

#statusString (readonly)

Returns node status (online/offline).

Returns:

  • (String)

    node status (online/offline)



28
29
30
# File 'lib/pvectl/models/node.rb', line 28

def status
  @status
end

#storage_poolsArray<Models::Storage> (readonly)

Returns storage pools.

Returns:



104
105
106
# File 'lib/pvectl/models/node.rb', line 104

def storage_pools
  @storage_pools
end

#subscriptionHash? (readonly)

Returns subscription info (status, level, productname).

Returns:

  • (Hash, nil)

    subscription info (status, level, productname)



89
90
91
# File 'lib/pvectl/models/node.rb', line 89

def subscription
  @subscription
end

#swap_totalInteger? (readonly)

Returns total swap in bytes.

Returns:

  • (Integer, nil)

    total swap in bytes



67
68
69
# File 'lib/pvectl/models/node.rb', line 67

def swap_total
  @swap_total
end

#swap_usedInteger? (readonly)

Returns swap used in bytes.

Returns:

  • (Integer, nil)

    swap used in bytes



64
65
66
# File 'lib/pvectl/models/node.rb', line 64

def swap_used
  @swap_used
end

#tasksArray (readonly)

Returns recent task history entries.

Returns:

  • (Array)

    recent task history entries



128
129
130
# File 'lib/pvectl/models/node.rb', line 128

def tasks
  @tasks
end

#time_infoHash? (readonly)

Returns time configuration (timezone, localtime, time).

Returns:

  • (Hash, nil)

    time configuration (timezone, localtime, time)



95
96
97
# File 'lib/pvectl/models/node.rb', line 95

def time_info
  @time_info
end

#updatesArray<Hash> (readonly)

Returns available updates.

Returns:

  • (Array<Hash>)

    available updates



119
120
121
# File 'lib/pvectl/models/node.rb', line 119

def updates
  @updates
end

#updates_availableInteger (readonly)

Returns number of available updates.

Returns:

  • (Integer)

    number of available updates



116
117
118
# File 'lib/pvectl/models/node.rb', line 116

def updates_available
  @updates_available
end

#uptimeInteger? (readonly)

Returns uptime in seconds.

Returns:

  • (Integer, nil)

    uptime in seconds



49
50
51
# File 'lib/pvectl/models/node.rb', line 49

def uptime
  @uptime
end

#versionString? (readonly)

Returns Proxmox version (e.g., “8.3.2”).

Returns:

  • (String, nil)

    Proxmox version (e.g., “8.3.2”)



55
56
57
# File 'lib/pvectl/models/node.rb', line 55

def version
  @version
end

Instance Method Details

#guests_totalInteger

Returns total guest count (VMs + containers).

Returns:

  • (Integer)

    total guests



190
191
192
# File 'lib/pvectl/models/node.rb', line 190

def guests_total
  guests_vms + guests_cts
end

#offline?Boolean

Checks if the node is offline.

Returns:

  • (Boolean)

    true if status is not “online”



183
184
185
# File 'lib/pvectl/models/node.rb', line 183

def offline?
  !online?
end

#online?Boolean

Checks if the node is online.

Returns:

  • (Boolean)

    true if status is “online”



176
177
178
# File 'lib/pvectl/models/node.rb', line 176

def online?
  status == "online"
end