]> git.proxmox.com Git - pve-client.git/blobdiff - pveclient
Helpers.pm: new helper configuration_directory
[pve-client.git] / pveclient
index a7e41efea3f740743d09d5741d64085e62c2ae3d..34e2aab8b1b14028e534bc0024cf8420ad529fa1 100755 (executable)
--- a/pveclient
+++ b/pveclient
@@ -9,6 +9,7 @@ use Data::Dumper;
 
 use PVE::APIClient::JSONSchema qw(register_standard_option get_standard_option);
 use PVE::APIClient::CLIHandler;
+use PVE::APIClient::PTY;
 
 use PVE::APIClient::LWP;
 use PVE::APIClient::Helpers;
@@ -21,11 +22,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
@@ -42,6 +50,11 @@ sub call_method {
 
 use base qw(PVE::APIClient::CLIHandler);
 
+sub read_password {
+   return PVE::APIClient::PTY::read_password("Remote password: ")
+}
+
+
 my $cmd = $ARGV[0];
 
 if ($cmd && $cmd eq 'packagedepends') {
@@ -76,6 +89,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,13 +100,11 @@ $path_properties->{api_path} = {
     },
 };
 
-my $format_result = sub {
-    my ($data, $format) = @_;
 
-    return if $path_returns->{type} eq 'null';
+my $format_result = sub {
+    my ($data) = @_;
 
-    # TODO: implement different output formats ($format)
-    print to_json($data, {utf8 => 1, allow_nonref => 1, canonical => 1, pretty => 1 });
+    PVE::APIClient::Helpers::print_result($data, $path_returns);
 };
 
 __PACKAGE__->register_method ({
@@ -108,10 +120,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 +136,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 +152,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 +168,7 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
-       print Dumper($param);
-
-       die "implement me";
-
+       return call_api_method('DELETE', $param);
     }});
 
 
@@ -178,9 +178,12 @@ our $cmddef = {
     lxc => $PVE::APIClient::Commands::lxc::cmddef,
     remote => $PVE::APIClient::Commands::remote::cmddef,
 
+    resume => [ 'PVE::APIClient::Commands::GuestStatus', 'resume', ['remote', 'vmid']],
+    shutdown => [ 'PVE::APIClient::Commands::GuestStatus', 'shutdown', ['remote', 'vmid']],
     spice => [ 'PVE::APIClient::Commands::GuestStatus', 'spice', ['remote', 'vmid']],
     start => [ 'PVE::APIClient::Commands::GuestStatus', 'start', ['remote', 'vmid']],
     stop => [ 'PVE::APIClient::Commands::GuestStatus', 'stop', ['remote', 'vmid']],
+    suspend => [ 'PVE::APIClient::Commands::GuestStatus', 'suspend', ['remote', 'vmid']],
 
     api => {
        get => [ __PACKAGE__, 'pveclient_get', ['remote', 'api_path'], {}, $format_result ],