Class: Pvectl::Commands::Get::Handlers::Capabilities

Inherits:
Object
  • Object
show all
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

Methods included from ResourceHandler

#selector_class

Constructor Details

#initialize(repository: nil, node_repository: nil) ⇒ Capabilities

Returns a new instance of Capabilities.

Parameters:



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

#connectionPvectl::Connection

Builds API connection from the current config.

Returns:



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.

Parameters:

  • node_name (String)

Returns:

Raises:



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.

Parameters:

  • node (String, nil) (defaults to: nil)

    when provided, only that node is queried

  • name (String, nil) (defaults to: nil)

    unused, interface compatibility

  • args (Array<String>) (defaults to: [])

    unused, interface compatibility

  • storage (String, nil) (defaults to: nil)

    unused, interface compatibility

  • node: (String, nil) (defaults to: nil)
  • name: (String, nil) (defaults to: nil)
  • args: (Array[String]) (defaults to: [])
  • storage: (String, nil) (defaults to: nil)

Returns:

Raises:



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, **_options)
  return fetch_for(node) if node

  online_node_names.flat_map do |node_name|
    repository.list(node: node_name)
  rescue StandardError
    []
  end
end

#node_repositoryRepositories::Node

Returns:



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_namesArray<String>

Names of online nodes.

Returns:

  • (Array<String>)


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

#presenterPresenters::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

#repositoryRepositories::Capabilities



77
78
79
# File 'lib/pvectl/commands/get/handlers/capabilities.rb', line 77

def repository
  @repository ||= Pvectl::Repositories::Capabilities.new(connection)
end