Class: Pvectl::Commands::Get::Handlers::Disks
- Inherits:
-
Object
- Object
- Pvectl::Commands::Get::Handlers::Disks
- 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.
Instance Attribute Summary collapse
-
#repository ⇒ Repositories::Disk
readonly
Returns repository, creating it if necessary.
Instance Method Summary collapse
-
#build_repository ⇒ Repositories::Disk
Builds repository with connection from config.
-
#describe(name:, node: nil, args: [], vmid: nil) ⇒ Models::PhysicalDisk
Describes a single physical disk with SMART data.
-
#initialize(repository: nil) ⇒ Disks
constructor
Creates handler with optional repository for dependency injection.
-
#list(node: nil, name: nil, args: [], storage: nil, **_options) ⇒ Array<Models::PhysicalDisk>
Lists physical disks with optional filtering.
-
#presenter ⇒ Presenters::Disk
Returns presenter for physical disks.
-
#selector_class ⇒ Class
Returns selector class for client-side filtering.
Constructor Details
#initialize(repository: nil) ⇒ Disks
Creates handler with optional repository for dependency injection.
26 27 28 |
# File 'lib/pvectl/commands/get/handlers/disks.rb', line 26 def initialize(repository: nil) @repository = repository end |
Instance Attribute Details
#repository ⇒ Repositories::Disk (readonly)
Returns repository, creating it if necessary.
83 84 85 |
# File 'lib/pvectl/commands/get/handlers/disks.rb', line 83 def repository @repository ||= build_repository end |
Instance Method Details
#build_repository ⇒ Repositories::Disk
Builds repository with connection from config.
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.
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.
37 38 39 40 41 |
# File 'lib/pvectl/commands/get/handlers/disks.rb', line 37 def list(node: nil, name: nil, args: [], storage: nil, **) disks = repository.list(node: node) disks = disks.select { |d| d.devpath == name } if name disks end |
#presenter ⇒ Presenters::Disk
Returns presenter for physical disks.
67 68 69 |
# File 'lib/pvectl/commands/get/handlers/disks.rb', line 67 def presenter Pvectl::Presenters::Disk.new end |
#selector_class ⇒ Class
Returns selector class for client-side filtering.
74 75 76 |
# File 'lib/pvectl/commands/get/handlers/disks.rb', line 74 def selector_class Pvectl::Selectors::Disk end |