Class: Pvectl::Commands::Get::Handlers::Hosts
- Inherits:
-
Object
- Object
- Pvectl::Commands::Get::Handlers::Hosts
- Includes:
- ResourceHandler
- Defined in:
- lib/pvectl/commands/get/handlers/hosts.rb
Overview
Handler for reading per-node /etc/hosts contents.
Implements ResourceHandler interface for the “hosts” resource type. /etc/hosts is a singleton resource per node — there is no cluster-wide hosts file, so a node name is always required.
Instance Method Summary collapse
-
#describe(name:, node: nil, **_opts) ⇒ Models::HostsFile
Describes the /etc/hosts contents for a single node.
-
#initialize(repository: nil) ⇒ Hosts
constructor
Creates handler with optional repository for dependency injection.
-
#list(node: nil, **_options) ⇒ Array<Models::HostsFile>
Returns the /etc/hosts contents for the given node, wrapped in an array.
-
#presenter ⇒ Presenters::HostsFile
Returns presenter for /etc/hosts.
Methods included from ResourceHandler
Constructor Details
#initialize(repository: nil) ⇒ Hosts
Creates handler with optional repository for dependency injection.
26 27 28 |
# File 'lib/pvectl/commands/get/handlers/hosts.rb', line 26 def initialize(repository: nil) @repository = repository end |
Instance Method Details
#describe(name:, node: nil, **_opts) ⇒ Models::HostsFile
Describes the /etc/hosts contents for a single node.
Accepts either ‘name` (positional argument from describe command) or `node` (–node flag) as the node identifier.
59 60 61 62 63 64 |
# File 'lib/pvectl/commands/get/handlers/hosts.rb', line 59 def describe(name:, node: nil, **_opts) node_name = name || node raise ArgumentError, "Node name required: pvectl describe hosts NODE or --node NODE" if node_name.nil? || node_name.to_s.empty? repository.fetch(node_name) end |
#list(node: nil, **_options) ⇒ Array<Models::HostsFile>
Returns the /etc/hosts contents for the given node, wrapped in an array.
36 37 38 39 40 |
# File 'lib/pvectl/commands/get/handlers/hosts.rb', line 36 def list(node: nil, **) raise ArgumentError, "hosts requires --node NODE to identify which node's /etc/hosts to read" if node.nil? || node.to_s.empty? [repository.fetch(node)] end |
#presenter ⇒ Presenters::HostsFile
Returns presenter for /etc/hosts.
45 46 47 |
# File 'lib/pvectl/commands/get/handlers/hosts.rb', line 45 def presenter Pvectl::Presenters::HostsFile.new end |