3 package PVE
::CLI
::pveclient
;
8 use lib
'/usr/share/pve-client';
12 use PVE
::JSONSchema
qw(register_standard_option get_standard_option);
15 use PVE
::APIClient
::LWP
;
16 use PVE
::APIClient
::Helpers
;
17 use PVE
::APIClient
::Commands
::config
;
18 use PVE
::APIClient
::Commands
::remote
;
19 use PVE
::APIClient
::Commands
::list
;
20 use PVE
::APIClient
::Commands
::lxc
;
21 use PVE
::APIClient
::Commands
::help
;
22 use PVE
::APIClient
::Commands
::start
;
27 my ($remote, $path, $method, $params) = @_;
29 die "missing API path\n" if !defined($path);
31 my $info = PVE
::APIClient
::Helpers
::lookup_api_method
($path, $method);
32 print Dumper
($params);
37 use base
qw(PVE::CLIHandler);
41 if ($cmd && $cmd eq 'packagedepends') {
42 # experimental code to print required perl packages
44 my $dir = Cwd
::getcwd
;
46 foreach my $k (keys %INC) {
47 my $file = abs_path
($INC{$k});
48 next if $file =~ m/^\Q$dir\E/;
49 my $res = `dpkg -S '$file'`;
50 if ($res && $res =~ m/^(\S+): $file$/) {
51 my $debian_package = $1;
52 $debian_package =~ s/:amd64$//;
53 $packages->{$debian_package} = 1;
55 die "unable to find package for '$file'\n";
58 print join("\n", sort(keys %$packages)) . "\n";
63 my $path_properties = {};
64 my $path_returns = { type
=> 'null' };
66 # dynamically update schema definition for direct API call
67 # like: pveclient api <get|set|create|delete|help> <remote> <path>
68 if (my $info = PVE
::APIClient
::Helpers
::extract_path_info
()) {
69 $path_properties = $info->{parameters
}->{properties
};
70 $path_returns = $info->{returns
};
73 $path_properties->{remote
} = get_standard_option
('pveclient-remote-name');
74 $path_properties->{api_path
} = {
75 description
=> "API path.",
78 my ($cmd, $pname, $cur, $args) = @_;
79 return PVE
::APIClient
::Helpers
::complete_api_path
($cur);
83 __PACKAGE__-
>register_method ({
84 name
=> 'pveclient_get',
85 path
=> 'pveclient_get',
87 description
=> "call API GET on <path>.",
89 additionalProperties
=> 0,
90 properties
=> $path_properties,
92 returns
=> $path_returns,
96 my $path = PVE
::Tools
::extract_param
($param, 'api_path');
97 my $remote = PVE
::Tools
::extract_param
($param, 'remote');
99 return call_method
($remote, $path, 'GET', $param);
102 __PACKAGE__-
>register_method ({
103 name
=> 'pveclient_set',
104 path
=> 'pveclient_set',
106 description
=> "call API PUT on <path>.",
108 additionalProperties
=> 0,
109 properties
=> $path_properties,
111 returns
=> $path_returns,
115 print Dumper
($param);
121 __PACKAGE__-
>register_method ({
122 name
=> 'pveclient_create',
123 path
=> 'pveclient_create',
125 description
=> "call API PUSH on <path>.",
127 additionalProperties
=> 0,
128 properties
=> $path_properties,
130 returns
=> $path_returns,
134 print Dumper
($param);
140 __PACKAGE__-
>register_method ({
141 name
=> 'pveclient_delete',
142 path
=> 'pveclient_delete',
144 description
=> "call API DELETE on <path>.",
146 additionalProperties
=> 0,
147 properties
=> $path_properties,
149 returns
=> $path_returns,
153 print Dumper
($param);
161 config
=> $PVE::APIClient
::Commands
::config
::cmddef
,
162 list
=> $PVE::APIClient
::Commands
::list
::cmddef
,
163 lxc
=> $PVE::APIClient
::Commands
::lxc
::cmddef
,
164 remote
=> $PVE::APIClient
::Commands
::remote
::cmddef
,
166 start
=> $PVE::APIClient
::Commands
::start
::cmddef
,
169 get
=> [ __PACKAGE__
, 'pveclient_get', ['remote', 'api_path']],
170 set
=> [ __PACKAGE__
, 'pveclient_set', ['remote', 'api_path']],
171 create
=> [ __PACKAGE__
, 'pveclient_create', ['remote', 'api_path']],
172 delete => [ __PACKAGE__
, 'pveclient_delete', ['remote', 'api_path']],
177 __PACKAGE__-
>run_cli_handler();