Class: Pvectl::Models::PhysicalDisk

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

Overview

Represents a physical disk (block device) on a Proxmox node.

PhysicalDisk instances are created from the Proxmox API responses and provide domain methods for disk analysis.

Examples:

Creating a disk from API data

disk = PhysicalDisk.new(
  devpath: "/dev/sda",
  model: "Samsung SSD 970",
  size: 500_000_000_000,
  type: "ssd",
  health: "PASSED",
  node: "pve1",
  gpt: 1,
  mounted: 1,
  used: "LVM"
)
disk.ssd?      # => true
disk.healthy?  # => true
disk.size_gb   # => 465.7
disk.gpt?      # => true
disk.mounted?  # => true
disk.osd?      # => false

See Also:

Instance Attribute Summary collapse

Attributes inherited from Base

#attributes

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ PhysicalDisk

Creates a new PhysicalDisk instance.

Options Hash (attrs):

  • :devpath (String)

    device path

  • :model (String)

    disk model name

  • :size (Integer)

    disk size in bytes

  • :type (String)

    disk type

  • :health (String)

    SMART health status

  • :serial (String)

    serial number

  • :vendor (String)

    vendor name

  • :node (String)

    Proxmox node name

  • :gpt (Integer)

    GPT partition table flag (1/0)

  • :mounted (Integer)

    mounted flag (1/0)

  • :used (String)

    usage type

  • :wwn (String)

    World Wide Name

  • :osdid (Integer)

    Ceph OSD ID

  • :parent (String)

    parent device path

  • :smart_type (String)

    SMART data type ("ata" or "text")

  • :smart_attributes (Array<Hash>)

    ATA SMART attributes

  • :smart_text (String)

    raw SMART text (NVMe/SAS)

  • :wearout (Integer)

    wearout percentage



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/pvectl/models/physical_disk.rb', line 107

def initialize(attrs = {})
  super
  @devpath = attributes[:devpath]
  @model = attributes[:model]
  @size = attributes[:size]
  @type = attributes[:type]
  @health = attributes[:health]
  @serial = attributes[:serial]
  @vendor = attributes[:vendor]
  @node = attributes[:node]
  @gpt = attributes[:gpt]
  @mounted = attributes[:mounted]
  @used = attributes[:used]
  @wwn = attributes[:wwn]
  @osdid = attributes[:osdid]
  @parent = attributes[:parent]
  @smart_type = attributes[:smart_type]
  @smart_attributes = attributes[:smart_attributes]
  @smart_text = attributes[:smart_text]
  @wearout = attributes[:wearout]
end

Instance Attribute Details

#devpathString? (readonly)



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

def devpath
  @devpath
end

#gptInteger? (readonly)



57
58
59
# File 'lib/pvectl/models/physical_disk.rb', line 57

def gpt
  @gpt
end

#healthString? (readonly)



45
46
47
# File 'lib/pvectl/models/physical_disk.rb', line 45

def health
  @health
end

#modelString? (readonly)



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

def model
  @model
end

#mountedInteger? (readonly)



60
61
62
# File 'lib/pvectl/models/physical_disk.rb', line 60

def mounted
  @mounted
end

#nodeString? (readonly)



54
55
56
# File 'lib/pvectl/models/physical_disk.rb', line 54

def node
  @node
end

#osdidInteger? (readonly)



69
70
71
# File 'lib/pvectl/models/physical_disk.rb', line 69

def osdid
  @osdid
end

#parentString? (readonly)



72
73
74
# File 'lib/pvectl/models/physical_disk.rb', line 72

def parent
  @parent
end

#serialString? (readonly)



48
49
50
# File 'lib/pvectl/models/physical_disk.rb', line 48

def serial
  @serial
end

#sizeInteger? (readonly)



39
40
41
# File 'lib/pvectl/models/physical_disk.rb', line 39

def size
  @size
end

#smart_attributesArray<Hash>? (readonly)



78
79
80
# File 'lib/pvectl/models/physical_disk.rb', line 78

def smart_attributes
  @smart_attributes
end

#smart_textString? (readonly)



81
82
83
# File 'lib/pvectl/models/physical_disk.rb', line 81

def smart_text
  @smart_text
end

#smart_typeString? (readonly)



75
76
77
# File 'lib/pvectl/models/physical_disk.rb', line 75

def smart_type
  @smart_type
end

#typeString? (readonly)



42
43
44
# File 'lib/pvectl/models/physical_disk.rb', line 42

def type
  @type
end

#usedString? (readonly)



63
64
65
# File 'lib/pvectl/models/physical_disk.rb', line 63

def used
  @used
end

#vendorString? (readonly)



51
52
53
# File 'lib/pvectl/models/physical_disk.rb', line 51

def vendor
  @vendor
end

#wearoutInteger? (readonly)



84
85
86
# File 'lib/pvectl/models/physical_disk.rb', line 84

def wearout
  @wearout
end

#wwnString? (readonly)



66
67
68
# File 'lib/pvectl/models/physical_disk.rb', line 66

def wwn
  @wwn
end

Instance Method Details

#gpt?Boolean

Checks if disk has a GPT partition table.



159
160
161
# File 'lib/pvectl/models/physical_disk.rb', line 159

def gpt?
  gpt == 1
end

#healthy?Boolean

Checks if disk SMART health status is PASSED.



145
146
147
# File 'lib/pvectl/models/physical_disk.rb', line 145

def healthy?
  health == "PASSED"
end

#merge_smart(smart_data) ⇒ void

This method returns an undefined value.

Merges SMART data into the model.

Called after initial construction when SMART data is fetched separately from the disk list endpoint.



184
185
186
187
188
189
190
# File 'lib/pvectl/models/physical_disk.rb', line 184

def merge_smart(smart_data)
  @smart_type = smart_data[:type]
  @smart_attributes = smart_data[:attributes]
  @smart_text = smart_data[:text]
  @wearout = smart_data[:wearout]
  @health = smart_data[:health] if smart_data[:health]
end

#mounted?Boolean

Checks if disk is currently mounted.



166
167
168
# File 'lib/pvectl/models/physical_disk.rb', line 166

def mounted?
  mounted == 1
end

#osd?Boolean

Checks if disk is a Ceph OSD.



173
174
175
# File 'lib/pvectl/models/physical_disk.rb', line 173

def osd?
  !osdid.nil? && osdid >= 0
end

#size_gbFloat?

Returns disk size in gigabytes.

Examples:

disk = PhysicalDisk.new(size: 500_000_000_000)
disk.size_gb # => 465.7


136
137
138
139
140
# File 'lib/pvectl/models/physical_disk.rb', line 136

def size_gb
  return nil if size.nil?

  (size.to_f / 1024 / 1024 / 1024).round(1)
end

#ssd?Boolean

Checks if disk is an SSD.



152
153
154
# File 'lib/pvectl/models/physical_disk.rb', line 152

def ssd?
  type == "ssd"
end