Module: Pvectl::Commands::Cloudinit
- Defined in:
- lib/pvectl/commands/cloudinit/command.rb,
lib/pvectl/commands/cloudinit/dump.rb,
lib/pvectl/commands/cloudinit/pending.rb,
lib/pvectl/commands/cloudinit/regenerate.rb
Overview
Namespace for the pvectl cloudinit command group.
Provides three subcommands that operate on cloud-init configuration of QEMU VMs:
-
regenerate vm <id> — rebuild the cloud-init ISO
-
pending vm <id> — list pending configuration changes
-
dump vm <id> <type> — print generated cloud-init YAML
All subcommands share a common service-construction helper and a unified error-mapping path that distinguishes usage errors from not-found and connection errors.
Defined Under Namespace
Classes: Dump, Pending, Regenerate
Class Method Summary collapse
-
.register(cli) ⇒ void
Registers the cloudinit command group with the CLI.
-
.unknown_resource_type(resource_type) ⇒ Integer
Prints the standard “unknown resource type” error.
-
.usage_error(message) ⇒ Integer
Prints a usage error and returns the standard usage exit code.
-
.with_service(global_options) {|service| ... } ⇒ Integer
Builds a fresh
Services::Cloudinitfrom the active configuration and yields it to the caller.
Class Method Details
.register(cli) ⇒ void
This method returns an undefined value.
Registers the cloudinit command group with the CLI.
22 23 24 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 |
# File 'lib/pvectl/commands/cloudinit/command.rb', line 22 def self.register(cli) cli.desc "Manage cloud-init configuration for VMs" cli.long_desc <<~HELP DESCRIPTION Manage cloud-init configuration for QEMU virtual machines. Cloud-init lets you configure users, SSH keys, network, and other guest-side settings without baking them into the template image. Cloud-init is a VM-only feature — LXC containers do not expose cloud-init endpoints. SUBCOMMANDS cloudinit regenerate vm ID Rebuild the cloud-init ISO cloudinit pending vm ID List pending changes cloudinit dump vm ID TYPE Print generated YAML EXAMPLES Apply pending cloud-init changes: $ pvectl cloudinit regenerate vm 100 Preview what would change on next regenerate: $ pvectl cloudinit pending vm 100 Inspect the user-data that the guest will see: $ pvectl cloudinit dump vm 100 user NOTES +TYPE+ for +dump+ must be one of: +user+, +network+, +meta+. SEE ALSO pvectl help edit vm Edit cloud-init keys (cipassword, sshkeys, etc.) HELP cli.command :cloudinit do |c| c.desc "Source node (skips VMID lookup)" c.flag [:node, :n], arg_name: "NODE" Regenerate.register_subcommand(c) Pending.register_subcommand(c) Dump.register_subcommand(c) end end |
.unknown_resource_type(resource_type) ⇒ Integer
Prints the standard “unknown resource type” error.
115 116 117 118 119 |
# File 'lib/pvectl/commands/cloudinit/command.rb', line 115 def self.unknown_resource_type(resource_type) $stderr.puts "Error: Unknown or invalid resource type for cloudinit: #{resource_type}" $stderr.puts "Valid types: vm" Pvectl::ExitCodes::USAGE_ERROR end |
.usage_error(message) ⇒ Integer
Prints a usage error and returns the standard usage exit code.
106 107 108 109 |
# File 'lib/pvectl/commands/cloudinit/command.rb', line 106 def self.usage_error() $stderr.puts "Error: #{}" Pvectl::ExitCodes::USAGE_ERROR end |
.with_service(global_options) {|service| ... } ⇒ Integer
Builds a fresh Services::Cloudinit from the active configuration and yields it to the caller. Maps known exceptions to pvectl exit codes — anything else bubbles up to CLI.on_error.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/pvectl/commands/cloudinit/command.rb', line 72 def self.with_service() config_service = Pvectl::Config::Service.new config_service.load(config: [:config]) config = config_service.current_config connection = Pvectl::Connection.new(config) service = Pvectl::Services::Cloudinit.new( vm_repository: Pvectl::Repositories::Vm.new(connection), resource_resolver: Pvectl::Utils::ResourceResolver.new(connection) ) yield service Pvectl::ExitCodes::SUCCESS rescue Pvectl::ResourceNotFoundError => e $stderr.puts "Error: #{e.}" Pvectl::ExitCodes::NOT_FOUND rescue ArgumentError => e $stderr.puts "Error: #{e.}" Pvectl::ExitCodes::USAGE_ERROR rescue Pvectl::Config::ConfigNotFoundError, Pvectl::Config::InvalidConfigError, Pvectl::Config::ContextNotFoundError, Pvectl::Config::ClusterNotFoundError, Pvectl::Config::UserNotFoundError raise rescue StandardError => e $stderr.puts "Error: #{e.}" Pvectl::ExitCodes::GENERAL_ERROR end |