]> git.proxmox.com Git - pve-client.git/blobdiff - PVE/APIClient/Commands/lxc.pm
use new PVE::APIClient::Config class, register_standard_option 'pveclient-remote...
[pve-client.git] / PVE / APIClient / Commands / lxc.pm
index 469bcf11309d2a02cf25c56b41e5405466abbdeb..41ff4db4b6d812489b43891f79b542328f74c008 100644 (file)
@@ -3,9 +3,41 @@ package PVE::APIClient::Commands::lxc;
 use strict;
 use warnings;
 
+use PVE::Tools;
+use PVE::JSONSchema qw(get_standard_option);
 use PVE::CLIHandler;
 
 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',
@@ -15,6 +47,7 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
+           remote => get_standard_option('pveclient-remote-name'),
            vmid => {
                description => "The container ID",
                type => 'string',
@@ -25,6 +58,14 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
+       my $conn = $get_remote_connection->($param->{remote});
+       my $node = 'localhost'; # ??
+
+       my $api_path = "api2/json/nodes/$node/lxc/$param->{vmid}";
+
+       my $res = $conn->get($api_path, {});
+
+       print to_json($res, { pretty => 1, canonical => 1});
        die "implement me";
 
     }});
@@ -37,10 +78,7 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           remote => {
-               description => "The remote name.",
-               type => 'string',
-           },
+           remote => get_standard_option('pveclient-remote-name'),
        },
     },
     returns => { type => 'null'},
@@ -53,7 +91,7 @@ __PACKAGE__->register_method ({
 
 
 our $cmddef = {
-    enter => [ __PACKAGE__, 'enter', ['vmid']],
+    enter => [ __PACKAGE__, 'enter', ['remote', 'vmid']],
     list => [ __PACKAGE__, 'list', ['remote']],
 };