+ code => sub {
+ 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 $res = [];
+ for my $name (keys %{$config->{ids}}) {
+ my $data = $config->{ids}->{$name};
+ next if $data->{type} ne 'remote';
+ push @$res, $data;
+ }
+
+ return $res;
+ }});
+
+__PACKAGE__->register_method ({
+ name => 'remote_add',
+ path => 'remote_add',
+ method => 'POST',
+ description => "Add a remote to your config file.",
+ parameters => PVE::APIClient::RemoteConfig->createSchema(1),
+ returns => { type => 'null'},
+ code => sub {
+ my ($param) = @_;
+
+ my $remote = $param->{name};
+
+ # Note: we try to keep lock time sort, and lock later when we have all info
+ my $config = PVE::APIClient::Config->load();
+
+ die "Remote '$remote' already exists\n"
+ if $config->{ids}->{$remote};
+
+ my $last_fp = 0;
+
+ my $password = $param->{password};
+ if (!defined($password)) {
+ $password = PVE::APIClient::PTY::read_password("Remote password: ");
+ }
+
+ my $setup = {
+ username => $param->{username},
+ password => $password,
+ host => $param->{host},
+ port => $param->{port} // 8006,
+ };
+
+ if ($param->{fingerprint}) {
+ $setup->{cached_fingerprints} = {
+ $param->{fingerprint} => 1,
+ };
+ } else {
+ $setup->{manual_verification} = 1;
+ $setup->{register_fingerprint_cb} = sub {
+ my $fp = shift @_;
+ $last_fp = $fp;
+ };
+ }
+
+ my $api = PVE::APIClient::LWP->new(%$setup);
+ $api->login();
+
+ $param->{fingerprint} = $last_fp if !defined($param->{fingerprint});
+
+ my $plugin = PVE::APIClient::Config->lookup('remote');
+
+ my $code = sub {
+
+ $config = PVE::APIClient::Config->load(); # reload
+
+ # check again (file is locked now)
+ die "Remote '$remote' already exists\n"
+ if $config->{ids}->{$remote};
+
+ my $opts = $plugin->check_config($remote, $param, 1, 1);
+
+ $config->{ids}->{$remote} = $opts;
+
+ PVE::APIClient::Config->save($config);
+ };
+
+ PVE::APIClient::Config->lock_config(undef, $code);
+
+ return undef;
+ }});
+
+__PACKAGE__->register_method ({
+ name => 'remote_set',
+ path => 'remote_set',
+ method => 'PUT',
+ description => "Update a remote configuration.",
+ parameters => PVE::APIClient::RemoteConfig->updateSchema(1),