Class: Pvectl::Models::Container
- 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.
Identifier Attributes collapse
-
#name ⇒ String?
readonly
Container name (hostname).
-
#node ⇒ String
readonly
Node name where container runs.
-
#status ⇒ String
readonly
Container status (running, stopped).
-
#vmid ⇒ Integer
readonly
Unique container identifier (CTID: 100-999999999).
Resource Attributes collapse
-
#cpu ⇒ Float?
readonly
Current CPU usage (0.0-1.0 scale).
-
#disk ⇒ Integer?
readonly
Current rootfs disk usage in bytes.
-
#maxcpu ⇒ Integer?
readonly
Allocated CPU cores.
-
#maxdisk ⇒ Integer?
readonly
Rootfs disk limit in bytes.
-
#maxmem ⇒ Integer?
readonly
Memory limit in bytes.
-
#maxswap ⇒ Integer?
readonly
Swap limit in bytes.
-
#mem ⇒ Integer?
readonly
Current memory usage in bytes.
-
#swap ⇒ Integer?
readonly
Current swap usage in bytes.
Metadata Attributes collapse
-
#lock ⇒ String?
readonly
Lock status (backup, migrate, etc.).
-
#pool ⇒ String?
readonly
Resource pool name.
-
#tags ⇒ String?
readonly
Semicolon-separated tags.
-
#template ⇒ Integer?
readonly
Template flag (1 if template, 0 otherwise).
-
#uptime ⇒ Integer?
readonly
Uptime in seconds.
Network I/O Attributes collapse
-
#netin ⇒ Integer?
readonly
Network input bytes.
-
#netout ⇒ Integer?
readonly
Network output bytes.
Describe-Only Attributes collapse
-
#arch ⇒ String?
readonly
Architecture (amd64, arm64).
-
#describe_data ⇒ Hash?
readonly
Raw API responses for describe command.
-
#description ⇒ String?
readonly
Container description.
-
#features ⇒ String?
readonly
Features configuration (nesting, keyctl, etc.).
-
#ha ⇒ Hash?
readonly
HA state information.
-
#hostname ⇒ String?
readonly
Container hostname (FQDN).
-
#network_interfaces ⇒ Array<Hash>
readonly
Network interface configurations.
-
#ostype ⇒ String?
readonly
OS type (debian, ubuntu, alpine, etc.).
-
#pid ⇒ Integer?
readonly
Runtime PID.
-
#rootfs ⇒ String?
readonly
Rootfs configuration string.
-
#type ⇒ String?
readonly
Resource type from API (“lxc”).
-
#unprivileged ⇒ Integer?
readonly
Unprivileged flag (1 if unprivileged, 0 otherwise).
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Container
constructor
Creates a new Container model from attributes.
-
#running? ⇒ Boolean
Checks if the container is running.
-
#stopped? ⇒ Boolean
Checks if the container is stopped.
-
#template? ⇒ Boolean
Checks if the container is a template.
-
#unprivileged? ⇒ Boolean
Checks if the container is unprivileged.
Constructor Details
#initialize(attrs = {}) ⇒ Container
Creates a new Container model from attributes.
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
#arch ⇒ String? (readonly)
Returns architecture (amd64, arm64).
103 104 105 |
# File 'lib/pvectl/models/container.rb', line 103 def arch @arch end |
#cpu ⇒ Float? (readonly)
Returns current CPU usage (0.0-1.0 scale).
43 44 45 |
# File 'lib/pvectl/models/container.rb', line 43 def cpu @cpu end |
#describe_data ⇒ Hash? (readonly)
Returns raw API responses for describe command.
133 134 135 |
# File 'lib/pvectl/models/container.rb', line 133 def describe_data @describe_data end |
#description ⇒ String? (readonly)
Returns container description.
118 119 120 |
# File 'lib/pvectl/models/container.rb', line 118 def description @description end |
#disk ⇒ Integer? (readonly)
Returns current rootfs disk usage in bytes.
61 62 63 |
# File 'lib/pvectl/models/container.rb', line 61 def disk @disk end |
#features ⇒ String? (readonly)
Returns features configuration (nesting, keyctl, etc.).
109 110 111 |
# File 'lib/pvectl/models/container.rb', line 109 def features @features end |
#ha ⇒ Hash? (readonly)
Returns HA state information.
127 128 129 |
# File 'lib/pvectl/models/container.rb', line 127 def ha @ha end |
#hostname ⇒ String? (readonly)
Returns container hostname (FQDN).
121 122 123 |
# File 'lib/pvectl/models/container.rb', line 121 def hostname @hostname end |
#lock ⇒ String? (readonly)
Returns lock status (backup, migrate, etc.).
83 84 85 |
# File 'lib/pvectl/models/container.rb', line 83 def lock @lock end |
#maxcpu ⇒ Integer? (readonly)
Returns allocated CPU cores.
46 47 48 |
# File 'lib/pvectl/models/container.rb', line 46 def maxcpu @maxcpu end |
#maxdisk ⇒ Integer? (readonly)
Returns rootfs disk limit in bytes.
64 65 66 |
# File 'lib/pvectl/models/container.rb', line 64 def maxdisk @maxdisk end |
#maxmem ⇒ Integer? (readonly)
Returns memory limit in bytes.
52 53 54 |
# File 'lib/pvectl/models/container.rb', line 52 def maxmem @maxmem end |
#maxswap ⇒ Integer? (readonly)
Returns swap limit in bytes.
58 59 60 |
# File 'lib/pvectl/models/container.rb', line 58 def maxswap @maxswap end |
#mem ⇒ Integer? (readonly)
Returns current memory usage in bytes.
49 50 51 |
# File 'lib/pvectl/models/container.rb', line 49 def mem @mem end |
#name ⇒ String? (readonly)
Returns container name (hostname).
30 31 32 |
# File 'lib/pvectl/models/container.rb', line 30 def name @name end |
#netin ⇒ Integer? (readonly)
Returns network input bytes.
90 91 92 |
# File 'lib/pvectl/models/container.rb', line 90 def netin @netin end |
#netout ⇒ Integer? (readonly)
Returns network output bytes.
93 94 95 |
# File 'lib/pvectl/models/container.rb', line 93 def netout @netout end |
#network_interfaces ⇒ Array<Hash> (readonly)
Returns network interface configurations.
115 116 117 |
# File 'lib/pvectl/models/container.rb', line 115 def network_interfaces @network_interfaces end |
#node ⇒ String (readonly)
Returns node name where container runs.
33 34 35 |
# File 'lib/pvectl/models/container.rb', line 33 def node @node end |
#ostype ⇒ String? (readonly)
Returns OS type (debian, ubuntu, alpine, etc.).
100 101 102 |
# File 'lib/pvectl/models/container.rb', line 100 def ostype @ostype end |
#pid ⇒ Integer? (readonly)
Returns runtime PID.
124 125 126 |
# File 'lib/pvectl/models/container.rb', line 124 def pid @pid end |
#pool ⇒ String? (readonly)
Returns resource pool name.
80 81 82 |
# File 'lib/pvectl/models/container.rb', line 80 def pool @pool end |
#rootfs ⇒ String? (readonly)
Returns rootfs configuration string.
112 113 114 |
# File 'lib/pvectl/models/container.rb', line 112 def rootfs @rootfs end |
#status ⇒ String (readonly)
Returns container status (running, stopped).
36 37 38 |
# File 'lib/pvectl/models/container.rb', line 36 def status @status end |
#swap ⇒ Integer? (readonly)
Returns current swap usage in bytes.
55 56 57 |
# File 'lib/pvectl/models/container.rb', line 55 def swap @swap end |
#tags ⇒ String? (readonly)
Returns semicolon-separated tags.
77 78 79 |
# File 'lib/pvectl/models/container.rb', line 77 def @tags end |
#template ⇒ Integer? (readonly)
Returns template flag (1 if template, 0 otherwise).
74 75 76 |
# File 'lib/pvectl/models/container.rb', line 74 def template @template end |
#type ⇒ String? (readonly)
Returns resource type from API (“lxc”).
130 131 132 |
# File 'lib/pvectl/models/container.rb', line 130 def type @type end |
#unprivileged ⇒ Integer? (readonly)
Returns unprivileged flag (1 if unprivileged, 0 otherwise).
106 107 108 |
# File 'lib/pvectl/models/container.rb', line 106 def unprivileged @unprivileged end |
#uptime ⇒ Integer? (readonly)
Returns uptime in seconds.
71 72 73 |
# File 'lib/pvectl/models/container.rb', line 71 def uptime @uptime end |
#vmid ⇒ Integer (readonly)
Returns 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.
179 180 181 |
# File 'lib/pvectl/models/container.rb', line 179 def running? status == "running" end |
#stopped? ⇒ Boolean
Checks if the container 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.
193 194 195 |
# File 'lib/pvectl/models/container.rb', line 193 def template? template == 1 end |
#unprivileged? ⇒ Boolean
Checks if the container is unprivileged.
200 201 202 |
# File 'lib/pvectl/models/container.rb', line 200 def unprivileged? unprivileged == 1 end |