]> git.proxmox.com Git - pve-client.git/blame - pveclient
use packages from PVE::APIClient
[pve-client.git] / pveclient
CommitLineData
29505e2c
DM
1#!/usr/bin/perl
2
b133a905
DM
3package PVE::CLI::pveclient;
4
29505e2c
DM
5use strict;
6use warnings;
f5fcd826 7use Cwd 'abs_path';
29505e2c
DM
8use Data::Dumper;
9
c9138c03
DM
10use PVE::APIClient::JSONSchema qw(register_standard_option get_standard_option);
11use PVE::APIClient::CLIHandler;
565bbc73 12
29505e2c
DM
13use PVE::APIClient::LWP;
14use PVE::APIClient::Helpers;
a6dab5b8 15use PVE::APIClient::Commands::config;
565bbc73 16use PVE::APIClient::Commands::remote;
5b090843 17use PVE::APIClient::Commands::list;
adf285bf 18use PVE::APIClient::Commands::lxc;
89335fb1 19use PVE::APIClient::Commands::GuestStatus;
565bbc73 20
29505e2c
DM
21use JSON;
22
29505e2c 23sub call_method {
b133a905 24 my ($remote, $path, $method, $params) = @_;
29505e2c
DM
25
26 die "missing API path\n" if !defined($path);
27
28 my $info = PVE::APIClient::Helpers::lookup_api_method($path, $method);
b133a905 29 print Dumper($params);
29505e2c
DM
30
31 die "implement me";
32}
33
c9138c03 34use base qw(PVE::APIClient::CLIHandler);
3a1bc22f 35
b133a905 36my $cmd = $ARGV[0];
dce6ecbc 37
b133a905 38if ($cmd && $cmd eq 'packagedepends') {
f5fcd826
DM
39 # experimental code to print required perl packages
40 my $packages = {};
41 my $dir = Cwd::getcwd;
42
43 foreach my $k (keys %INC) {
44 my $file = abs_path($INC{$k});
45 next if $file =~ m/^\Q$dir\E/;
46 my $res = `dpkg -S '$file'`;
47 if ($res && $res =~ m/^(\S+): $file$/) {
48 my $debian_package = $1;
49 $debian_package =~ s/:amd64$//;
50 $packages->{$debian_package} = 1;
51 } else {
52 die "unable to find package for '$file'\n";
53 }
54 }
55 print join("\n", sort(keys %$packages)) . "\n";
b133a905
DM
56
57 exit(0);
58}
59
60my $path_properties = {};
61my $path_returns = { type => 'null' };
62
63# dynamically update schema definition for direct API call
64# like: pveclient api <get|set|create|delete|help> <remote> <path>
65if (my $info = PVE::APIClient::Helpers::extract_path_info()) {
66 $path_properties = $info->{parameters}->{properties};
67 $path_returns = $info->{returns};
29505e2c
DM
68}
69
b133a905
DM
70$path_properties->{remote} = get_standard_option('pveclient-remote-name');
71$path_properties->{api_path} = {
72 description => "API path.",
73 type => 'string',
74 completion => sub {
75 my ($cmd, $pname, $cur, $args) = @_;
76 return PVE::APIClient::Helpers::complete_api_path($cur);
77 },
78};
79
80__PACKAGE__->register_method ({
81 name => 'pveclient_get',
82 path => 'pveclient_get',
83 method => 'GET',
84 description => "call API GET on <path>.",
85 parameters => {
86 additionalProperties => 0,
87 properties => $path_properties,
88 },
89 returns => $path_returns,
90 code => sub {
91 my ($param) = @_;
92
93 my $path = PVE::Tools::extract_param($param, 'api_path');
94 my $remote = PVE::Tools::extract_param($param, 'remote');
95
96 return call_method($remote, $path, 'GET', $param);
97 }});
98
99__PACKAGE__->register_method ({
100 name => 'pveclient_set',
101 path => 'pveclient_set',
102 method => 'PUT',
103 description => "call API PUT on <path>.",
104 parameters => {
105 additionalProperties => 0,
106 properties => $path_properties,
107 },
108 returns => $path_returns,
109 code => sub {
110 my ($param) = @_;
111
112 print Dumper($param);
113
114 die "implement me";
115
116 }});
117
118__PACKAGE__->register_method ({
119 name => 'pveclient_create',
120 path => 'pveclient_create',
121 method => 'PUSH',
122 description => "call API PUSH on <path>.",
123 parameters => {
124 additionalProperties => 0,
125 properties => $path_properties,
126 },
127 returns => $path_returns,
128 code => sub {
129 my ($param) = @_;
130
131 print Dumper($param);
132
133 die "implement me";
134
135 }});
136
137__PACKAGE__->register_method ({
138 name => 'pveclient_delete',
139 path => 'pveclient_delete',
140 method => 'DELETE',
141 description => "call API DELETE on <path>.",
142 parameters => {
143 additionalProperties => 0,
144 properties => $path_properties,
145 },
146 returns => $path_returns,
147 code => sub {
148 my ($param) = @_;
149
150 print Dumper($param);
151
152 die "implement me";
153
154 }});
155
156
157our $cmddef = {
158 config => $PVE::APIClient::Commands::config::cmddef,
159 list => $PVE::APIClient::Commands::list::cmddef,
160 lxc => $PVE::APIClient::Commands::lxc::cmddef,
161 remote => $PVE::APIClient::Commands::remote::cmddef,
4cedebf6
RJ
162
163 spice => [ 'PVE::APIClient::Commands::GuestStatus', 'spice', ['remote', 'vmid']],
89335fb1
DM
164 start => [ 'PVE::APIClient::Commands::GuestStatus', 'start', ['remote', 'vmid']],
165 stop => [ 'PVE::APIClient::Commands::GuestStatus', 'stop', ['remote', 'vmid']],
b133a905
DM
166
167 api => {
168 get => [ __PACKAGE__, 'pveclient_get', ['remote', 'api_path']],
169 set => [ __PACKAGE__, 'pveclient_set', ['remote', 'api_path']],
170 create => [ __PACKAGE__, 'pveclient_create', ['remote', 'api_path']],
171 delete => [ __PACKAGE__, 'pveclient_delete', ['remote', 'api_path']],
172 }
173};
174
175
176__PACKAGE__->run_cli_handler();