]> git.proxmox.com Git - pve-client.git/blob - PVE/APIClient/Commands/lxc.pm
use new PVE::APIClient::Config class, register_standard_option 'pveclient-remote...
[pve-client.git] / PVE / APIClient / Commands / lxc.pm
1 package PVE::APIClient::Commands::lxc;
2
3 use strict;
4 use warnings;
5
6 use PVE::Tools;
7 use PVE::JSONSchema qw(get_standard_option);
8 use PVE::CLIHandler;
9
10 use base qw(PVE::CLIHandler);
11 use PVE::APIClient::Config;
12
13 my $load_remote_config = sub {
14 my ($remote) = @_;
15
16 my $conf = PVE::APIClient::Config::load_config();
17
18 my $remote_conf = $conf->{"remote_$remote"} ||
19 die "no such remote '$remote'\n";
20
21 foreach my $opt (qw(hostname username password fingerprint)) {
22 die "missing option '$opt' (remote '$remote')" if !defined($remote_conf->{$opt});
23 }
24
25 return $remote_conf;
26 };
27
28 my $get_remote_connection = sub {
29 my ($remote) = @_;
30
31 my $conf = $load_remote_config->($remote);
32
33 return PVE::APIClient::LWP->new(
34 username => $conf->{username},
35 password => $conf->{password},
36 host => $conf->{hostname},
37 cached_fingerprints => {
38 $conf->{fingerprint} => 1
39 });
40 };
41
42 __PACKAGE__->register_method ({
43 name => 'enter',
44 path => 'enter',
45 method => 'POST',
46 description => "Enter container console.",
47 parameters => {
48 additionalProperties => 0,
49 properties => {
50 remote => get_standard_option('pveclient-remote-name'),
51 vmid => {
52 description => "The container ID",
53 type => 'string',
54 },
55 },
56 },
57 returns => { type => 'null'},
58 code => sub {
59 my ($param) = @_;
60
61 my $conn = $get_remote_connection->($param->{remote});
62 my $node = 'localhost'; # ??
63
64 my $api_path = "api2/json/nodes/$node/lxc/$param->{vmid}";
65
66 my $res = $conn->get($api_path, {});
67
68 print to_json($res, { pretty => 1, canonical => 1});
69 die "implement me";
70
71 }});
72
73 __PACKAGE__->register_method ({
74 name => 'list',
75 path => 'list',
76 method => 'GET',
77 description => "List containers.",
78 parameters => {
79 additionalProperties => 0,
80 properties => {
81 remote => get_standard_option('pveclient-remote-name'),
82 },
83 },
84 returns => { type => 'null'},
85 code => sub {
86 my ($param) = @_;
87
88 die "implement me";
89
90 }});
91
92
93 our $cmddef = {
94 enter => [ __PACKAGE__, 'enter', ['remote', 'vmid']],
95 list => [ __PACKAGE__, 'list', ['remote']],
96 };
97
98 1;