]>
git.proxmox.com Git - pve-client.git/blob - pveclient
3 package PVE
::CLI
::pveclient
;
10 use PVE
::JSONSchema
qw(register_standard_option get_standard_option);
13 use PVE
::APIClient
::LWP
;
14 use PVE
::APIClient
::Helpers
;
15 use PVE
::APIClient
::Commands
::config
;
16 use PVE
::APIClient
::Commands
::remote
;
17 use PVE
::APIClient
::Commands
::list
;
18 use PVE
::APIClient
::Commands
::lxc
;
19 use PVE
::APIClient
::Commands
::GuestStatus
;
24 my ($remote, $path, $method, $params) = @_;
26 die "missing API path\n" if !defined($path);
28 my $info = PVE
::APIClient
::Helpers
::lookup_api_method
($path, $method);
29 print Dumper
($params);
34 use base
qw(PVE::CLIHandler);
38 if ($cmd && $cmd eq 'packagedepends') {
39 # experimental code to print required perl packages
41 my $dir = Cwd
::getcwd
;
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;
52 die "unable to find package for '$file'\n";
55 print join("\n", sort(keys %$packages)) . "\n";
60 my $path_properties = {};
61 my $path_returns = { type
=> 'null' };
63 # dynamically update schema definition for direct API call
64 # like: pveclient api <get|set|create|delete|help> <remote> <path>
65 if (my $info = PVE
::APIClient
::Helpers
::extract_path_info
()) {
66 $path_properties = $info->{parameters
}->{properties
};
67 $path_returns = $info->{returns
};
70 $path_properties->{remote
} = get_standard_option
('pveclient-remote-name');
71 $path_properties->{api_path
} = {
72 description
=> "API path.",
75 my ($cmd, $pname, $cur, $args) = @_;
76 return PVE
::APIClient
::Helpers
::complete_api_path
($cur);
80 __PACKAGE__-
>register_method ({
81 name
=> 'pveclient_get',
82 path
=> 'pveclient_get',
84 description
=> "call API GET on <path>.",
86 additionalProperties
=> 0,
87 properties
=> $path_properties,
89 returns
=> $path_returns,
93 my $path = PVE
::Tools
::extract_param
($param, 'api_path');
94 my $remote = PVE
::Tools
::extract_param
($param, 'remote');
96 return call_method
($remote, $path, 'GET', $param);
99 __PACKAGE__-
>register_method ({
100 name
=> 'pveclient_set',
101 path
=> 'pveclient_set',
103 description
=> "call API PUT on <path>.",
105 additionalProperties
=> 0,
106 properties
=> $path_properties,
108 returns
=> $path_returns,
112 print Dumper
($param);
118 __PACKAGE__-
>register_method ({
119 name
=> 'pveclient_create',
120 path
=> 'pveclient_create',
122 description
=> "call API PUSH on <path>.",
124 additionalProperties
=> 0,
125 properties
=> $path_properties,
127 returns
=> $path_returns,
131 print Dumper
($param);
137 __PACKAGE__-
>register_method ({
138 name
=> 'pveclient_delete',
139 path
=> 'pveclient_delete',
141 description
=> "call API DELETE on <path>.",
143 additionalProperties
=> 0,
144 properties
=> $path_properties,
146 returns
=> $path_returns,
150 print Dumper
($param);
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
,
163 spice
=> [ 'PVE::APIClient::Commands::GuestStatus', 'spice', ['remote', 'vmid']],
164 start
=> [ 'PVE::APIClient::Commands::GuestStatus', 'start', ['remote', 'vmid']],
165 stop
=> [ 'PVE::APIClient::Commands::GuestStatus', 'stop', ['remote', 'vmid']],
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']],
176 __PACKAGE__-
>run_cli_handler();