[pve-devel] applied: [PATCH pve-client] fully implement api get/set/create/delete
Dietmar Maurer
dietmar at proxmox.com
Thu Jun 14 10:31:31 CEST 2018
applied
> On June 14, 2018 at 10:20 AM Dietmar Maurer <dietmar at proxmox.com> wrote:
>
>
> Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
> ---
> PVE/APIClient/Helpers.pm | 17 +++++++++++++++++
> pveclient | 37 ++++++++++++++++++-------------------
> 2 files changed, 35 insertions(+), 19 deletions(-)
>
> diff --git a/PVE/APIClient/Helpers.pm b/PVE/APIClient/Helpers.pm
> index 1ea8a5e..d8a7fba 100644
> --- a/PVE/APIClient/Helpers.pm
> +++ b/PVE/APIClient/Helpers.pm
> @@ -43,6 +43,23 @@ $build_pve_api_path_hash = sub {
> }
> };
>
> +my $default_output_format = 'table';
> +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;
> +}
> +
> sub get_api_definition {
>
> if (!defined($pve_api_definition)) {
> diff --git a/pveclient b/pveclient
> index a7e41ef..404090f 100755
> --- a/pveclient
> +++ b/pveclient
> @@ -21,11 +21,18 @@ use PVE::APIClient::Commands::GuestStatus;
>
> use JSON;
>
> -sub call_method {
> - my ($remote, $path, $method, $param) = @_;
> +sub call_api_method {
> + my ($method, $param) = @_;
>
> + my $path = PVE::APIClient::Tools::extract_param($param, 'api_path');
> die "missing API path\n" if !defined($path);
>
> + my $remote = PVE::APIClient::Tools::extract_param($param, '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();
>
> # test if api path exists
> @@ -76,6 +83,7 @@ if (my $info =
> PVE::APIClient::Helpers::extract_path_info()) {
> $path_returns = $info->{returns};
> }
>
> +$path_properties->{format} = get_standard_option('pveclient-output-format'),
> $path_properties->{remote} = get_standard_option('pveclient-remote-name');
> $path_properties->{api_path} = {
> description => "API path.",
> @@ -86,8 +94,11 @@ $path_properties->{api_path} = {
> },
> };
>
> +
> my $format_result = sub {
> - my ($data, $format) = @_;
> + my ($data) = @_;
> +
> + my $format = PVE::APIClient::Helpers::get_output_format();
>
> return if $path_returns->{type} eq 'null';
>
> @@ -108,10 +119,7 @@ __PACKAGE__->register_method ({
> code => sub {
> my ($param) = @_;
>
> - my $path = PVE::Tools::extract_param($param, 'api_path');
> - my $remote = PVE::Tools::extract_param($param, 'remote');
> -
> - return call_method($remote, $path, 'GET', $param);
> + return call_api_method('GET', $param);
> }});
>
> __PACKAGE__->register_method ({
> @@ -127,10 +135,7 @@ __PACKAGE__->register_method ({
> code => sub {
> my ($param) = @_;
>
> - print Dumper($param);
> -
> - die "implement me";
> -
> + return call_api_method('PUT', $param);
> }});
>
> __PACKAGE__->register_method ({
> @@ -146,10 +151,7 @@ __PACKAGE__->register_method ({
> code => sub {
> my ($param) = @_;
>
> - print Dumper($param);
> -
> - die "implement me";
> -
> + return call_api_method('PUSH', $param);
> }});
>
> __PACKAGE__->register_method ({
> @@ -165,10 +167,7 @@ __PACKAGE__->register_method ({
> code => sub {
> my ($param) = @_;
>
> - print Dumper($param);
> -
> - die "implement me";
> -
> + return call_api_method('DELETE', $param);
> }});
>
>
> --
> 2.11.0
>
>
More information about the pve-devel
mailing list