Class: Pvectl::Commands::Apt
- Inherits:
-
Object
- Object
- Pvectl::Commands::Apt
- Defined in:
- lib/pvectl/commands/apt.rb,
sig/pvectl/commands/apt.rbs
Overview
Top-level pvectl apt command for managing APT packages on Proxmox nodes.
Exposes four sub-commands:
apt listlist pending package updatesapt updaterefresh the package index (apt-get update)apt changelogshow changelog for a packageapt versionslist installed Proxmox-relevant package versions
Each sub-command requires --node NODE (falls back to default-node from
the active context configuration when not provided).
Class Method Summary collapse
-
.execute(operation, args, options, global_options) ⇒ Integer
Executes the command.
-
.register(cli) ⇒ void
Registers the apt command and all sub-commands with the CLI.
-
.register_changelog(parent) ⇒ void
Registers the
apt changelogsubcommand. -
.register_list(parent) ⇒ void
Registers the
apt listsubcommand. -
.register_update(parent) ⇒ void
Registers the
apt updatesubcommand. -
.register_versions(parent) ⇒ void
Registers the
apt versionssubcommand.
Instance Method Summary collapse
-
#build_update_result(node, upid) ⇒ Models::NodeOperationResult
Builds a NodeOperationResult representing an apt update kick-off.
-
#config_error(message) ⇒ Integer
Outputs a config error.
-
#execute ⇒ Integer
Executes the command.
-
#initialize(operation, args, options, global_options, output: $stdout) ⇒ Apt
constructor
Initializes an apt command instance.
-
#load_config ⇒ void
Loads configuration.
-
#render_operation_result(result) ⇒ void
Renders a NodeOperationResult (used by
apt update). -
#render_packages(packages) ⇒ void
Renders an array of AptPackage models using the configured formatter.
-
#repository ⇒ Repositories::Apt
Returns the apt repository (lazy).
-
#resolve_node ⇒ String?
Resolves the node from --node option or default-node config.
-
#run_changelog(node) ⇒ Integer
Runs
apt changelog— prints raw changelog text to stdout. -
#run_list(node) ⇒ Integer
Runs
apt list— prints pending updates as a table. -
#run_update(node) ⇒ Integer
Runs
apt update— triggers index refresh and reports the UPID. -
#run_versions(node) ⇒ Integer
Runs
apt versions— lists important Proxmox package versions. -
#usage_error(message) ⇒ Integer
Outputs a usage error.
Constructor Details
#initialize(operation, args, options, global_options, output: $stdout) ⇒ Apt
Initializes an apt command instance.
218 219 220 221 222 223 224 |
# File 'lib/pvectl/commands/apt.rb', line 218 def initialize(operation, args, , , output: $stdout) @operation = operation @args = Array(args).compact @options = @global_options = @output = output end |
Class Method Details
.execute(operation, args, options, global_options) ⇒ Integer
Executes the command.
207 208 209 |
# File 'lib/pvectl/commands/apt.rb', line 207 def self.execute(operation, args, , ) new(operation, args, , ).execute end |
.register(cli) ⇒ void
This method returns an undefined value.
Registers the apt command and all sub-commands with the CLI.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/pvectl/commands/apt.rb', line 25 def self.register(cli) cli.desc "Manage APT packages on Proxmox nodes" cli.long_desc <<~HELP DESCRIPTION Manage APT (Advanced Package Tool) packages on Proxmox VE nodes. Wraps the Proxmox /nodes/{node}/apt API to inspect pending updates, refresh the package index, read package changelogs, and report installed Proxmox-relevant package versions. SUB-COMMANDS apt list List pending package updates apt update Refresh the package index (apt-get update) apt changelog PACKAGE Show changelog for a package apt versions Show installed Proxmox package versions EXAMPLES List pending updates on a node: $ pvectl apt list --node pve1 Refresh the package index on the default node: $ pvectl apt update Refresh quietly without sending update notifications: $ pvectl apt update --node pve1 --quiet Show changelog for a specific package version: $ pvectl apt changelog pve-manager --node pve1 --version 8.2.4-1 Inspect installed Proxmox versions (parity with pveversion -v): $ pvectl apt versions --node pve1 -o wide NOTES --node defaults to the context's default-node when configured. Proxmox does NOT expose `apt upgrade` over the API (security restriction). To actually install updates you must SSH to the node and run apt full-upgrade manually. `apt update` is asynchronous; the response includes the Proxmox task UPID, inspect with `pvectl get tasks` and `pvectl logs task UPID`. SEE ALSO pvectl help get List resources (try `get nodes`) pvectl help logs Inspect task output HELP cli.command :apt do |c| # Shared --node flag declared on the parent so every subcommand inherits it. c.desc "Node name (defaults to context default-node)" c.flag [:node], arg_name: "NODE" register_list(c) register_update(c) register_changelog(c) register_versions(c) end end |
.register_changelog(parent) ⇒ void
This method returns an undefined value.
Registers the apt changelog subcommand.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/pvectl/commands/apt.rb', line 148 def self.register_changelog(parent) parent.desc "Show the changelog for an APT package on a node" parent.long_desc <<~HELP Show the upstream changelog for a package on the target node. When --version is omitted the latest available version's changelog is returned. EXAMPLES $ pvectl apt changelog pve-manager --node pve1 $ pvectl apt changelog pve-manager --node pve1 --version 8.2.4-1 SEE ALSO pvectl help apt Parent command HELP parent.arg_name "PACKAGE" parent.command :changelog do |sub| sub.desc "Package version (optional, defaults to latest)" sub.flag [:version], arg_name: "VERSION" sub.action do |, , args| exit_code = execute(:changelog, args, , ) exit exit_code if exit_code != 0 end end end |
.register_list(parent) ⇒ void
This method returns an undefined value.
Registers the apt list subcommand.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/pvectl/commands/apt.rb', line 88 def self.register_list(parent) parent.desc "List pending APT updates on a node" parent.long_desc <<~HELP List packages that have an available APT update on the target node. EXAMPLES $ pvectl apt list --node pve1 $ pvectl apt list --node pve1 -o wide $ pvectl apt list --node pve1 -o json SEE ALSO pvectl help apt Parent command HELP parent.command :list do |sub| sub.action do |, , args| exit_code = execute(:list, args, , ) exit exit_code if exit_code != 0 end end end |
.register_update(parent) ⇒ void
This method returns an undefined value.
Registers the apt update subcommand.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/pvectl/commands/apt.rb', line 113 def self.register_update(parent) parent.desc "Refresh the APT package index on a node (apt-get update)" parent.long_desc <<~HELP Refresh the APT package index on the target node. Equivalent to running `apt-get update` directly on the node. This does NOT install updates — Proxmox does not expose apt upgrade over the API for security reasons. EXAMPLES $ pvectl apt update --node pve1 $ pvectl apt update --node pve1 --quiet $ pvectl apt update --node pve1 --notify SEE ALSO pvectl help apt Parent command HELP parent.command :update do |sub| sub.desc "Send a notification about new packages" sub.switch [:notify], negatable: false sub.desc "Suppress progress output" sub.switch [:quiet], negatable: false sub.action do |, , args| exit_code = execute(:update, args, , ) exit exit_code if exit_code != 0 end end end |
.register_versions(parent) ⇒ void
This method returns an undefined value.
Registers the apt versions subcommand.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/pvectl/commands/apt.rb', line 178 def self.register_versions(parent) parent.desc "Show installed Proxmox package versions on a node" parent.long_desc <<~HELP Show installed versions of important Proxmox VE packages on the target node — parity with `pveversion -v` on the node itself. EXAMPLES $ pvectl apt versions --node pve1 $ pvectl apt versions --node pve1 -o wide $ pvectl apt versions --node pve1 -o yaml SEE ALSO pvectl help apt Parent command HELP parent.command :versions do |sub| sub.action do |, , args| exit_code = execute(:versions, args, , ) exit exit_code if exit_code != 0 end end end |
Instance Method Details
#build_update_result(node, upid) ⇒ Models::NodeOperationResult
Builds a NodeOperationResult representing an apt update kick-off.
360 361 362 363 364 365 366 367 368 |
# File 'lib/pvectl/commands/apt.rb', line 360 def build_update_result(node, upid) Pvectl::Models::NodeOperationResult.new( operation: :update, node_model: Pvectl::Models::Node.new(name: node), resource: { node: node }, task_upid: upid, success: :pending ) end |
#config_error(message) ⇒ Integer
Outputs a config error.
383 384 385 386 |
# File 'lib/pvectl/commands/apt.rb', line 383 def config_error() $stderr.puts "Error: #{}" ExitCodes::CONFIG_ERROR end |
#execute ⇒ Integer
Executes the command.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/pvectl/commands/apt.rb', line 229 def execute load_config node = resolve_node return config_error("node is required (provide --node or configure default-node)") unless node case @operation when :list then run_list(node) when :update then run_update(node) when :changelog then run_changelog(node) when :versions then run_versions(node) else usage_error("Unknown apt operation: #{@operation}") end rescue Pvectl::Config::ConfigNotFoundError, Pvectl::Config::InvalidConfigError, Pvectl::Config::ContextNotFoundError, Pvectl::Config::ClusterNotFoundError, Pvectl::Config::UserNotFoundError => e $stderr.puts "Error: #{e.}" ExitCodes::CONFIG_ERROR rescue StandardError => e $stderr.puts "Error: #{e.}" ExitCodes::GENERAL_ERROR end |
#load_config ⇒ void
This method returns an undefined value.
Loads configuration.
259 260 261 262 263 |
# File 'lib/pvectl/commands/apt.rb', line 259 def load_config service = Pvectl::Config::Service.new service.load(config: @global_options[:config]) @config = service.current_config end |
#render_operation_result(result) ⇒ void
This method returns an undefined value.
Renders a NodeOperationResult (used by apt update).
346 347 348 349 350 351 352 353 |
# File 'lib/pvectl/commands/apt.rb', line 346 def render_operation_result(result) Pvectl::Formatters::OutputHelper.print( data: [result], presenter: Pvectl::Presenters::NodeOperationResult.new, format: @global_options[:output] || "table", color_flag: @global_options[:color] ) end |
#render_packages(packages) ⇒ void
This method returns an undefined value.
Renders an array of AptPackage models using the configured formatter.
333 334 335 336 337 338 339 340 |
# File 'lib/pvectl/commands/apt.rb', line 333 def render_packages(packages) Pvectl::Formatters::OutputHelper.print( data: packages, presenter: Pvectl::Presenters::AptPackage.new, format: @global_options[:output] || "table", color_flag: @global_options[:color] ) end |
#repository ⇒ Repositories::Apt
Returns the apt repository (lazy).
275 276 277 |
# File 'lib/pvectl/commands/apt.rb', line 275 def repository @repository ||= Pvectl::Repositories::Apt.new(Pvectl::Connection.new(@config)) end |
#resolve_node ⇒ String?
Resolves the node from --node option or default-node config.
268 269 270 |
# File 'lib/pvectl/commands/apt.rb', line 268 def resolve_node @options[:node] || @config&.default_node end |
#run_changelog(node) ⇒ Integer
Runs apt changelog — prints raw changelog text to stdout.
305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/pvectl/commands/apt.rb', line 305 def run_changelog(node) return usage_error("package name is required") if @args.empty? package = @args.first version = @options[:version] text = repository.changelog(node, package, version: version) if text.nil? || text.empty? @output.puts "(no changelog available)" else @output.puts text end ExitCodes::SUCCESS end |
#run_list(node) ⇒ Integer
Runs apt list — prints pending updates as a table.
283 284 285 286 287 |
# File 'lib/pvectl/commands/apt.rb', line 283 def run_list(node) packages = repository.pending(node) render_packages(packages) ExitCodes::SUCCESS end |
#run_update(node) ⇒ Integer
Runs apt update — triggers index refresh and reports the UPID.
293 294 295 296 297 298 299 |
# File 'lib/pvectl/commands/apt.rb', line 293 def run_update(node) upid = repository.refresh(node, notify: @options[:notify] ? true : false, quiet: @options[:quiet] ? true : false) result = build_update_result(node, upid) render_operation_result(result) ExitCodes::SUCCESS end |
#run_versions(node) ⇒ Integer
Runs apt versions — lists important Proxmox package versions.
323 324 325 326 327 |
# File 'lib/pvectl/commands/apt.rb', line 323 def run_versions(node) packages = repository.versions(node) render_packages(packages) ExitCodes::SUCCESS end |
#usage_error(message) ⇒ Integer
Outputs a usage error.
374 375 376 377 |
# File 'lib/pvectl/commands/apt.rb', line 374 def usage_error() $stderr.puts "Error: #{}" ExitCodes::USAGE_ERROR end |