- parameters => {
- additionalProperties => 0,
- properties => {
- name => get_standard_option('pveclient-remote-name', { completion => sub {} }),
- host => {
- description => "The host, either host, host:port or https://host:port",
- type => 'string',
- },
- username => {
- description => "The username.",
- type => 'string',
- optional => 1,
- },
- },
- },
+ parameters => PVE::APIClient::RemoteConfig->createSchema(1),
+ returns => { type => 'null'},
+ code => sub {
+ my ($param) = @_;
+
+ # fixme: lock config file
+
+ my $remote = $param->{name};
+
+ 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::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 $opts = $plugin->check_config($remote, $param, 1, 1);
+ $config->{ids}->{$remote} = $opts;
+
+ PVE::APIClient::Config->save($config);
+
+ return undef;
+ }});
+
+__PACKAGE__->register_method ({
+ name => 'update',
+ path => 'update',
+ method => 'PUT',
+ description => "Update a remote configuration.",
+ parameters => PVE::APIClient::RemoteConfig->updateSchema(1),