Class: Pvectl::Models::Vm

Inherits:
Base
  • Object
show all
Defined in:
lib/pvectl/models/vm.rb,
sig/pvectl/models/vm.rbs

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.

Examples:

Creating a VM model

vm = Vm.new(vmid: 100, name: "web", status: "running", node: "pve1")
vm.running? #=> true
vm.template? #=> false

From API response

data = { "vmid" => 100, "name" => "web", "status" => "running" }
vm = Vm.new(data)

See Also:

Instance Attribute Summary collapse

Attributes inherited from Base

#attributes

Instance Method Summary collapse

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

#cpuFloat? (readonly)



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

def cpu
  @cpu
end

#describe_dataHash? (readonly)



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

def describe_data
  @describe_data
end

#diskInteger? (readonly)



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

def disk
  @disk
end

#hastateString? (readonly)



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

def hastate
  @hastate
end

#maxcpuInteger? (readonly)



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

def maxcpu
  @maxcpu
end

#maxdiskInteger? (readonly)



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

def maxdisk
  @maxdisk
end

#maxmemInteger? (readonly)



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

def maxmem
  @maxmem
end

#memInteger? (readonly)



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

def mem
  @mem
end

#nameString? (readonly)



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

def name
  @name
end

#netinInteger? (readonly)



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

def netin
  @netin
end

#netoutInteger? (readonly)



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

def netout
  @netout
end

#nodeString (readonly)



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

def node
  @node
end

#poolString? (readonly)



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

def pool
  @pool
end

#statusString (readonly)



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

def status
  @status
end

#tagsString? (readonly)



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

def tags
  @tags
end

#templateInteger? (readonly)



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

def template
  @template
end

#typeString? (readonly)



79
80
81
# File 'lib/pvectl/models/vm.rb', line 79

def type
  @type
end

#uptimeInteger? (readonly)



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

def uptime
  @uptime
end

#vmidInteger (readonly)



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