Class: Pvectl::Commands::Get::Handlers::Storage
- Inherits:
-
Object
- Object
- Pvectl::Commands::Get::Handlers::Storage
- Includes:
- ResourceHandler
- Defined in:
- lib/pvectl/commands/get/handlers/storage.rb
Overview
Handler for listing Proxmox cluster storage pools.
Implements ResourceHandler interface for the “storages” resource type (with “storage” and “stor” as aliases). Uses Repositories::Storage for data access and Presenters::Storage for formatting.
Instance Method Summary collapse
-
#describe(name:, node: nil, args: [], vmid: nil) ⇒ Models::Storage+
Describes a single storage pool by name.
-
#initialize(repository: nil) ⇒ Storage
constructor
Creates handler with optional repository for dependency injection.
-
#list(node: nil, name: nil, args: [], storage: nil, **_options) ⇒ Array<Models::Storage>
Lists storage pools with optional filtering.
-
#presenter ⇒ Presenters::Storage
Returns presenter for storage pools.
Methods included from ResourceHandler
Constructor Details
#initialize(repository: nil) ⇒ Storage
Creates handler with optional repository for dependency injection.
27 28 29 |
# File 'lib/pvectl/commands/get/handlers/storage.rb', line 27 def initialize(repository: nil) @repository = repository end |
Instance Method Details
#describe(name:, node: nil, args: [], vmid: nil) ⇒ Models::Storage+
Describes a single storage pool by name.
For local storage (exists on multiple nodes):
-
Without node: returns array of instances (which nodes have it)
-
With node: returns full describe for that specific node
For shared storage: returns full describe (single instance).
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/pvectl/commands/get/handlers/storage.rb', line 64 def describe(name:, node: nil, args: [], vmid: nil) raise ArgumentError, "Invalid storage name" if name.nil? || name.empty? # Check if storage exists on multiple nodes (local storage) instances = repository.list_instances(name) raise Pvectl::ResourceNotFoundError, "Storage not found: #{name}" if instances.empty? if instances.size > 1 && node.nil? # Return list of instances instead of single describe return instances end # Single instance or node specified - full describe storage = repository.describe(name, node: node) unless storage if node raise Pvectl::ResourceNotFoundError, "Storage '#{name}' not found on node '#{node}'" else raise Pvectl::ResourceNotFoundError, "Storage not found: #{name}" end end storage end |
#list(node: nil, name: nil, args: [], storage: nil, **_options) ⇒ Array<Models::Storage>
Lists storage pools with optional filtering.
38 39 40 41 42 |
# File 'lib/pvectl/commands/get/handlers/storage.rb', line 38 def list(node: nil, name: nil, args: [], storage: nil, **) storage_pools = repository.list(node: node) storage_pools = storage_pools.select { |s| s.name == name } if name storage_pools end |
#presenter ⇒ Presenters::Storage
Returns presenter for storage pools.
47 48 49 |
# File 'lib/pvectl/commands/get/handlers/storage.rb', line 47 def presenter Pvectl::Presenters::Storage.new end |