# TODO: implement different output formats ($format)
if ($format eq 'json') {
- print to_json($data, {utf8 => 1, allow_nonref => 1, canonical => 1, pretty => 1 });
+ print to_json($data, {utf8 => 1, allow_nonref => 1, canonical => 1, pretty => 1 });
} elsif ($format eq 'text') {
- my $type = $result_schema->{type};
- if ($type eq 'object') {
- die "implement me";
- } elsif ($type eq 'array') {
- my $item_type = $result_schema->{items}->{type};
- if ($item_type eq 'object') {
- die "implement me";
- } elsif ($item_type eq 'array') {
- die "implement me";
- } else {
- foreach my $el (@$data) {
- print "$el\n"
- }
- }
- } else {
- print "$data\n";
- }
+ my $type = $result_schema->{type};
+ if ($type eq 'object') {
+ die "implement me";
+ } elsif ($type eq 'array') {
+ my $item_type = $result_schema->{items}->{type};
+ if ($item_type eq 'object') {
+ die "implement me";
+ } elsif ($item_type eq 'array') {
+ die "implement me";
+ } else {
+ foreach my $el (@$data) {
+ print "$el\n"
+ }
+ }
+ } else {
+ print "$data\n";
+ }
} else {
- die "internal error: unknown output format"; # should not happen
+ die "internal error: unknown output format"; # should not happen
}
}
-
my $__real_remove_formats; $__real_remove_formats = sub {
my ($properties) = @_;
my $stack = [ grep { length($_) > 0 } split('\/+' , $path)]; # skip empty fragments
- my $child = $map_path_to_info->(get_api_definition(), $stack, $uri_param);
+ my $api = get_api_definition();
+
+ my $child = scalar(@$stack) ? $map_path_to_info->($api->{children}, $stack, $uri_param) : $api;
if (!($child && $child->{info} && $child->{info}->{$method})) {
return undef if $noerr;
&$print_result(@option_list);
}
+sub merge_api_definition_properties {
+ my ($path, $method, $properties) = @_;
+
+ my $info = PVE::APIClient::Helpers::find_method_info($path, $method);
+
+ return { %{$info->{parameters}->{properties}}, %$properties };
+}
+
sub complete_api_path {
my ($text) = @_;
- get_api_definition(); # make sure API data is loaded
+ my $api = get_api_definition(); # make sure API data is loaded
$text =~ s!^/!!;
my $info;
if (!defined($dir)) {
$dir = '';
- $info = { children => $pve_api_definition };
+ $info = $api;
} else {
my $stack = [ grep { length($_) > 0 } split('\/+' , $dir)]; # skip empty fragments
- $info = $map_path_to_info->($pve_api_definition, $stack, {});
+ $info = $map_path_to_info->($api->{children}, $stack, {});
}
my $res = [];
}
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);
+ }
+
+ if ($task_status->{exitstatus} ne "OK") {
+ die $task_status->{exitstatus};
}
return $task_status->{exitstatus};