Class: Pvectl::Commands::Get::Handlers::Disks

Inherits:
Object
  • Object
show all
Includes:
ResourceHandler
Defined in:
lib/pvectl/commands/get/handlers/disks.rb,
sig/pvectl/commands/get/handlers/disks.rbs

Overview

Handler for listing physical disks on Proxmox nodes.

Implements ResourceHandler interface for the "disks" resource type. Uses Repositories::Disk for data access and Presenters::Disk for formatting.

Examples:

Using via ResourceRegistry

handler = ResourceRegistry.for("disks")
disks = handler.list(node: "pve1")

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository: nil) ⇒ Disks

Creates handler with optional repository for dependency injection.

Parameters:

  • (defaults to: nil)

    repository (default: create new)

  • (defaults to: nil)


26
27
28
# File 'lib/pvectl/commands/get/handlers/disks.rb', line 26

def initialize(repository: nil)
  @repository = repository
end

Instance Attribute Details

#repositoryRepositories::Disk (readonly)

Returns repository, creating it if necessary.

Returns:

  • Disk repository



83
84
85
# File 'lib/pvectl/commands/get/handlers/disks.rb', line 83

def repository
  @repository ||= build_repository
end

Instance Method Details

#build_repositoryRepositories::Disk

Builds repository with connection from config.

Returns:

  • configured Disk repository



90
91
92
93
94
95
# File 'lib/pvectl/commands/get/handlers/disks.rb', line 90

def build_repository
  config_service = Pvectl::Config::Service.new
  config_service.load
  connection = Pvectl::Connection.new(config_service.current_config)
  Pvectl::Repositories::Disk.new(connection)
end

#describe(name:, node: nil, args: [], vmid: nil) ⇒ Models::PhysicalDisk

Describes a single physical disk with SMART data.

Locates the disk by devpath across all nodes (or a specific node), then fetches SMART data and merges it into the model.

Raises:

  • when disk not found

Parameters:

  • device path (e.g., "/dev/nvme0n1")

  • (defaults to: nil)

    optional node filter

  • (defaults to: [])

    unused, for interface compatibility

  • (defaults to: nil)

    unused, for interface compatibility

  • (defaults to: nil)
  • (defaults to: [])
  • (defaults to: nil)

Returns:

  • enriched disk model



54
55
56
57
58
59
60
61
62
# File 'lib/pvectl/commands/get/handlers/disks.rb', line 54

def describe(name:, node: nil, args: [], vmid: nil)
  disks = repository.list(node: node)
  disk = disks.find { |d| d.devpath == name }
  raise Pvectl::ResourceNotFoundError, "Disk not found: #{name}" unless disk

  smart_data = repository.smart(disk.node, name)
  disk.merge_smart(smart_data)
  disk
end

#list(node: nil, name: nil, args: [], storage: nil, **_options) ⇒ Array<Models::PhysicalDisk>

Lists physical disks with optional filtering.

Parameters:

  • (defaults to: nil)

    filter by node name

  • (defaults to: nil)

    filter by device path (e.g., "/dev/sda")

  • (defaults to: [])

    unused, for interface compatibility

  • (defaults to: nil)

    unused, for interface compatibility

  • (defaults to: nil)
  • (defaults to: nil)
  • (defaults to: [])
  • (defaults to: nil)

Returns:

  • collection of PhysicalDisk models



37
38
39
40
41
# File 'lib/pvectl/commands/get/handlers/disks.rb', line 37

def list(node: nil, name: nil, args: [], storage: nil, **_options)
  disks = repository.list(node: node)
  disks = disks.select { |d| d.devpath == name } if name
  disks
end

#presenterPresenters::Disk

Returns presenter for physical disks.

Returns:

  • Disk presenter instance



67
68
69
# File 'lib/pvectl/commands/get/handlers/disks.rb', line 67

def presenter
  Pvectl::Presenters::Disk.new
end

#selector_classClass

Returns selector class for client-side filtering.

Returns:

  • Selectors::Disk class



74
75
76
# File 'lib/pvectl/commands/get/handlers/disks.rb', line 74

def selector_class
  Pvectl::Selectors::Disk
end