]>
git.proxmox.com Git - pve-client.git/blob - pveclient
3 package PVE
::CLI
::pveclient
;
10 use PVE
::APIClient
::JSONSchema
qw(register_standard_option get_standard_option);
11 use PVE
::APIClient
::CLIHandler
;
12 use PVE
::APIClient
::PTY
;
14 use PVE
::APIClient
::LWP
;
15 use PVE
::APIClient
::Helpers
;
16 use PVE
::APIClient
::Config
;
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
::GuestStatus
;
26 my ($method, $param) = @_;
28 my $path = PVE
::APIClient
::Tools
::extract_param
($param, 'api_path');
29 die "missing API path\n" if !defined($path);
31 my $remote = PVE
::APIClient
::Tools
::extract_param
($param, 'remote');
32 die "missing remote\n" if !defined($remote);
34 my $format = PVE
::APIClient
::Tools
::extract_param
($param, 'format');
35 PVE
::APIClient
::Helpers
::set_output_format
($format);
37 my $config = PVE
::APIClient
::Config-
>load();
40 my $info = PVE
::APIClient
::Helpers
::find_method_info
($path, $method, $uri_param);
42 my $conn = PVE
::APIClient
::Config-
>remote_conn($config, $remote);
44 my $res = $conn->call($method, "api2/json/$path", $param);
45 die "undefined result" if !defined($res);
46 die "undefined result data" if !exists($res->{data
});
51 use base
qw(PVE::APIClient::CLIHandler);
54 return PVE
::APIClient
::PTY
::read_password
("Remote password: ")
60 if ($cmd && $cmd eq 'packagedepends') {
61 # experimental code to print required perl packages
63 my $dir = Cwd
::getcwd
;
65 foreach my $k (keys %INC) {
66 my $file = abs_path
($INC{$k});
67 next if $file =~ m/^\Q$dir\E/;
68 my $res = `dpkg -S '$file'`;
69 if ($res && $res =~ m/^(\S+): $file$/) {
70 my $debian_package = $1;
71 $debian_package =~ s/:amd64$//;
72 $packages->{$debian_package} = 1;
74 die "unable to find package for '$file'\n";
77 print join("\n", sort(keys %$packages)) . "\n";
82 my $path_properties = {};
83 my $path_returns = { type
=> 'null' };
85 # dynamically update schema definition for direct API call
86 # like: pveclient api <get|set|create|delete|help> <remote> <path>
88 if (my $info = PVE
::APIClient
::Helpers
::extract_path_info
($uri_param)) {
89 foreach my $key (keys %{$info->{parameters
}->{properties
}}) {
90 next if defined($uri_param->{$key});
91 $path_properties->{$key} = $info->{parameters
}->{properties
}->{$key};
93 $path_returns = $info->{returns
};
96 $path_properties->{format
} = get_standard_option
('pveclient-output-format'),
97 $path_properties->{remote
} = get_standard_option
('pveclient-remote-name');
98 $path_properties->{api_path
} = {
99 description
=> "API path.",
102 my ($cmd, $pname, $cur, $args) = @_;
103 return PVE
::APIClient
::Helpers
::complete_api_path
($cur);
108 my $format_result = sub {
111 PVE
::APIClient
::Helpers
::print_result
($data, $path_returns);
114 __PACKAGE__-
>register_method ({
115 name
=> 'pveclient_get',
116 path
=> 'pveclient_get',
118 description
=> "call API GET on <path>.",
120 additionalProperties
=> 0,
121 properties
=> $path_properties,
123 returns
=> $path_returns,
127 return call_api_method
('GET', $param);
130 __PACKAGE__-
>register_method ({
131 name
=> 'pveclient_set',
132 path
=> 'pveclient_set',
134 description
=> "call API PUT on <path>.",
136 additionalProperties
=> 0,
137 properties
=> $path_properties,
139 returns
=> $path_returns,
143 return call_api_method
('PUT', $param);
146 __PACKAGE__-
>register_method ({
147 name
=> 'pveclient_create',
148 path
=> 'pveclient_create',
150 description
=> "call API PUSH on <path>.",
152 additionalProperties
=> 0,
153 properties
=> $path_properties,
155 returns
=> $path_returns,
159 return call_api_method
('PUSH', $param);
162 __PACKAGE__-
>register_method ({
163 name
=> 'pveclient_delete',
164 path
=> 'pveclient_delete',
166 description
=> "call API DELETE on <path>.",
168 additionalProperties
=> 0,
169 properties
=> $path_properties,
171 returns
=> $path_returns,
175 return call_api_method
('DELETE', $param);
180 config
=> $PVE::APIClient
::Commands
::config
::cmddef
,
181 list
=> $PVE::APIClient
::Commands
::list
::cmddef
,
182 lxc
=> $PVE::APIClient
::Commands
::lxc
::cmddef
,
183 remote
=> $PVE::APIClient
::Commands
::remote
::cmddef
,
185 resume
=> [ 'PVE::APIClient::Commands::GuestStatus', 'resume', ['remote', 'vmid']],
186 shutdown => [ 'PVE::APIClient::Commands::GuestStatus', 'shutdown', ['remote', 'vmid']],
187 spice
=> [ 'PVE::APIClient::Commands::GuestStatus', 'spice', ['remote', 'vmid']],
188 start
=> [ 'PVE::APIClient::Commands::GuestStatus', 'start', ['remote', 'vmid']],
189 stop
=> [ 'PVE::APIClient::Commands::GuestStatus', 'stop', ['remote', 'vmid']],
190 suspend
=> [ 'PVE::APIClient::Commands::GuestStatus', 'suspend', ['remote', 'vmid']],
193 get
=> [ __PACKAGE__
, 'pveclient_get', ['remote', 'api_path'], {}, $format_result ],
194 set
=> [ __PACKAGE__
, 'pveclient_set', ['remote', 'api_path'], {}, $format_result ],
195 create
=> [ __PACKAGE__
, 'pveclient_create', ['remote', 'api_path'], {}, $format_result ],
196 delete => [ __PACKAGE__
, 'pveclient_delete', ['remote', 'api_path'], {}, $format_result ],
201 __PACKAGE__-
>run_cli_handler();