Class: Pvectl::Commands::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/pvectl/commands/console.rb,
sig/pvectl/commands/console.rbs

Overview

CLI registration for the pvectl console command.

Opens an interactive terminal console to a VM or container via WebSocket-based termproxy. Dispatches to ConsoleVm or ConsoleCt based on the resource type argument.

Examples:

Open console to a VM

pvectl console vm 100

Open console to a container

pvectl console ct 200

Open console with explicit credentials

pvectl console vm 100 --user root@pam --password secret

Constant Summary collapse

SUPPORTED_RESOURCES =

Supported resource type arguments.

%w[vm ct container].freeze

Class Method Summary collapse

Class Method Details

.register(cli) ⇒ void

This method returns an undefined value.

Registers the console command with the CLI.



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
83
84
85
86
87
88
89
90
# File 'lib/pvectl/commands/console.rb', line 28

def self.register(cli)
  cli.desc "Open interactive terminal console to a VM or container"
  cli.long_desc "    Open an interactive terminal session to a VM or container via\n    WebSocket-based termproxy (xtermjs protocol).\n\n    EXAMPLES\n      Open console to a VM:\n        $ pvectl console vm 100\n\n      Open console to a container:\n        $ pvectl console ct 200\n\n      Specify node explicitly:\n        $ pvectl console vm 100 --node pve1\n\n      Provide credentials (prompted for password if omitted):\n        $ pvectl console vm 100 --user root@pam\n\n    NOTES\n      Console requires session authentication (username/password). If your\n      config only has an API token, pvectl will prompt for credentials.\n\n      Disconnect with Ctrl+].\n\n      The console uses a WebSocket connection. Network interruptions will\n      close the session.\n\n    SEE ALSO\n      pvectl help describe        View VM/container configuration\n      pvectl help start           Start a stopped VM before connecting\n  HELP\n  cli.arg_name \"RESOURCE_TYPE ID\"\n  cli.command :console do |c|\n    c.desc \"Filter by node name\"\n    c.flag [:node, :n], arg_name: \"NODE\"\n\n    c.desc \"Username for session authentication\"\n    c.flag [:user], arg_name: \"USER\"\n\n    c.desc \"Password for session authentication\"\n    c.flag [:password], arg_name: \"PASSWORD\"\n\n    c.action do |global_options, options, args|\n      resource_type = args.shift\n      resource_id = args.shift\n\n      unless resource_type && SUPPORTED_RESOURCES.include?(resource_type)\n        $stderr.puts \"Error: Resource type required (vm, ct)\"\n        exit Pvectl::ExitCodes::USAGE_ERROR\n      end\n\n      exit_code = case resource_type\n      when \"ct\", \"container\"\n        ConsoleCt.execute(resource_id, options, global_options)\n      else\n        ConsoleVm.execute(resource_id, options, global_options)\n      end\n\n      exit exit_code if exit_code != 0\n    end\n  end\nend\n"