Class: Pvectl::Commands::Get::Handlers::Templates
- Inherits:
-
Object
- Object
- Pvectl::Commands::Get::Handlers::Templates
- Includes:
- ResourceHandler
- Defined in:
- lib/pvectl/commands/get/handlers/templates.rb
Overview
Handler for listing templates (both VM and container).
Queries both VM and Container repositories, filters by template? == true, and merges into a single list. Supports –type flag for filtering by resource type (vm/ct/qemu/lxc).
Constant Summary collapse
- TYPE_MAP =
Type filter mapping — normalizes user input to API type values.
{ "vm" => "qemu", "qemu" => "qemu", "ct" => "lxc", "container" => "lxc", "lxc" => "lxc" }.freeze
- SORT_FIELDS =
Sort field mappings for template listing.
{ "name" => ->(t) { t.name || "" }, "node" => ->(t) { t.node || "" }, "type" => ->(t) { t.type || "" }, "disk" => ->(t) { -(t.maxdisk || 0) } }.freeze
Instance Method Summary collapse
-
#initialize(vm_repository: nil, container_repository: nil) ⇒ Templates
constructor
Creates handler with optional repositories for dependency injection.
-
#list(node: nil, name: nil, type_filter: nil, sort: nil, **_options) ⇒ Array<Models::Vm, Models::Container>
Lists templates with optional filtering.
-
#presenter ⇒ Presenters::Template
Returns presenter for templates.
Methods included from ResourceHandler
Constructor Details
#initialize(vm_repository: nil, container_repository: nil) ⇒ Templates
Creates handler with optional repositories for dependency injection.
45 46 47 48 |
# File 'lib/pvectl/commands/get/handlers/templates.rb', line 45 def initialize(vm_repository: nil, container_repository: nil) @vm_repository = vm_repository @container_repository = container_repository end |
Instance Method Details
#list(node: nil, name: nil, type_filter: nil, sort: nil, **_options) ⇒ Array<Models::Vm, Models::Container>
Lists templates with optional filtering.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/pvectl/commands/get/handlers/templates.rb', line 58 def list(node: nil, name: nil, type_filter: nil, sort: nil, **) validate_type_filter!(type_filter) templates = [] unless skip_vms?(type_filter) vms = vm_repository.list(node: node) templates.concat(vms.select(&:template?)) end unless skip_containers?(type_filter) containers = container_repository.list(node: node) templates.concat(containers.select(&:template?)) end templates = apply_sort(templates, sort) if sort templates end |
#presenter ⇒ Presenters::Template
Returns presenter for templates.
80 81 82 |
# File 'lib/pvectl/commands/get/handlers/templates.rb', line 80 def presenter Pvectl::Presenters::Template.new end |