]> git.proxmox.com Git - pve-client.git/commitdiff
Add task log to 'lxc create'
authorRené Jochum <r.jochum@proxmox.com>
Tue, 19 Jun 2018 15:46:51 +0000 (17:46 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 20 Jun 2018 04:42:49 +0000 (06:42 +0200)
PVE/APIClient/Commands/lxc.pm
PVE/APIClient/Helpers.pm

index 2309ec04e359fafc19df2f0ff8e63b86d9e32443..3add2dd3f3a658a209305df40f6daa6d2d51bf09 100644 (file)
@@ -429,6 +429,16 @@ __PACKAGE__->register_method ({
                remote => get_standard_option('pveclient-remote-name'),
                vmid => get_standard_option('pve-vmid'),
                node => get_standard_option('pve-node'),
+               quiet => {
+                   description => "Suppress log output.",
+                   type => 'boolean',
+                   optional => 1,
+               },
+               background => {
+                   description => "Do not wait for the command to complete.",
+                   type => 'boolean',
+                   optional => 1,
+               },
        }),
     },
     returns => { type => 'null'},
@@ -439,12 +449,17 @@ __PACKAGE__->register_method ({
        my $vmid = $param->{vmid};
        my $node = PVE::APIClient::Tools::extract_param($param, 'node');
 
+       my $quiet = PVE::APIClient::Tools::extract_param($param, 'quiet');
+       my $background = PVE::APIClient::Tools::extract_param($param, 'background');
+
        my $config = PVE::APIClient::Config->load();
        my $conn = PVE::APIClient::Config->remote_conn($config, $remote);
 
        my $upid = $conn->post("/nodes/$node/lxc", $param);
 
-       print PVE::APIClient::Helpers::poll_task($conn, $node, $upid) . "\n";
+       if (!$background) {
+           print PVE::APIClient::Helpers::poll_task($conn, $node, $upid, $quiet) . "\n";
+       }
 
        return undef;
     }});
@@ -475,7 +490,7 @@ __PACKAGE__->register_method ({
 
        my $upid = $conn->delete("/nodes/$resource->{node}/lxc/$resource->{vmid}", $param);
 
-       print PVE::APIClient::Helpers::poll_task($conn, $resource->{node}, $upid) . "\n";
+       print PVE::APIClient::Helpers::poll_task($conn, $resource->{node}, $upid, 1) . "\n";
 
        return undef;
     }});
index 30b847533564d0240c15831173dee9d73c4f36fb..7d855ec6ce58fc6775569fbb426c364dcc3f58bf 100644 (file)
@@ -321,19 +321,38 @@ sub get_vmid_resource {
 }
 
 sub poll_task {
-    my ($conn, $node, $upid) = @_;
+    my ($conn, $node, $upid, $quiet) = @_;
 
     my $path = "api2/json/nodes/$node/tasks/$upid/status";
 
     my $task_status;
+    my $last_line = 0;
     while(1) {
+       if (!$quiet) {
+           my $path = "api2/json/nodes/$node/tasks/$upid/log";
+           my $task_log = $conn->get($path, {start => $last_line});
+
+           my $printme = '';
+           for my $li (@$task_log) {
+               if ($li->{t} eq 'no content') {
+                   next;
+               }
+               $printme .= $li->{t} . "\n";
+               $last_line = $li->{n};
+           }
+
+           if ($printme ne '') {
+               print $printme;
+           }
+       }
+
        $task_status = $conn->get($path, {});
 
        if ($task_status->{status} eq "stopped") {
            last;
        }
 
-       sleep(10);
+       sleep(2);
     }
 
     return $task_status->{exitstatus};