mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-06-14 13:26:24 +00:00
implement 'qm terminal' to open terminal via serial device
This commit is contained in:
parent
9f9d2fb261
commit
c243fc8af6
@ -3,7 +3,7 @@ Version: @@VERSION@@-@@PKGRELEASE@@
|
|||||||
Section: admin
|
Section: admin
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Architecture: @@ARCH@@
|
Architecture: @@ARCH@@
|
||||||
Depends: libc6 (>= 2.7-18), perl (>= 5.10.0-19), libterm-readline-gnu-perl, pve-qemu-kvm (>= 1.4-16), netcat-traditional, libpve-storage-perl, pve-cluster, redhat-cluster-pve, libjson-perl, libjson-xs-perl, libio-multiplex-perl, libnet-ssleay-perl
|
Depends: libc6 (>= 2.7-18), perl (>= 5.10.0-19), libterm-readline-gnu-perl, pve-qemu-kvm (>= 1.4-16), netcat-traditional, libpve-storage-perl, pve-cluster, redhat-cluster-pve, libjson-perl, libjson-xs-perl, libio-multiplex-perl, libnet-ssleay-perl, socat
|
||||||
Conflicts: netcat-openbsd
|
Conflicts: netcat-openbsd
|
||||||
Maintainer: Proxmox Support Team <support@proxmox.com>
|
Maintainer: Proxmox Support Team <support@proxmox.com>
|
||||||
Description: Qemu Server Tools
|
Description: Qemu Server Tools
|
||||||
|
54
qm
54
qm
@ -326,6 +326,58 @@ __PACKAGE__->register_method ({
|
|||||||
return undef;
|
return undef;
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
__PACKAGE__->register_method ({
|
||||||
|
name => 'terminal',
|
||||||
|
path => 'terminal',
|
||||||
|
method => 'POST',
|
||||||
|
description => "Open a terminal using a serial device (The VM need to have a serial device configured, for example 'serial0: socket')",
|
||||||
|
parameters => {
|
||||||
|
additionalProperties => 0,
|
||||||
|
properties => {
|
||||||
|
vmid => get_standard_option('pve-vmid'),
|
||||||
|
iface => {
|
||||||
|
type => 'string',
|
||||||
|
optional => 1,
|
||||||
|
enum => [qw(serial0 serial1 serial2 serial3)],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
returns => { type => 'null'},
|
||||||
|
code => sub {
|
||||||
|
my ($param) = @_;
|
||||||
|
|
||||||
|
my $vmid = $param->{vmid};
|
||||||
|
|
||||||
|
my $conf = PVE::QemuServer::load_config ($vmid); # check if VM exists
|
||||||
|
|
||||||
|
my $iface = $param->{iface};
|
||||||
|
|
||||||
|
if ($iface) {
|
||||||
|
die "serial interface '$iface' is not configured\n" if !$conf->{$iface};
|
||||||
|
die "wrong serial type on interface '$iface'\n" if $conf->{$iface} ne 'socket';
|
||||||
|
} else {
|
||||||
|
foreach my $opt (qw(serial0 serial1 serial2 serial3)) {
|
||||||
|
if ($conf->{$opt} && ($conf->{$opt} eq 'socket')) {
|
||||||
|
$iface = $opt;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
die "unable to find a serial interface\n" if !$iface;
|
||||||
|
}
|
||||||
|
|
||||||
|
die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid);
|
||||||
|
|
||||||
|
my $socket = "/var/run/qemu-server/${vmid}.$iface";
|
||||||
|
|
||||||
|
my $cmd = "socat UNIX-CONNECT:$socket STDIO,raw,echo=0,escape=0x0f";
|
||||||
|
|
||||||
|
print "starting serial terminal on interface $iface (press control-O to exit)\n";
|
||||||
|
|
||||||
|
system($cmd);
|
||||||
|
|
||||||
|
return undef;
|
||||||
|
}});
|
||||||
|
|
||||||
my $cmddef = {
|
my $cmddef = {
|
||||||
list => [ "PVE::API2::Qemu", 'vmlist', [],
|
list => [ "PVE::API2::Qemu", 'vmlist', [],
|
||||||
{ node => $nodename }, sub {
|
{ node => $nodename }, sub {
|
||||||
@ -413,6 +465,8 @@ my $cmddef = {
|
|||||||
monitor => [ __PACKAGE__, 'monitor', ['vmid']],
|
monitor => [ __PACKAGE__, 'monitor', ['vmid']],
|
||||||
|
|
||||||
mtunnel => [ __PACKAGE__, 'mtunnel', []],
|
mtunnel => [ __PACKAGE__, 'mtunnel', []],
|
||||||
|
|
||||||
|
terminal => [ __PACKAGE__, 'terminal', ['vmid']],
|
||||||
};
|
};
|
||||||
|
|
||||||
my $cmd = shift;
|
my $cmd = shift;
|
||||||
|
Loading…
Reference in New Issue
Block a user