]> git.proxmox.com Git - pve-container.git/commitdiff
added pct exec
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 1 Sep 2015 07:16:49 +0000 (09:16 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 3 Sep 2015 16:37:25 +0000 (18:37 +0200)
Using the new 'extra-args' options for command arguments.

Examples:
 # pct exec 100 ls /
 # pct exec 100 -- ls -l /

src/pct

diff --git a/src/pct b/src/pct
index 9c78d5a388fda70c7bbfd8df5e4e5226f1363b00..45a33b5152c4b05493246327701eb5abc162885b 100755 (executable)
--- a/src/pct
+++ b/src/pct
@@ -86,6 +86,32 @@ __PACKAGE__->register_method ({
        exec('lxc-attach', '-n',  $param->{vmid});
     }});
 
+__PACKAGE__->register_method ({
+    name => 'exec',
+    path => 'exec',
+    method => 'GET',
+    description => "Launch a command inside the specified container.",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           vmid => get_standard_option('pve-vmid'),
+           'extra-args' => get_standard_option('extra-args'),
+       },
+    },
+    returns => { type => 'null' },
+
+    code => sub {
+       my ($param) = @_;
+
+       # test if container exists on this node
+       PVE::LXC::load_config($param->{vmid});
+
+       if (!@{$param->{'extra-args'}}) {
+           die "missing command";
+       }
+       exec('lxc-attach', '-n', $param->{vmid}, '--', @{$param->{'extra-args'}});
+    }});
+
 my $cmddef = {
     #test => [ __PACKAGE__, 'test', [], {}, sub {} ],
     list=> [ 'PVE::API2::LXC', 'vmlist', [], { node => $nodename }, sub {
@@ -124,6 +150,7 @@ my $cmddef = {
     
     console => [ __PACKAGE__, 'console', ['vmid']],
     enter => [ __PACKAGE__, 'enter', ['vmid']],
+    exec => [ __PACKAGE__, 'exec', ['vmid', 'extra-args']],
     
     destroy => [ 'PVE::API2::LXC', 'destroy_vm', ['vmid'], 
                 { node => $nodename }, $upid_exit ],