]> git.proxmox.com Git - pve-client.git/blobdiff - PVE/APIClient/Commands/remote.pm
register standard option inside PVE::APIClient::Config
[pve-client.git] / PVE / APIClient / Commands / remote.pm
index b8b1465321064762474294d05d4e66c7fa258282..5d04e3a87cc21e73793dfe907c9e359e0f305030 100644 (file)
@@ -3,7 +3,7 @@ package PVE::APIClient::Commands::remote;
 use strict;
 use warnings;
 
-use PVE::JSONSchema qw(register_standard_option get_standard_option);
+use PVE::JSONSchema qw(get_standard_option);
 use PVE::APIClient::Config;
 
 use PVE::CLIHandler;
@@ -13,23 +13,33 @@ use PVE::PTY ();
 
 use base qw(PVE::CLIHandler);
 
-my $complete_remote_name = sub {
-
-    my $config = PVE::APIClient::Config->new();
-    return $config->remote_names;
-};
-
-register_standard_option('pveclient-remote-name', {
-    description => "The name of the remote.",
-    type => 'string',
-    pattern => qr(\w+),
-    completion => $complete_remote_name,
-});
-
 sub read_password {
    return PVE::PTY::read_password("Remote password: ")
 }
 
+__PACKAGE__->register_method ({
+    name => 'list',
+    path => 'list',
+    method => 'GET',
+    description => "List remotes from your config file.",
+    parameters => {
+       additionalProperties => 0,
+    },
+    returns => { type => 'null' },
+    code => sub {
+       my $config = PVE::APIClient::Config->new();
+       my $known_remotes = $config->remote_names;
+
+       printf("%10s %10s %10s %10s %100s\n", "Name", "Host", "Port", "Username", "Fingerprint");
+       for my $name (@$known_remotes) {
+           my $remote = $config->lookup_remote($name);
+           printf("%10s %10s %10s %10s %100s\n", $name, $remote->{'host'},
+               $remote->{'port'}, $remote->{'username'}, $remote->{'fingerprint'});
+       }
+
+       return undef;
+    }});
+
 __PACKAGE__->register_method ({
     name => 'add',
     path => 'add',
@@ -107,13 +117,17 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
-       die "implement me";
+       my $config = PVE::APIClient::Config->new();
+       $config->remove_remote($param->{name});
+       $config->save;
 
+       return undef;
     }});
 
 our $cmddef = {
     add => [ __PACKAGE__, 'add', ['name', 'host', 'username']],
     remove => [ __PACKAGE__, 'remove', ['name']],
+    list => [__PACKAGE__, 'list'],
 };
 
 1;