Class: Pvectl::Commands::Config::SetCluster
- Inherits:
-
Object
- Object
- Pvectl::Commands::Config::SetCluster
- Defined in:
- lib/pvectl/commands/config/set_cluster.rb
Overview
Handler for the ‘pvectl config set-cluster` command.
Creates a new cluster or modifies an existing one in the configuration. Requires –server flag for new clusters.
Class Method Summary collapse
-
.execute(cluster_name, options, global_options) ⇒ Integer
Executes the set-cluster command.
-
.register_subcommand(parent) ⇒ void
Registers the set-cluster subcommand.
Class Method Details
.execute(cluster_name, options, global_options) ⇒ Integer
Executes the set-cluster command.
62 63 64 65 66 67 68 69 70 71 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 |
# File 'lib/pvectl/commands/config/set_cluster.rb', line 62 def self.execute(cluster_name, , ) config_path = [:config] service = Pvectl::Config::Service.new service.load(config: config_path) existing_cluster = service.cluster(cluster_name) action = existing_cluster ? "modified" : "created" # Use existing values if not provided server = [:server] || existing_cluster&.server = [:"certificate-authority"] || [:certificate_authority] || existing_cluster&. # Handle insecure-skip-tls-verify flag insecure_skip = [:"insecure-skip-tls-verify"] verify_ssl = if insecure_skip.nil? existing_cluster ? existing_cluster.verify_ssl : true else !insecure_skip end # Validate required fields for new clusters if server.nil? $stderr.puts "Error: --server is required for new clusters" return ExitCodes::USAGE_ERROR end service.set_cluster( name: cluster_name, server: server, verify_ssl: verify_ssl, certificate_authority: ) puts "Cluster \"#{cluster_name}\" #{action}." 0 end |
.register_subcommand(parent) ⇒ void
This method returns an undefined value.
Registers the set-cluster subcommand.
21 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 |
# File 'lib/pvectl/commands/config/set_cluster.rb', line 21 def self.register_subcommand(parent) parent.desc "Create or modify a cluster" parent.long_desc <<~HELP Create a new cluster definition or modify an existing one. EXAMPLES Add a cluster: $ pvectl config set-cluster production --server=https://pve.example.com:8006 Skip TLS verification (testing only): $ pvectl config set-cluster lab --server=https://pve-lab:8006 --insecure-skip-tls-verify HELP parent.command :"set-cluster" do |set_cluster| set_cluster.arg_name "CLUSTER_NAME" set_cluster.desc "Proxmox server URL (e.g., https://pve.example.com:8006)" set_cluster.flag [:server] set_cluster.desc "Path to CA certificate file" set_cluster.flag [:"certificate-authority"] set_cluster.desc "Skip TLS certificate verification" set_cluster.switch [:"insecure-skip-tls-verify"], negatable: false set_cluster.action do |, , args| if args.empty? $stderr.puts "Error: cluster name is required" exit ExitCodes::USAGE_ERROR end exit_code = execute(args[0], , ) exit exit_code if exit_code != 0 end end end |