Class: Pvectl::Models::PhysicalDisk

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

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

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ PhysicalDisk

Creates a new PhysicalDisk instance.

Parameters:

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

    disk attributes from API

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)

Returns device path (e.g., “/dev/sda”).

Returns:

  • (String, nil)

    device path (e.g., “/dev/sda”)



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

def devpath
  @devpath
end

#gptInteger? (readonly)

Returns whether disk has a GPT partition table (1 = yes, 0 = no).

Returns:

  • (Integer, nil)

    whether disk has a GPT partition table (1 = yes, 0 = no)



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

def gpt
  @gpt
end

#healthString? (readonly)

Returns SMART health status (e.g., “PASSED”, “FAILED”).

Returns:

  • (String, nil)

    SMART health status (e.g., “PASSED”, “FAILED”)



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

def health
  @health
end

#modelString? (readonly)

Returns disk model name.

Returns:

  • (String, nil)

    disk model name



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

def model
  @model
end

#mountedInteger? (readonly)

Returns whether disk is mounted (1 = yes, 0 = no).

Returns:

  • (Integer, nil)

    whether disk is mounted (1 = yes, 0 = no)



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

def mounted
  @mounted
end

#nodeString? (readonly)

Returns Proxmox node name this disk belongs to.

Returns:

  • (String, nil)

    Proxmox node name this disk belongs to



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

def node
  @node
end

#osdidInteger? (readonly)

Returns Ceph OSD ID (-1 if not an OSD).

Returns:

  • (Integer, nil)

    Ceph OSD ID (-1 if not an OSD)



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

def osdid
  @osdid
end

#parentString? (readonly)

Returns parent device path (e.g., “/dev/sda” for partition “/dev/sda1”).

Returns:

  • (String, nil)

    parent device path (e.g., “/dev/sda” for partition “/dev/sda1”)



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

def parent
  @parent
end

#serialString? (readonly)

Returns disk serial number.

Returns:

  • (String, nil)

    disk serial number



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

def serial
  @serial
end

#sizeInteger? (readonly)

Returns disk size in bytes.

Returns:

  • (Integer, nil)

    disk size in bytes



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

def size
  @size
end

#smart_attributesArray<Hash>? (readonly)

Returns ATA SMART attributes array.

Returns:

  • (Array<Hash>, nil)

    ATA SMART attributes array



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

def smart_attributes
  @smart_attributes
end

#smart_textString? (readonly)

Returns raw SMART text (NVMe/SAS).

Returns:

  • (String, nil)

    raw SMART text (NVMe/SAS)



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

def smart_text
  @smart_text
end

#smart_typeString? (readonly)

Returns SMART type (“ata” or “text”).

Returns:

  • (String, nil)

    SMART type (“ata” or “text”)



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

def smart_type
  @smart_type
end

#typeString? (readonly)

Returns disk type (“ssd”, “hdd”, etc.).

Returns:

  • (String, nil)

    disk type (“ssd”, “hdd”, etc.)



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

def type
  @type
end

#usedString? (readonly)

Returns how the disk is used (e.g., “LVM”, “ZFS”, “ext4”).

Returns:

  • (String, nil)

    how the disk is used (e.g., “LVM”, “ZFS”, “ext4”)



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

def used
  @used
end

#vendorString? (readonly)

Returns disk vendor.

Returns:

  • (String, nil)

    disk vendor



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

def vendor
  @vendor
end

#wearoutInteger? (readonly)

Returns disk wearout percentage.

Returns:

  • (Integer, nil)

    disk wearout percentage



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

def wearout
  @wearout
end

#wwnString? (readonly)

Returns World Wide Name identifier.

Returns:

  • (String, nil)

    World Wide Name identifier



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.

Returns:

  • (Boolean)

    true if gpt is 1



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.

Returns:

  • (Boolean)

    true if health 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.

Parameters:

  • smart_data (Hash{Symbol => untyped})

    SMART response data



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.

Returns:

  • (Boolean)

    true if mounted is 1



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.

Returns:

  • (Boolean)

    true if osdid is non-nil and >= 0



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

Returns:

  • (Float, nil)

    size in GB (binary, 1024-based), or nil if size unknown



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.

Returns:

  • (Boolean)

    true if type is “ssd”



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

def ssd?
  type == "ssd"
end