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

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

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

#connectionPvectl::Connection

Builds API connection from current config.

Returns:



101
102
103
104
105
106
107
# File 'lib/pvectl/commands/get/handlers/time.rb', line 101

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) ⇒ Models::TimeConfig

Fetches the time config for a specific node, raising ResourceNotFoundError if the node itself does not exist in the cluster.

Parameters:

  • node_name (String)

    node name

Returns:

Raises:



72
73
74
75
76
77
78
# File 'lib/pvectl/commands/get/handlers/time.rb', line 72

def fetch_for(node_name)
  unless node_repository.get(node_name)
    raise Pvectl::ResourceNotFoundError, "Node not found: #{node_name}"
  end

  repository.fetch(node_name)
end

#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

  • 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:



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

#node_repositoryRepositories::Node

Returns node repository, lazily built.

Returns:



94
95
96
# File 'lib/pvectl/commands/get/handlers/time.rb', line 94

def node_repository
  @node_repository ||= Pvectl::Repositories::Node.new(connection)
end

#online_node_namesArray<String>

Names of online nodes (offline nodes are skipped because querying them is guaranteed to fail).

Returns:

  • (Array<String>)

    node names



84
85
86
# File 'lib/pvectl/commands/get/handlers/time.rb', line 84

def online_node_names
  node_repository.list.select { |n| n.status == "online" }.map(&:name)
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

#repositoryRepositories::TimeConfig

Returns time repository, lazily built.

Returns:



89
90
91
# File 'lib/pvectl/commands/get/handlers/time.rb', line 89

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