mirror of
https://git.proxmox.com/git/pve-client
synced 2025-10-04 20:37:13 +00:00
use new features from pve-common
This commit is contained in:
parent
874acd772a
commit
59d3653b91
@ -9,6 +9,7 @@ use PVE::APIClient::JSONSchema qw(get_standard_option);
|
|||||||
use PVE::APIClient::Tools qw(extract_param);
|
use PVE::APIClient::Tools qw(extract_param);
|
||||||
use PVE::APIClient::Config;
|
use PVE::APIClient::Config;
|
||||||
|
|
||||||
|
use PVE::APIClient::CLIFormatter;
|
||||||
use PVE::APIClient::CLIHandler;
|
use PVE::APIClient::CLIHandler;
|
||||||
|
|
||||||
use base qw(PVE::APIClient::CLIHandler);
|
use base qw(PVE::APIClient::CLIHandler);
|
||||||
@ -23,6 +24,7 @@ __PACKAGE__->register_method ({
|
|||||||
description => "Dump default configuration.",
|
description => "Dump default configuration.",
|
||||||
parameters => {
|
parameters => {
|
||||||
additionalProperties => 0,
|
additionalProperties => 0,
|
||||||
|
properties => {},
|
||||||
},
|
},
|
||||||
returns => {
|
returns => {
|
||||||
type => 'object',
|
type => 'object',
|
||||||
@ -90,7 +92,13 @@ __PACKAGE__->register_method ({
|
|||||||
|
|
||||||
our $cmddef = {
|
our $cmddef = {
|
||||||
set => [ __PACKAGE__, 'set',],
|
set => [ __PACKAGE__, 'set',],
|
||||||
list => [__PACKAGE__, 'list', undef, undef, sub { PVE::APIClient::Helpers::print_result(@_);}],
|
list => [__PACKAGE__, 'list', undef, undef,
|
||||||
|
sub {
|
||||||
|
my ($data, $schema, $options) = @_;
|
||||||
|
|
||||||
|
PVE::APIClient::CLIFormatter::print_api_result($data, $schema, undef, $options);
|
||||||
|
}
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -30,7 +30,6 @@ __PACKAGE__->register_method ({
|
|||||||
additionalProperties => 0,
|
additionalProperties => 0,
|
||||||
properties => {
|
properties => {
|
||||||
remote => get_standard_option('pveclient-remote-name'),
|
remote => get_standard_option('pveclient-remote-name'),
|
||||||
'format' => get_standard_option('pve-output-format'),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
returns => {
|
returns => {
|
||||||
@ -43,9 +42,6 @@ __PACKAGE__->register_method ({
|
|||||||
code => sub {
|
code => sub {
|
||||||
my ($param) = @_;
|
my ($param) = @_;
|
||||||
|
|
||||||
my $format = PVE::APIClient::Tools::extract_param($param, 'format');
|
|
||||||
PVE::APIClient::Helpers::set_output_format($format);
|
|
||||||
|
|
||||||
my $config = PVE::APIClient::Config->load();
|
my $config = PVE::APIClient::Config->load();
|
||||||
my $conn = PVE::APIClient::Config->remote_conn($config, $param->{remote});
|
my $conn = PVE::APIClient::Config->remote_conn($config, $param->{remote});
|
||||||
|
|
||||||
@ -54,7 +50,8 @@ __PACKAGE__->register_method ({
|
|||||||
|
|
||||||
|
|
||||||
our $cmddef = [ __PACKAGE__, 'list', ['remote'], {}, sub {
|
our $cmddef = [ __PACKAGE__, 'list', ['remote'], {}, sub {
|
||||||
PVE::APIClient::Helpers::print_ordered_result($list_returns_properties, @_);
|
my ($data, $schema, $options) = @_;
|
||||||
|
PVE::APIClient::Helpers::print_ordered_result($list_returns_properties, $data, $schema, $options);
|
||||||
}];
|
}];
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -35,9 +35,7 @@ __PACKAGE__->register_method ({
|
|||||||
description => "List remotes from your config file.",
|
description => "List remotes from your config file.",
|
||||||
parameters => {
|
parameters => {
|
||||||
additionalProperties => 0,
|
additionalProperties => 0,
|
||||||
properties => {
|
properties => {},
|
||||||
'format' => get_standard_option('pve-output-format'),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
returns => {
|
returns => {
|
||||||
type => 'array',
|
type => 'array',
|
||||||
@ -49,9 +47,6 @@ __PACKAGE__->register_method ({
|
|||||||
code => sub {
|
code => sub {
|
||||||
my ($param) = @_;
|
my ($param) = @_;
|
||||||
|
|
||||||
my $format = PVE::APIClient::Tools::extract_param($param, 'format');
|
|
||||||
PVE::APIClient::Helpers::set_output_format($format);
|
|
||||||
|
|
||||||
my $config = PVE::APIClient::Config->load();
|
my $config = PVE::APIClient::Config->load();
|
||||||
|
|
||||||
my $res = [];
|
my $res = [];
|
||||||
@ -212,7 +207,8 @@ our $cmddef = {
|
|||||||
set => [ __PACKAGE__, 'remote_set', ['name']],
|
set => [ __PACKAGE__, 'remote_set', ['name']],
|
||||||
delete => [ __PACKAGE__, 'remote_delete', ['name']],
|
delete => [ __PACKAGE__, 'remote_delete', ['name']],
|
||||||
list => [__PACKAGE__, 'remote_list', undef, {}, sub {
|
list => [__PACKAGE__, 'remote_list', undef, {}, sub {
|
||||||
PVE::APIClient::Helpers::print_ordered_result($remote_list_returns_properties, @_);
|
my ($data, $schema, $options) = @_;
|
||||||
|
PVE::APIClient::Helpers::print_ordered_result($remote_list_returns_properties, $data, $schema, $options);
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,23 +27,6 @@ our $method_map = {
|
|||||||
delete => 'DELETE',
|
delete => 'DELETE',
|
||||||
};
|
};
|
||||||
|
|
||||||
my $default_output_format = 'text';
|
|
||||||
my $client_output_format = $default_output_format;
|
|
||||||
|
|
||||||
sub set_output_format {
|
|
||||||
my ($format) = @_;
|
|
||||||
|
|
||||||
if (!defined($format)) {
|
|
||||||
$client_output_format = $default_output_format;
|
|
||||||
} else {
|
|
||||||
$client_output_format = $format;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub get_output_format {
|
|
||||||
return $client_output_format;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $__real_remove_formats; $__real_remove_formats = sub {
|
my $__real_remove_formats; $__real_remove_formats = sub {
|
||||||
my ($properties) = @_;
|
my ($properties) = @_;
|
||||||
|
|
||||||
@ -405,23 +388,12 @@ sub extract_even_elements {
|
|||||||
return [ grep { ($ind++ % 2) == 0 } @$list ];
|
return [ grep { ($ind++ % 2) == 0 } @$list ];
|
||||||
}
|
}
|
||||||
|
|
||||||
sub print_result {
|
|
||||||
my ($data, $result_schema, $param_order) = @_;
|
|
||||||
|
|
||||||
my $options = {};
|
|
||||||
PVE::APIClient::CLIFormatter::query_terminal_options($options);
|
|
||||||
|
|
||||||
my $format = get_output_format();
|
|
||||||
PVE::APIClient::CLIFormatter::print_api_result(
|
|
||||||
$format, $data, $result_schema, $param_order, $options);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub print_ordered_result {
|
sub print_ordered_result {
|
||||||
my ($property_list, $data, $result_schema) = @_;
|
my ($property_list, $data, $result_schema, $options) = @_;
|
||||||
|
|
||||||
my $param_order = extract_even_elements($property_list);
|
my $param_order = extract_even_elements($property_list);
|
||||||
|
|
||||||
print_result($data, $result_schema, $param_order);
|
PVE::APIClient::CLIFormatter::print_api_result($data, $result_schema, $param_order, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
31
pveclient
31
pveclient
@ -24,7 +24,7 @@ use PVE::APIClient::Commands::GuestStatus;
|
|||||||
use JSON;
|
use JSON;
|
||||||
|
|
||||||
sub call_api_method {
|
sub call_api_method {
|
||||||
my ($method, $param) = @_;
|
my ($method, $param, $options) = @_;
|
||||||
|
|
||||||
my $path = PVE::APIClient::Tools::extract_param($param, 'api_path');
|
my $path = PVE::APIClient::Tools::extract_param($param, 'api_path');
|
||||||
die "missing API path\n" if !defined($path);
|
die "missing API path\n" if !defined($path);
|
||||||
@ -32,9 +32,6 @@ sub call_api_method {
|
|||||||
my $remote = PVE::APIClient::Tools::extract_param($param, 'remote');
|
my $remote = PVE::APIClient::Tools::extract_param($param, 'remote');
|
||||||
die "missing remote\n" if !defined($remote);
|
die "missing remote\n" if !defined($remote);
|
||||||
|
|
||||||
my $format = PVE::APIClient::Tools::extract_param($param, 'format');
|
|
||||||
PVE::APIClient::Helpers::set_output_format($format);
|
|
||||||
|
|
||||||
my $config = PVE::APIClient::Config->load();
|
my $config = PVE::APIClient::Config->load();
|
||||||
|
|
||||||
my $uri_param = {};
|
my $uri_param = {};
|
||||||
@ -103,18 +100,14 @@ if (my $info = PVE::APIClient::Helpers::extract_path_info($uri_param)) {
|
|||||||
$path_returns = $info->{returns};
|
$path_returns = $info->{returns};
|
||||||
}
|
}
|
||||||
|
|
||||||
$path_properties->{format} = get_standard_option('pve-output-format'),
|
|
||||||
$path_properties->{remote} = get_standard_option('pveclient-remote-name');
|
$path_properties->{remote} = get_standard_option('pveclient-remote-name');
|
||||||
$path_properties->{api_path} = $api_path_property;
|
$path_properties->{api_path} = $api_path_property;
|
||||||
|
|
||||||
my $format_result = sub {
|
my $format_result = sub {
|
||||||
my ($data) = @_;
|
my ($data, $schema, $options) = @_;
|
||||||
|
|
||||||
my $format = PVE::APIClient::Helpers::get_output_format();
|
# NOTE; we need to use $path_returns instead of $schema
|
||||||
|
PVE::APIClient::CLIFormatter::print_api_result($data, $path_returns, undef, $options);
|
||||||
my $options = PVE::APIClient::CLIFormatter::query_terminal_options({});
|
|
||||||
|
|
||||||
PVE::APIClient::CLIFormatter::print_api_result($format, $data, $path_returns, undef, $options);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
__PACKAGE__->register_method ({
|
__PACKAGE__->register_method ({
|
||||||
@ -128,9 +121,9 @@ __PACKAGE__->register_method ({
|
|||||||
},
|
},
|
||||||
returns => $path_returns,
|
returns => $path_returns,
|
||||||
code => sub {
|
code => sub {
|
||||||
my ($param) = @_;
|
my ($param, $options) = @_;
|
||||||
|
|
||||||
return call_api_method('GET', $param);
|
return call_api_method('GET', $param, $options);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
__PACKAGE__->register_method ({
|
__PACKAGE__->register_method ({
|
||||||
@ -144,9 +137,9 @@ __PACKAGE__->register_method ({
|
|||||||
},
|
},
|
||||||
returns => $path_returns,
|
returns => $path_returns,
|
||||||
code => sub {
|
code => sub {
|
||||||
my ($param) = @_;
|
my ($param, $options) = @_;
|
||||||
|
|
||||||
return call_api_method('PUT', $param);
|
return call_api_method('PUT', $param, $options);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
__PACKAGE__->register_method ({
|
__PACKAGE__->register_method ({
|
||||||
@ -160,9 +153,9 @@ __PACKAGE__->register_method ({
|
|||||||
},
|
},
|
||||||
returns => $path_returns,
|
returns => $path_returns,
|
||||||
code => sub {
|
code => sub {
|
||||||
my ($param) = @_;
|
my ($param, $options) = @_;
|
||||||
|
|
||||||
return call_api_method('PUSH', $param);
|
return call_api_method('PUSH', $param, $options);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
__PACKAGE__->register_method ({
|
__PACKAGE__->register_method ({
|
||||||
@ -176,9 +169,9 @@ __PACKAGE__->register_method ({
|
|||||||
},
|
},
|
||||||
returns => $path_returns,
|
returns => $path_returns,
|
||||||
code => sub {
|
code => sub {
|
||||||
my ($param) = @_;
|
my ($param, $options) = @_;
|
||||||
|
|
||||||
return call_api_method('DELETE', $param);
|
return call_api_method('DELETE', $param, $options);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
__PACKAGE__->register_method ({
|
__PACKAGE__->register_method ({
|
||||||
|
Loading…
Reference in New Issue
Block a user