Class: Pvectl::Models::Storage
- Defined in:
- lib/pvectl/models/storage.rb
Overview
Represents a storage pool in the Proxmox cluster.
Immutable domain model containing storage attributes and predicate methods. Created by Repositories::Storage from API data. Display formatting is handled by Presenters::Storage.
Instance Attribute Summary collapse
-
#active_flag ⇒ Integer?
readonly
Active flag (0/1) (from /nodes/#node/storage).
-
#avail ⇒ Integer?
readonly
Available bytes (from /nodes/#node/storage).
-
#content ⇒ String?
readonly
Comma-separated content types (images, iso, vztmpl, backup, rootdir).
-
#disk ⇒ Integer?
readonly
Disk used in bytes.
-
#enabled ⇒ Integer?
readonly
Enabled flag (0/1) (from /nodes/#node/storage).
-
#export ⇒ String?
readonly
Export path (nfs).
-
#max_files ⇒ Integer?
readonly
Max backups (deprecated).
-
#maxdisk ⇒ Integer?
readonly
Total disk in bytes.
-
#name ⇒ String
readonly
Storage pool name.
-
#node ⇒ String?
readonly
Node name (nil for shared storage).
-
#nodes_allowed ⇒ String?
readonly
Allowed nodes (nil = all).
-
#path ⇒ String?
readonly
Configuration fields (from /storage/storage API endpoint).
-
#plugintype ⇒ String
readonly
Storage plugin type (dir, lvmthin, rbd, nfs, zfspool, etc.).
-
#pool ⇒ String?
readonly
Pool name (zfs, ceph).
-
#prune_backups ⇒ Hash?
readonly
Retention policy hash.
-
#server ⇒ String?
readonly
Server for nfs, iscsi, ceph.
-
#shared ⇒ Integer
readonly
Shared flag (1 = shared, 0 = local).
-
#status ⇒ String
readonly
Storage status (available, unavailable).
-
#thinpool ⇒ String?
readonly
Thin pool name (lvmthin).
-
#vgname ⇒ String?
readonly
Volume group (lvm).
-
#volumes ⇒ Array<Hash>
readonly
Content summary.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Checks if the storage is active/available.
-
#enabled? ⇒ Boolean
Checks if the storage is enabled.
-
#initialize(attrs = {}) ⇒ Storage
constructor
Creates a new Storage model from attributes.
-
#shared? ⇒ Boolean
Checks if the storage is shared across nodes.
-
#total ⇒ Integer?
Returns total bytes (alias for maxdisk).
-
#used ⇒ Integer?
Returns used bytes (alias for disk).
Constructor Details
#initialize(attrs = {}) ⇒ Storage
Creates a new Storage model from attributes.
Handles field aliasing between different API endpoints:
-
/cluster/resources uses: disk, maxdisk
-
/nodes/#node/storage uses: used, total, avail
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/pvectl/models/storage.rb', line 96 def initialize(attrs = {}) super(attrs) @name = @attributes[:name] || @attributes[:storage] @plugintype = @attributes[:plugintype] || @attributes[:type] @node = @attributes[:node] @content = @attributes[:content] @shared = @attributes[:shared] || 0 # Handle field aliasing between endpoints # /cluster/resources uses: disk, maxdisk # /nodes/{node}/storage uses: used, total, avail @disk = @attributes[:disk] || @attributes[:used] @maxdisk = @attributes[:maxdisk] || @attributes[:total] @avail = @attributes[:avail] @enabled = @attributes[:enabled] @active_flag = @attributes[:active] # Status normalization: /nodes/{node}/storage has no status field # Derive from active flag if status not present @status = @attributes[:status] || derive_status_from_active # Configuration fields from /storage/{storage} API endpoint @path = @attributes[:path] @server = @attributes[:server] @export = @attributes[:export] @pool = @attributes[:pool] @vgname = @attributes[:vgname] @thinpool = @attributes[:thinpool] @nodes_allowed = @attributes[:nodes] # API returns "nodes" not "nodes_allowed" @prune_backups = @attributes[:"prune-backups"] # API uses hyphen @max_files = @attributes[:maxfiles] @volumes = @attributes[:volumes] || [] end |
Instance Attribute Details
#active_flag ⇒ Integer? (readonly)
Returns active flag (0/1) (from /nodes/#node/storage).
55 56 57 |
# File 'lib/pvectl/models/storage.rb', line 55 def active_flag @active_flag end |
#avail ⇒ Integer? (readonly)
Returns available bytes (from /nodes/#node/storage).
49 50 51 |
# File 'lib/pvectl/models/storage.rb', line 49 def avail @avail end |
#content ⇒ String? (readonly)
Returns comma-separated content types (images, iso, vztmpl, backup, rootdir).
43 44 45 |
# File 'lib/pvectl/models/storage.rb', line 43 def content @content end |
#disk ⇒ Integer? (readonly)
Returns disk used in bytes.
37 38 39 |
# File 'lib/pvectl/models/storage.rb', line 37 def disk @disk end |
#enabled ⇒ Integer? (readonly)
Returns enabled flag (0/1) (from /nodes/#node/storage).
52 53 54 |
# File 'lib/pvectl/models/storage.rb', line 52 def enabled @enabled end |
#export ⇒ String? (readonly)
Returns export path (nfs).
65 66 67 |
# File 'lib/pvectl/models/storage.rb', line 65 def export @export end |
#max_files ⇒ Integer? (readonly)
Returns max backups (deprecated).
83 84 85 |
# File 'lib/pvectl/models/storage.rb', line 83 def max_files @max_files end |
#maxdisk ⇒ Integer? (readonly)
Returns total disk in bytes.
40 41 42 |
# File 'lib/pvectl/models/storage.rb', line 40 def maxdisk @maxdisk end |
#name ⇒ String (readonly)
Returns storage pool name.
25 26 27 |
# File 'lib/pvectl/models/storage.rb', line 25 def name @name end |
#node ⇒ String? (readonly)
Returns node name (nil for shared storage).
34 35 36 |
# File 'lib/pvectl/models/storage.rb', line 34 def node @node end |
#nodes_allowed ⇒ String? (readonly)
Returns allowed nodes (nil = all).
77 78 79 |
# File 'lib/pvectl/models/storage.rb', line 77 def nodes_allowed @nodes_allowed end |
#path ⇒ String? (readonly)
Configuration fields (from /storage/storage API endpoint)
59 60 61 |
# File 'lib/pvectl/models/storage.rb', line 59 def path @path end |
#plugintype ⇒ String (readonly)
Returns storage plugin type (dir, lvmthin, rbd, nfs, zfspool, etc.).
28 29 30 |
# File 'lib/pvectl/models/storage.rb', line 28 def plugintype @plugintype end |
#pool ⇒ String? (readonly)
Returns pool name (zfs, ceph).
68 69 70 |
# File 'lib/pvectl/models/storage.rb', line 68 def pool @pool end |
#prune_backups ⇒ Hash? (readonly)
Returns retention policy hash.
80 81 82 |
# File 'lib/pvectl/models/storage.rb', line 80 def prune_backups @prune_backups end |
#server ⇒ String? (readonly)
Returns server for nfs, iscsi, ceph.
62 63 64 |
# File 'lib/pvectl/models/storage.rb', line 62 def server @server end |
#shared ⇒ Integer (readonly)
Returns shared flag (1 = shared, 0 = local).
46 47 48 |
# File 'lib/pvectl/models/storage.rb', line 46 def shared @shared end |
#status ⇒ String (readonly)
Returns storage status (available, unavailable).
31 32 33 |
# File 'lib/pvectl/models/storage.rb', line 31 def status @status end |
#thinpool ⇒ String? (readonly)
Returns thin pool name (lvmthin).
74 75 76 |
# File 'lib/pvectl/models/storage.rb', line 74 def thinpool @thinpool end |
#vgname ⇒ String? (readonly)
Returns volume group (lvm).
71 72 73 |
# File 'lib/pvectl/models/storage.rb', line 71 def vgname @vgname end |
#volumes ⇒ Array<Hash> (readonly)
Content summary
87 88 89 |
# File 'lib/pvectl/models/storage.rb', line 87 def volumes @volumes end |
Instance Method Details
#active? ⇒ Boolean
Checks if the storage is active/available.
133 134 135 |
# File 'lib/pvectl/models/storage.rb', line 133 def active? status == "available" || status == "active" end |
#enabled? ⇒ Boolean
Checks if the storage is enabled.
156 157 158 |
# File 'lib/pvectl/models/storage.rb', line 156 def enabled? enabled == 1 end |
#shared? ⇒ Boolean
Checks if the storage is shared across nodes.
163 164 165 |
# File 'lib/pvectl/models/storage.rb', line 163 def shared? shared == 1 end |
#total ⇒ Integer?
Returns total bytes (alias for maxdisk). Provides semantic clarity when working with /nodes/#node/storage API.
149 150 151 |
# File 'lib/pvectl/models/storage.rb', line 149 def total maxdisk end |
#used ⇒ Integer?
Returns used bytes (alias for disk). Provides semantic clarity when working with /nodes/#node/storage API.
141 142 143 |
# File 'lib/pvectl/models/storage.rb', line 141 def used disk end |