[pve-devel] [PATCH pve-client v3 2/2] Add task log to 'lxc create'
René Jochum
r.jochum at proxmox.com
Tue Jun 19 17:46:51 CEST 2018
---
PVE/APIClient/Commands/lxc.pm | 19 +++++++++++++++++--
PVE/APIClient/Helpers.pm | 23 +++++++++++++++++++++--
2 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/PVE/APIClient/Commands/lxc.pm b/PVE/APIClient/Commands/lxc.pm
index 2309ec0..3add2dd 100644
--- a/PVE/APIClient/Commands/lxc.pm
+++ b/PVE/APIClient/Commands/lxc.pm
@@ -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;
}});
diff --git a/PVE/APIClient/Helpers.pm b/PVE/APIClient/Helpers.pm
index 30b8475..7d855ec 100644
--- a/PVE/APIClient/Helpers.pm
+++ b/PVE/APIClient/Helpers.pm
@@ -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};
--
2.11.0
More information about the pve-devel
mailing list