[pve-devel] [PATCH container] close #1940: added ability to specify escape sequence
Thomas Lamprecht
t.lamprecht at proxmox.com
Tue Oct 9 09:00:52 CEST 2018
On 10/8/18 3:21 PM, Tim Marx wrote:
> added the ability to pass a user defined escape sequence to pct console command
thanks for your patch!
>
> 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 => {
inline/whitespace error above
> + 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";
> + }
you actually can just set a pattern in the above property definition, e.g.:
pattern => '\^?([a-z])'
(start end hooks/anchors get automatically added)
Our nice JSONSchema using API does then the rest automatically :-)
> + }
> +
> # 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 {
>
More information about the pve-devel
mailing list