1 package PVE
::APIClient
::Commands
::remote
;
6 use PVE
::APIClient
::Helpers
;
7 use PVE
::APIClient
::JSONSchema
qw(get_standard_option);
8 use PVE
::APIClient
::Tools
qw(extract_param);
9 use PVE
::APIClient
::Config
;
11 use PVE
::APIClient
::CLIHandler
;
13 use PVE
::APIClient
::LWP
;
14 use PVE
::APIClient
::PTY
;
16 use base
qw(PVE::APIClient::CLIHandler);
19 return PVE
::APIClient
::PTY
::read_password
("Remote password: ")
22 __PACKAGE__-
>register_method ({
26 description
=> "List remotes from your config file.",
28 additionalProperties
=> 0,
30 returns
=> { type
=> 'null' },
32 my $config = PVE
::APIClient
::Config-
>load();
34 printf("%10s %10s %10s %10s %100s\n", "Name", "Host", "Port", "Username", "Fingerprint");
35 for my $name (keys %{$config->{ids
}}) {
36 my $data = $config->{ids
}->{$name};
37 next if $data->{type
} ne 'remote';
38 printf("%10s %10s %10s %10s %100s\n", $name, $data->{'host'},
39 $data->{'port'} // '-', $data->{'username'}, $data->{'fingerprint'} // '-');
45 __PACKAGE__-
>register_method ({
49 description
=> "Add a remote to your config file.",
50 parameters
=> PVE
::APIClient
::RemoteConfig-
>createSchema(1),
51 returns
=> { type
=> 'null'},
55 my $remote = $param->{name
};
57 # Note: we try to keep lock time sort, and lock later when we have all info
58 my $config = PVE
::APIClient
::Config-
>load();
60 die "Remote '$remote' already exists\n"
61 if $config->{ids
}->{$remote};
65 my $password = $param->{password
};
66 if (!defined($password)) {
67 $password = PVE
::APIClient
::PTY
::read_password
("Remote password: ");
71 username
=> $param->{username
},
72 password
=> $password,
73 host
=> $param->{host
},
74 port
=> $param->{port
} // 8006,
77 if ($param->{fingerprint
}) {
78 $setup->{cached_fingerprints
} = {
79 $param->{fingerprint
} => 1,
82 $setup->{manual_verification
} = 1;
83 $setup->{register_fingerprint_cb
} = sub {
89 my $api = PVE
::APIClient
::LWP-
>new(%$setup);
92 $param->{fingerprint
} = $last_fp if !defined($param->{fingerprint
});
94 my $plugin = PVE
::APIClient
::Config-
>lookup('remote');
98 $config = PVE
::APIClient
::Config-
>load(); # reload
100 # check again (file is locked now)
101 die "Remote '$remote' already exists\n"
102 if $config->{ids
}->{$remote};
104 my $opts = $plugin->check_config($remote, $param, 1, 1);
106 $config->{ids
}->{$remote} = $opts;
108 PVE
::APIClient
::Config-
>save($config);
111 PVE
::APIClient
::Config-
>lock_config(undef, $code);
116 __PACKAGE__-
>register_method ({
120 description
=> "Update a remote configuration.",
121 parameters
=> PVE
::APIClient
::RemoteConfig-
>updateSchema(1),
122 returns
=> { type
=> 'null'},
126 my $name = extract_param
($param, 'name');
127 my $digest = extract_param
($param, 'digest');
128 my $delete = extract_param
($param, 'delete');
131 my $config = PVE
::APIClient
::Config-
>load();
132 my $remote = PVE
::APIClient
::Config-
>lookup_remote($config, $name);
134 my $plugin = PVE
::APIClient
::Config-
>lookup('remote');
135 my $opts = $plugin->check_config($name, $param, 0, 1);
137 foreach my $k (%$opts) {
138 $remote->{$k} = $opts->{$k};
142 my $options = $plugin->private()->{options
}->{'remote'};
143 foreach my $k (PVE
::APIClient
::Tools
::APIClient
::split_list
($delete)) {
144 my $d = $options->{$k} ||
145 die "no such option '$k'\n";
146 die "unable to delete required option '$k'\n"
148 die "unable to delete fixed option '$k'\n"
150 delete $remote->{$k};
154 PVE
::APIClient
::Config-
>save($config);
157 PVE
::APIClient
::Config-
>lock_config(undef, $code);
162 __PACKAGE__-
>register_method ({
166 description
=> "Removes a remote from your config file.",
168 additionalProperties
=> 0,
170 name
=> get_standard_option
('pveclient-remote-name'),
173 returns
=> { type
=> 'null'},
178 my $config = PVE
::APIClient
::Config-
>load();
179 delete $config->{ids
}->{$param->{name
}};
180 PVE
::APIClient
::Config-
>save($config);
183 PVE
::APIClient
::Config-
>lock_config(undef, $code);
189 add
=> [ __PACKAGE__
, 'add', ['name', 'host', 'username']],
190 update
=> [ __PACKAGE__
, 'update', ['name']],
191 remove
=> [ __PACKAGE__
, 'remove', ['name']],
192 list
=> [__PACKAGE__
, 'list'],