X-Git-Url: https://git.proxmox.com/?p=pve-client.git;a=blobdiff_plain;f=PVE%2FAPIClient%2FConfig.pm;h=e29a4fd87774ef8e9d3e9a79cef784626a893a21;hp=86007d2917573c5b1f52167c23c706ecc88e1c23;hb=aa570b3853bef5f16827df72c429c59c8ac91151;hpb=3454a319f2bbd606609971ff438cd4fe05c815d0 diff --git a/PVE/APIClient/Config.pm b/PVE/APIClient/Config.pm index 86007d2..e29a4fd 100644 --- a/PVE/APIClient/Config.pm +++ b/PVE/APIClient/Config.pm @@ -6,6 +6,7 @@ use JSON; use File::HomeDir; use PVE::Tools; +use PVE::APIClient::LWP; sub load_config { @@ -18,6 +19,35 @@ sub load_config { } return decode_json($conf_str); -}; +} + +sub load_remote_config { + my ($remote) = @_; + + my $conf = load_config(); + + my $remote_conf = $conf->{"remote_$remote"} || + die "no such remote '$remote'\n"; + + foreach my $opt (qw(hostname username password fingerprint)) { + die "missing option '$opt' (remote '$remote')" if !defined($remote_conf->{$opt}); + } + + return $remote_conf; +} + +sub get_remote_connection { + my ($remote) = @_; + + my $conf = load_remote_config($remote); + + return PVE::APIClient::LWP->new( + username => $conf->{username}, + password => $conf->{password}, + host => $conf->{hostname}, + cached_fingerprints => { + $conf->{fingerprint} => 1 + }); +} 1;