Class: Pvectl::Commands::ConsoleVm
- Inherits:
-
Object
- Object
- Pvectl::Commands::ConsoleVm
- Defined in:
- lib/pvectl/commands/console_vm.rb
Overview
Handler for the ‘pvectl console vm` command.
Opens an interactive terminal console session to a QEMU virtual machine via WebSocket-based termproxy. Requires a running VM and interactive terminal (TTY).
Class Method Summary collapse
-
.execute(vmid, options, global_options) ⇒ Integer
Executes the console VM command.
Instance Method Summary collapse
-
#execute ⇒ Integer
Executes the console flow.
-
#initialize(vmid, options, global_options) ⇒ ConsoleVm
constructor
Initializes a console VM command.
Constructor Details
#initialize(vmid, options, global_options) ⇒ ConsoleVm
Initializes a console VM command.
35 36 37 38 39 |
# File 'lib/pvectl/commands/console_vm.rb', line 35 def initialize(vmid, , ) @vmid = vmid @options = @global_options = end |
Class Method Details
.execute(vmid, options, global_options) ⇒ Integer
Executes the console VM command.
26 27 28 |
# File 'lib/pvectl/commands/console_vm.rb', line 26 def self.execute(vmid, , ) new(vmid, , ).execute end |
Instance Method Details
#execute ⇒ Integer
Executes the console flow.
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 |
# File 'lib/pvectl/commands/console_vm.rb', line 44 def execute return usage_error("VMID is required") unless @vmid return usage_error("Console requires an interactive terminal (TTY)") unless $stdin.tty? load_config connection = Pvectl::Connection.new(@config) repo = Pvectl::Repositories::Vm.new(connection) resource = repo.get(@vmid.to_i) return not_found("VM #{@vmid} not found") unless resource username, password = resolve_credentials return ExitCodes::GENERAL_ERROR if username.nil? || password.nil? $stderr.puts "Connecting to VM #{resource.vmid} (#{resource.name || 'unnamed'}) on node #{resource.node}..." Pvectl::Services::Console.new.run( resource: resource, resource_path: resource_path, server: @config.server, username: username, password: password, verify_ssl: @config.verify_ssl ) ExitCodes::SUCCESS rescue Services::Console::ResourceNotRunningError => e $stderr.puts "Error: #{e.}" ExitCodes::GENERAL_ERROR rescue Services::Console::AuthenticationError => e $stderr.puts "Error: #{e.}" ExitCodes::PERMISSION_DENIED rescue Pvectl::Config::ConfigNotFoundError, Pvectl::Config::InvalidConfigError, Pvectl::Config::ContextNotFoundError, Pvectl::Config::ClusterNotFoundError, Pvectl::Config::UserNotFoundError, Pvectl::Config::MissingCredentialsError raise # re-raise for CLI handler rescue Errno::ECONNREFUSED, SocketError, Timeout::Error => e $stderr.puts "Error: Cannot connect to console: #{e.}" ExitCodes::CONNECTION_ERROR rescue StandardError => e $stderr.puts "Error: #{e.}" ExitCodes::GENERAL_ERROR end |