Class: Pvectl::Commands::Get::Handlers::Capabilities
- Inherits:
-
Object
- Object
- Pvectl::Commands::Get::Handlers::Capabilities
- Includes:
- ResourceHandler
- Defined in:
- lib/pvectl/commands/get/handlers/capabilities.rb,
sig/pvectl/commands/get/handlers/capabilities.rbs
Overview
Handler for pvectl get node-capabilities.
Surfaces what features a node supports — primarily the available
QEMU CPU models and machine types. When --node is provided the
query is scoped to that node; otherwise the handler iterates all
online nodes and aggregates the results, silently skipping
unreachable nodes (matches the pattern used by the time handler).
Instance Method Summary collapse
-
#connection ⇒ Pvectl::Connection
Builds API connection from the current config.
-
#fetch_for(node_name) ⇒ Array<Models::Capability>
Fetches capabilities for a specific node, raising when the node itself does not exist in the cluster.
-
#initialize(repository: nil, node_repository: nil) ⇒ Capabilities
constructor
A new instance of Capabilities.
-
#list(node: nil, name: nil, args: [], storage: nil, **_options) ⇒ Array<Models::Capability>
Lists capabilities, optionally scoped to a node.
- #node_repository ⇒ Repositories::Node
-
#online_node_names ⇒ Array<String>
Names of online nodes.
-
#presenter ⇒ Presenters::Capability
Returns the capability presenter.
- #repository ⇒ Repositories::Capabilities
Methods included from ResourceHandler
Constructor Details
#initialize(repository: nil, node_repository: nil) ⇒ Capabilities
Returns a new instance of Capabilities.
23 24 25 26 |
# File 'lib/pvectl/commands/get/handlers/capabilities.rb', line 23 def initialize(repository: nil, node_repository: nil) @repository = repository @node_repository = node_repository end |
Instance Method Details
#connection ⇒ Pvectl::Connection
Builds API connection from the current config.
89 90 91 92 93 94 95 |
# File 'lib/pvectl/commands/get/handlers/capabilities.rb', line 89 def connection @connection ||= begin config_service = Pvectl::Config::Service.new config_service.load Pvectl::Connection.new(config_service.current_config) end end |
#fetch_for(node_name) ⇒ Array<Models::Capability>
Fetches capabilities for a specific node, raising when the node itself does not exist in the cluster.
61 62 63 64 65 66 67 |
# File 'lib/pvectl/commands/get/handlers/capabilities.rb', line 61 def fetch_for(node_name) unless node_repository.get(node_name) raise Pvectl::ResourceNotFoundError, "Node not found: #{node_name}" end repository.list(node: node_name) end |
#list(node: nil, name: nil, args: [], storage: nil, **_options) ⇒ Array<Models::Capability>
Lists capabilities, optionally scoped to a node.
36 37 38 39 40 41 42 43 44 |
# File 'lib/pvectl/commands/get/handlers/capabilities.rb', line 36 def list(node: nil, name: nil, args: [], storage: nil, **) return fetch_for(node) if node online_node_names.flat_map do |node_name| repository.list(node: node_name) rescue StandardError [] end end |
#node_repository ⇒ Repositories::Node
82 83 84 |
# File 'lib/pvectl/commands/get/handlers/capabilities.rb', line 82 def node_repository @node_repository ||= Pvectl::Repositories::Node.new(connection) end |
#online_node_names ⇒ Array<String>
Names of online nodes.
72 73 74 |
# File 'lib/pvectl/commands/get/handlers/capabilities.rb', line 72 def online_node_names node_repository.list.select { |n| n.status == "online" }.map(&:name) end |
#presenter ⇒ Presenters::Capability
Returns the capability presenter.
49 50 51 |
# File 'lib/pvectl/commands/get/handlers/capabilities.rb', line 49 def presenter Pvectl::Presenters::Capability.new end |
#repository ⇒ Repositories::Capabilities
77 78 79 |
# File 'lib/pvectl/commands/get/handlers/capabilities.rb', line 77 def repository @repository ||= Pvectl::Repositories::Capabilities.new(connection) end |