Class: Pvectl::Models::Vm
Overview
Represents a QEMU virtual machine in the Proxmox cluster.
Immutable domain model containing VM attributes and status predicates. Created by Repositories::Vm from API data. Display/formatting methods are in Presenters::Vm.
Instance Attribute Summary collapse
-
#cpu ⇒ Float?
readonly
Current CPU usage (0-1 scale).
-
#describe_data ⇒ Hash?
readonly
Raw API responses for describe command.
-
#disk ⇒ Integer?
readonly
Current disk usage in bytes.
-
#hastate ⇒ String?
readonly
HA state.
-
#maxcpu ⇒ Integer?
readonly
Maximum CPU cores.
-
#maxdisk ⇒ Integer?
readonly
Maximum disk size in bytes.
-
#maxmem ⇒ Integer?
readonly
Maximum memory in bytes.
-
#mem ⇒ Integer?
readonly
Current memory usage in bytes.
-
#name ⇒ String?
readonly
VM name.
-
#netin ⇒ Integer?
readonly
Network input bytes.
-
#netout ⇒ Integer?
readonly
Network output bytes.
-
#node ⇒ String
readonly
Node name where VM runs.
-
#pool ⇒ String?
readonly
Resource pool name.
-
#status ⇒ String
readonly
VM status (running, stopped, paused).
-
#tags ⇒ String?
readonly
Semicolon-separated tags.
-
#template ⇒ Integer?
readonly
Template flag (1 if template, 0 otherwise).
-
#type ⇒ String?
readonly
Resource type from API (“qemu”).
-
#uptime ⇒ Integer?
readonly
Uptime in seconds.
-
#vmid ⇒ Integer
readonly
Unique VM identifier.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Vm
constructor
Creates a new VM model from attributes.
-
#paused? ⇒ Boolean
Checks if the VM is paused.
-
#running? ⇒ Boolean
Checks if the VM is running.
-
#stopped? ⇒ Boolean
Checks if the VM is stopped.
-
#template? ⇒ Boolean
Checks if the VM is a template.
Constructor Details
#initialize(attrs = {}) ⇒ Vm
Creates a new VM model from attributes.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/pvectl/models/vm.rb', line 84 def initialize(attrs = {}) super(attrs) # Use @attributes which has normalized symbol keys from Base @vmid = @attributes[:vmid] @name = @attributes[:name] @status = @attributes[:status] @node = @attributes[:node] @cpu = @attributes[:cpu] @maxcpu = @attributes[:maxcpu] @mem = @attributes[:mem] @maxmem = @attributes[:maxmem] @disk = @attributes[:disk] @maxdisk = @attributes[:maxdisk] @uptime = @attributes[:uptime] @template = @attributes[:template] @tags = @attributes[:tags] @hastate = @attributes[:hastate] @netin = @attributes[:netin] @netout = @attributes[:netout] @describe_data = @attributes[:describe_data] @pool = @attributes[:pool] @type = @attributes[:type] end |
Instance Attribute Details
#cpu ⇒ Float? (readonly)
Returns current CPU usage (0-1 scale).
37 38 39 |
# File 'lib/pvectl/models/vm.rb', line 37 def cpu @cpu end |
#describe_data ⇒ Hash? (readonly)
Returns raw API responses for describe command.
73 74 75 |
# File 'lib/pvectl/models/vm.rb', line 73 def describe_data @describe_data end |
#disk ⇒ Integer? (readonly)
Returns current disk usage in bytes.
49 50 51 |
# File 'lib/pvectl/models/vm.rb', line 49 def disk @disk end |
#hastate ⇒ String? (readonly)
Returns HA state.
64 65 66 |
# File 'lib/pvectl/models/vm.rb', line 64 def hastate @hastate end |
#maxcpu ⇒ Integer? (readonly)
Returns maximum CPU cores.
40 41 42 |
# File 'lib/pvectl/models/vm.rb', line 40 def maxcpu @maxcpu end |
#maxdisk ⇒ Integer? (readonly)
Returns maximum disk size in bytes.
52 53 54 |
# File 'lib/pvectl/models/vm.rb', line 52 def maxdisk @maxdisk end |
#maxmem ⇒ Integer? (readonly)
Returns maximum memory in bytes.
46 47 48 |
# File 'lib/pvectl/models/vm.rb', line 46 def maxmem @maxmem end |
#mem ⇒ Integer? (readonly)
Returns current memory usage in bytes.
43 44 45 |
# File 'lib/pvectl/models/vm.rb', line 43 def mem @mem end |
#name ⇒ String? (readonly)
Returns VM name.
28 29 30 |
# File 'lib/pvectl/models/vm.rb', line 28 def name @name end |
#netin ⇒ Integer? (readonly)
Returns network input bytes.
67 68 69 |
# File 'lib/pvectl/models/vm.rb', line 67 def netin @netin end |
#netout ⇒ Integer? (readonly)
Returns network output bytes.
70 71 72 |
# File 'lib/pvectl/models/vm.rb', line 70 def netout @netout end |
#node ⇒ String (readonly)
Returns node name where VM runs.
34 35 36 |
# File 'lib/pvectl/models/vm.rb', line 34 def node @node end |
#pool ⇒ String? (readonly)
Returns resource pool name.
76 77 78 |
# File 'lib/pvectl/models/vm.rb', line 76 def pool @pool end |
#status ⇒ String (readonly)
Returns VM status (running, stopped, paused).
31 32 33 |
# File 'lib/pvectl/models/vm.rb', line 31 def status @status end |
#tags ⇒ String? (readonly)
Returns semicolon-separated tags.
61 62 63 |
# File 'lib/pvectl/models/vm.rb', line 61 def @tags end |
#template ⇒ Integer? (readonly)
Returns template flag (1 if template, 0 otherwise).
58 59 60 |
# File 'lib/pvectl/models/vm.rb', line 58 def template @template end |
#type ⇒ String? (readonly)
Returns resource type from API (“qemu”).
79 80 81 |
# File 'lib/pvectl/models/vm.rb', line 79 def type @type end |
#uptime ⇒ Integer? (readonly)
Returns uptime in seconds.
55 56 57 |
# File 'lib/pvectl/models/vm.rb', line 55 def uptime @uptime end |
#vmid ⇒ Integer (readonly)
Returns unique VM identifier.
25 26 27 |
# File 'lib/pvectl/models/vm.rb', line 25 def vmid @vmid end |
Instance Method Details
#paused? ⇒ Boolean
Checks if the VM is paused.
125 126 127 |
# File 'lib/pvectl/models/vm.rb', line 125 def paused? status == "paused" end |
#running? ⇒ Boolean
Checks if the VM is running.
111 112 113 |
# File 'lib/pvectl/models/vm.rb', line 111 def running? status == "running" end |
#stopped? ⇒ Boolean
Checks if the VM is stopped.
118 119 120 |
# File 'lib/pvectl/models/vm.rb', line 118 def stopped? status == "stopped" end |
#template? ⇒ Boolean
Checks if the VM is a template.
132 133 134 |
# File 'lib/pvectl/models/vm.rb', line 132 def template? template == 1 end |