Class: Pvectl::Models::Container

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

Overview

Represents an LXC container in the Proxmox cluster.

Immutable domain model containing container attributes and status predicates. Created by Repositories::Container from API data. Display/formatting methods are in Presenters::Container.

Examples:

Creating a Container model

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

From API response

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

See Also:

Identifier Attributes collapse

Resource Attributes collapse

Metadata Attributes collapse

Network I/O Attributes collapse

Describe-Only Attributes collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Container

Creates a new Container model from attributes.

Parameters:

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

    Container attributes from API (string or symbol keys)



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
172
173
174
# File 'lib/pvectl/models/container.rb', line 140

def initialize(attrs = {})
  super(attrs)
  # Use @attributes which has normalized symbol keys from Base
  @vmid = @attributes[:vmid]
  @name = @attributes[:name]
  @node = @attributes[:node]
  @status = @attributes[:status]
  @cpu = @attributes[:cpu]
  @maxcpu = @attributes[:maxcpu]
  @mem = @attributes[:mem]
  @maxmem = @attributes[:maxmem]
  @swap = @attributes[:swap]
  @maxswap = @attributes[:maxswap]
  @disk = @attributes[:disk]
  @maxdisk = @attributes[:maxdisk]
  @uptime = @attributes[:uptime]
  @template = @attributes[:template]
  @tags = @attributes[:tags]
  @pool = @attributes[:pool]
  @lock = @attributes[:lock]
  @netin = @attributes[:netin]
  @netout = @attributes[:netout]
  @ostype = @attributes[:ostype]
  @arch = @attributes[:arch]
  @unprivileged = @attributes[:unprivileged]
  @features = @attributes[:features]
  @rootfs = @attributes[:rootfs]
  @network_interfaces = @attributes[:network_interfaces] || []
  @description = @attributes[:description]
  @hostname = @attributes[:hostname]
  @pid = @attributes[:pid]
  @ha = @attributes[:ha]
  @type = @attributes[:type]
  @describe_data = @attributes[:describe_data]
end

Instance Attribute Details

#archString? (readonly)

Returns architecture (amd64, arm64).

Returns:

  • (String, nil)

    architecture (amd64, arm64)



103
104
105
# File 'lib/pvectl/models/container.rb', line 103

def arch
  @arch
end

#cpuFloat? (readonly)

Returns current CPU usage (0.0-1.0 scale).

Returns:

  • (Float, nil)

    current CPU usage (0.0-1.0 scale)



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

def cpu
  @cpu
end

#describe_dataHash? (readonly)

Returns raw API responses for describe command.

Returns:

  • (Hash, nil)

    raw API responses for describe command



133
134
135
# File 'lib/pvectl/models/container.rb', line 133

def describe_data
  @describe_data
end

#descriptionString? (readonly)

Returns container description.

Returns:

  • (String, nil)

    container description



118
119
120
# File 'lib/pvectl/models/container.rb', line 118

def description
  @description
end

#diskInteger? (readonly)

Returns current rootfs disk usage in bytes.

Returns:

  • (Integer, nil)

    current rootfs disk usage in bytes



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

def disk
  @disk
end

#featuresString? (readonly)

Returns features configuration (nesting, keyctl, etc.).

Returns:

  • (String, nil)

    features configuration (nesting, keyctl, etc.)



109
110
111
# File 'lib/pvectl/models/container.rb', line 109

def features
  @features
end

#haHash? (readonly)

Returns HA state information.

Returns:

  • (Hash, nil)

    HA state information



127
128
129
# File 'lib/pvectl/models/container.rb', line 127

def ha
  @ha
end

#hostnameString? (readonly)

Returns container hostname (FQDN).

Returns:

  • (String, nil)

    container hostname (FQDN)



121
122
123
# File 'lib/pvectl/models/container.rb', line 121

def hostname
  @hostname
end

#lockString? (readonly)

Returns lock status (backup, migrate, etc.).

Returns:

  • (String, nil)

    lock status (backup, migrate, etc.)



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

def lock
  @lock
end

#maxcpuInteger? (readonly)

Returns allocated CPU cores.

Returns:

  • (Integer, nil)

    allocated CPU cores



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

def maxcpu
  @maxcpu
end

#maxdiskInteger? (readonly)

Returns rootfs disk limit in bytes.

Returns:

  • (Integer, nil)

    rootfs disk limit in bytes



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

def maxdisk
  @maxdisk
end

#maxmemInteger? (readonly)

Returns memory limit in bytes.

Returns:

  • (Integer, nil)

    memory limit in bytes



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

def maxmem
  @maxmem
end

#maxswapInteger? (readonly)

Returns swap limit in bytes.

Returns:

  • (Integer, nil)

    swap limit in bytes



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

def maxswap
  @maxswap
end

#memInteger? (readonly)

Returns current memory usage in bytes.

Returns:

  • (Integer, nil)

    current memory usage in bytes



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

def mem
  @mem
end

#nameString? (readonly)

Returns container name (hostname).

Returns:

  • (String, nil)

    container name (hostname)



30
31
32
# File 'lib/pvectl/models/container.rb', line 30

def name
  @name
end

#netinInteger? (readonly)

Returns network input bytes.

Returns:

  • (Integer, nil)

    network input bytes



90
91
92
# File 'lib/pvectl/models/container.rb', line 90

def netin
  @netin
end

#netoutInteger? (readonly)

Returns network output bytes.

Returns:

  • (Integer, nil)

    network output bytes



93
94
95
# File 'lib/pvectl/models/container.rb', line 93

def netout
  @netout
end

#network_interfacesArray<Hash> (readonly)

Returns network interface configurations.

Returns:

  • (Array<Hash>)

    network interface configurations



115
116
117
# File 'lib/pvectl/models/container.rb', line 115

def network_interfaces
  @network_interfaces
end

#nodeString (readonly)

Returns node name where container runs.

Returns:

  • (String)

    node name where container runs



33
34
35
# File 'lib/pvectl/models/container.rb', line 33

def node
  @node
end

#ostypeString? (readonly)

Returns OS type (debian, ubuntu, alpine, etc.).

Returns:

  • (String, nil)

    OS type (debian, ubuntu, alpine, etc.)



100
101
102
# File 'lib/pvectl/models/container.rb', line 100

def ostype
  @ostype
end

#pidInteger? (readonly)

Returns runtime PID.

Returns:

  • (Integer, nil)

    runtime PID



124
125
126
# File 'lib/pvectl/models/container.rb', line 124

def pid
  @pid
end

#poolString? (readonly)

Returns resource pool name.

Returns:

  • (String, nil)

    resource pool name



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

def pool
  @pool
end

#rootfsString? (readonly)

Returns rootfs configuration string.

Returns:

  • (String, nil)

    rootfs configuration string



112
113
114
# File 'lib/pvectl/models/container.rb', line 112

def rootfs
  @rootfs
end

#statusString (readonly)

Returns container status (running, stopped).

Returns:

  • (String)

    container status (running, stopped)



36
37
38
# File 'lib/pvectl/models/container.rb', line 36

def status
  @status
end

#swapInteger? (readonly)

Returns current swap usage in bytes.

Returns:

  • (Integer, nil)

    current swap usage in bytes



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

def swap
  @swap
end

#tagsString? (readonly)

Returns semicolon-separated tags.

Returns:

  • (String, nil)

    semicolon-separated tags



77
78
79
# File 'lib/pvectl/models/container.rb', line 77

def tags
  @tags
end

#templateInteger? (readonly)

Returns template flag (1 if template, 0 otherwise).

Returns:

  • (Integer, nil)

    template flag (1 if template, 0 otherwise)



74
75
76
# File 'lib/pvectl/models/container.rb', line 74

def template
  @template
end

#typeString? (readonly)

Returns resource type from API (“lxc”).

Returns:

  • (String, nil)

    resource type from API (“lxc”)



130
131
132
# File 'lib/pvectl/models/container.rb', line 130

def type
  @type
end

#unprivilegedInteger? (readonly)

Returns unprivileged flag (1 if unprivileged, 0 otherwise).

Returns:

  • (Integer, nil)

    unprivileged flag (1 if unprivileged, 0 otherwise)



106
107
108
# File 'lib/pvectl/models/container.rb', line 106

def unprivileged
  @unprivileged
end

#uptimeInteger? (readonly)

Returns uptime in seconds.

Returns:

  • (Integer, nil)

    uptime in seconds



71
72
73
# File 'lib/pvectl/models/container.rb', line 71

def uptime
  @uptime
end

#vmidInteger (readonly)

Returns unique container identifier (CTID: 100-999999999).

Returns:

  • (Integer)

    unique container identifier (CTID: 100-999999999)



27
28
29
# File 'lib/pvectl/models/container.rb', line 27

def vmid
  @vmid
end

Instance Method Details

#running?Boolean

Checks if the container is running.

Returns:

  • (Boolean)

    true if status is “running”



179
180
181
# File 'lib/pvectl/models/container.rb', line 179

def running?
  status == "running"
end

#stopped?Boolean

Checks if the container is stopped.

Returns:

  • (Boolean)

    true if status is “stopped”



186
187
188
# File 'lib/pvectl/models/container.rb', line 186

def stopped?
  status == "stopped"
end

#template?Boolean

Checks if the container is a template.

Returns:

  • (Boolean)

    true if template flag is 1



193
194
195
# File 'lib/pvectl/models/container.rb', line 193

def template?
  template == 1
end

#unprivileged?Boolean

Checks if the container is unprivileged.

Returns:

  • (Boolean)

    true if unprivileged flag is 1



200
201
202
# File 'lib/pvectl/models/container.rb', line 200

def unprivileged?
  unprivileged == 1
end