Class: Pvectl::Commands::Get::Handlers::Time

Inherits:
Object
  • Object
show all
Includes:
ResourceHandler
Defined in:
lib/pvectl/commands/get/handlers/time.rb

Overview

Handler for listing node time and timezone settings.

Implements ResourceHandler interface for the “time” resource type. When ‘–node` is supplied, returns the time config for that single node. Otherwise, iterates over all online nodes and aggregates their time configs. Unreachable nodes (those that raise during fetch) are silently skipped so one bad node does not abort the whole listing.

Examples:

Using via ResourceRegistry

handler = ResourceRegistry.for("time")
configs = handler.list(node: "pve1")

See Also:

Instance Method Summary collapse

Methods included from ResourceHandler

#selector_class

Constructor Details

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

Creates handler with optional repositories for dependency injection.

Parameters:



30
31
32
33
# File 'lib/pvectl/commands/get/handlers/time.rb', line 30

def initialize(repository: nil, node_repository: nil)
  @repository = repository
  @node_repository = node_repository
end

Instance Method Details

#list(node: nil, name: nil, args: [], storage: nil, **_options) ⇒ Array<Models::TimeConfig>

Lists time/timezone configs.

Parameters:

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

    when given, only that node is queried; otherwise iterates all online nodes

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

    unused, for interface compatibility

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

    unused, for interface compatibility

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

    unused, for interface compatibility

Returns:

Raises:



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pvectl/commands/get/handlers/time.rb', line 44

def list(node: nil, name: nil, args: [], storage: nil, **_options)
  return [fetch_for(node)] if node

  online_node_names.filter_map do |node_name|
    begin
      repository.fetch(node_name)
    rescue StandardError
      # Skip unreachable nodes - one bad node should not abort the listing.
      nil
    end
  end
end

#presenterPresenters::TimeConfig

Returns presenter for time configs.



60
61
62
# File 'lib/pvectl/commands/get/handlers/time.rb', line 60

def presenter
  Pvectl::Presenters::TimeConfig.new
end