]> git.proxmox.com Git - pve-client.git/commitdiff
move config related code to PVE/APIClient/Config.pm
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 29 May 2018 07:33:05 +0000 (09:33 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 29 May 2018 07:33:05 +0000 (09:33 +0200)
PVE/APIClient/Commands/lxc.pm
PVE/APIClient/Config.pm

index 41ff4db4b6d812489b43891f79b542328f74c008..5e2a8206f8221271f46c49df17753cb44c92fa46 100644 (file)
@@ -2,6 +2,7 @@ package PVE::APIClient::Commands::lxc;
 
 use strict;
 use warnings;
 
 use strict;
 use warnings;
+use JSON;
 
 use PVE::Tools;
 use PVE::JSONSchema qw(get_standard_option);
 
 use PVE::Tools;
 use PVE::JSONSchema qw(get_standard_option);
@@ -10,35 +11,6 @@ use PVE::CLIHandler;
 use base qw(PVE::CLIHandler);
 use PVE::APIClient::Config;
 
 use base qw(PVE::CLIHandler);
 use PVE::APIClient::Config;
 
-my $load_remote_config = sub {
-    my ($remote) = @_;
-
-    my $conf = PVE::APIClient::Config::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;
-};
-
-my $get_remote_connection = sub {
-    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
-       });
-};
-
 __PACKAGE__->register_method ({
     name => 'enter',
     path => 'enter',
 __PACKAGE__->register_method ({
     name => 'enter',
     path => 'enter',
@@ -58,7 +30,7 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
     code => sub {
        my ($param) = @_;
 
-       my $conn = $get_remote_connection->($param->{remote});
+       my $conn = PVE::APIClient::Config::get_remote_connection($param->{remote});
        my $node = 'localhost'; # ??
 
        my $api_path = "api2/json/nodes/$node/lxc/$param->{vmid}";
        my $node = 'localhost'; # ??
 
        my $api_path = "api2/json/nodes/$node/lxc/$param->{vmid}";
index 86007d2917573c5b1f52167c23c706ecc88e1c23..e29a4fd87774ef8e9d3e9a79cef784626a893a21 100644 (file)
@@ -6,6 +6,7 @@ use JSON;
 use File::HomeDir;
 
 use PVE::Tools;
 use File::HomeDir;
 
 use PVE::Tools;
+use PVE::APIClient::LWP;
 
 sub load_config {
 
 
 sub load_config {
 
@@ -18,6 +19,35 @@ sub load_config {
     }
 
     return decode_json($conf_str);
     }
 
     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;
 
 1;