]>
git.proxmox.com Git - pve-client.git/blob - PVE/APIClient/Commands/lxc.pm
1 package PVE
::APIClient
::Commands
::lxc
;
11 use base
qw(PVE::CLIHandler);
13 my $load_config = sub {
15 my $filename = home
() . '/.pveclient';
16 my $conf_str = PVE
::Tools
::file_get_contents
($filename);
18 my $filemode = (stat($filename))[2] & 07777;
19 if ($filemode != 0600) {
20 die sprintf "wrong permissions on '$filename' %04o (expected 0600)\n", $filemode;
23 return decode_json
($conf_str);
26 my $load_remote_config = sub {
29 my $conf = $load_config->();
31 my $remote_conf = $conf->{"remote_$remote"} ||
32 die "no such remote '$remote'\n";
34 foreach my $opt (qw(hostname username password fingerprint)) {
35 die "missing option '$opt' (remote '$remote')" if !defined($remote_conf->{$opt});
41 my $get_remote_connection = sub {
44 my $conf = $load_remote_config->($remote);
46 return PVE
::APIClient
::LWP-
>new(
47 username
=> $conf->{username
},
48 password
=> $conf->{password
},
49 host
=> $conf->{hostname
},
50 cached_fingerprints
=> {
51 $conf->{fingerprint
} => 1
56 __PACKAGE__-
>register_method ({
60 description
=> "Enter container console.",
62 additionalProperties
=> 0,
65 description
=> "The name of the remote.",
69 description
=> "The container ID",
74 returns
=> { type
=> 'null'},
78 my $conn = $get_remote_connection->($param->{remote
});
79 my $node = 'localhost'; # ??
81 my $api_path = "api2/json/nodes/$node/lxc/$param->{vmid}";
83 my $res = $conn->get($api_path, {});
85 print to_json
($res, { pretty
=> 1, canonical
=> 1});
90 __PACKAGE__-
>register_method ({
94 description
=> "List containers.",
96 additionalProperties
=> 0,
99 description
=> "The remote name.",
104 returns
=> { type
=> 'null'},
114 enter
=> [ __PACKAGE__
, 'enter', ['remote', 'vmid']],
115 list
=> [ __PACKAGE__
, 'list', ['remote']],