[pve-devel] [PATCH container] close #1940: added ability to specify escape sequence
Tim Marx
t.marx at proxmox.com
Mon Oct 8 15:21:53 CEST 2018
added the ability to pass a user defined escape sequence to pct console command
Signed-off-by: Tim Marx <t.marx at proxmox.com>
---
src/PVE/CLI/pct.pm | 17 ++++++++++++++++-
src/PVE/LXC.pm | 6 +++---
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/src/PVE/CLI/pct.pm b/src/PVE/CLI/pct.pm
index 6296d6f..3824ee5 100755
--- a/src/PVE/CLI/pct.pm
+++ b/src/PVE/CLI/pct.pm
@@ -119,6 +119,11 @@ __PACKAGE__->register_method ({
additionalProperties => 0,
properties => {
vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_running }),
+ escape => {
+ description => "Escape character.",
+ type => 'string',
+ optional => 1,
+ },
},
},
returns => { type => 'null' },
@@ -126,10 +131,20 @@ __PACKAGE__->register_method ({
code => sub {
my ($param) = @_;
+ my $escape = $param->{escape};
+
+ if (defined($escape)) {
+ if ($escape =~ /^\^?([a-z])$/) {
+ $escape = $escape;
+ } else {
+ die "invalid escape character definition: $escape\n";
+ }
+ }
+
# test if container exists on this node
my $conf = PVE::LXC::Config->load_config($param->{vmid});
- my $cmd = PVE::LXC::get_console_command($param->{vmid}, $conf);
+ my $cmd = PVE::LXC::get_console_command($param->{vmid}, $conf, $escape);
exec(@$cmd);
}});
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 89f289e..09960a8 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -664,17 +664,17 @@ sub verify_searchdomain_list {
}
sub get_console_command {
- my ($vmid, $conf, $noescapechar) = @_;
+ my ($vmid, $conf, $escapechar) = @_;
my $cmode = PVE::LXC::Config->get_cmode($conf);
my $cmd = [];
if ($cmode eq 'console') {
push @$cmd, 'lxc-console', '-n', $vmid, '-t', 0;
- push @$cmd, '-e', -1 if $noescapechar;
+ push @$cmd, '-e', $escapechar if $escapechar;
} elsif ($cmode eq 'tty') {
push @$cmd, 'lxc-console', '-n', $vmid;
- push @$cmd, '-e', -1 if $noescapechar;
+ push @$cmd, '-e', $escapechar if $escapechar;
} elsif ($cmode eq 'shell') {
push @$cmd, 'lxc-attach', '--clear-env', '-n', $vmid;
} else {
--
2.11.0
More information about the pve-devel
mailing list