]>
Commit | Line | Data |
---|---|---|
f3e76e36 DM |
1 | package PVE::CLI::qm; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | # Note: disable '+' prefix for Getopt::Long (for resize command) | |
7 | use Getopt::Long qw(:config no_getopt_compat); | |
8 | ||
9 | use Fcntl ':flock'; | |
10 | use File::Path; | |
f3e76e36 | 11 | use IO::Select; |
7c2d9b40 TL |
12 | use IO::Socket::UNIX; |
13 | use JSON; | |
5f1dc9af | 14 | use POSIX qw(strftime); |
7c2d9b40 TL |
15 | use Term::ReadLine; |
16 | use URI::Escape; | |
f3e76e36 | 17 | |
192bbfda | 18 | use PVE::APIClient::LWP; |
f3e76e36 | 19 | use PVE::Cluster; |
520884de | 20 | use PVE::Exception qw(raise_param_exc); |
9e784b11 | 21 | use PVE::GuestHelpers; |
7c2d9b40 TL |
22 | use PVE::INotify; |
23 | use PVE::JSONSchema qw(get_standard_option); | |
24 | use PVE::Network; | |
25 | use PVE::RPCEnvironment; | |
26 | use PVE::SafeSyslog; | |
27 | use PVE::Tools qw(extract_param); | |
28 | ||
29 | use PVE::API2::Qemu::Agent; | |
30 | use PVE::API2::Qemu; | |
0a13e08e | 31 | use PVE::QemuConfig; |
e0fd2b2f | 32 | use PVE::QemuServer::Drive; |
d036e418 | 33 | use PVE::QemuServer::Helpers; |
7c2d9b40 | 34 | use PVE::QemuServer::Agent qw(agent_available); |
8653feeb | 35 | use PVE::QemuServer::ImportDisk; |
0a13e08e | 36 | use PVE::QemuServer::Monitor qw(mon_cmd); |
7cd9f6d7 | 37 | use PVE::QemuServer::OVF; |
7c2d9b40 | 38 | use PVE::QemuServer; |
f3e76e36 DM |
39 | |
40 | use PVE::CLIHandler; | |
f3e76e36 DM |
41 | use base qw(PVE::CLIHandler); |
42 | ||
43 | my $upid_exit = sub { | |
44 | my $upid = shift; | |
45 | my $status = PVE::Tools::upid_read_status($upid); | |
831ad442 | 46 | exit(PVE::Tools::upid_status_is_error($status) ? -1 : 0); |
f3e76e36 DM |
47 | }; |
48 | ||
49 | my $nodename = PVE::INotify::nodename(); | |
10ff4fe7 | 50 | my %node = (node => $nodename); |
f3e76e36 | 51 | |
5e4035c7 DM |
52 | sub setup_environment { |
53 | PVE::RPCEnvironment->setup_default_cli_env(); | |
54 | } | |
55 | ||
f3e76e36 DM |
56 | sub run_vnc_proxy { |
57 | my ($path) = @_; | |
58 | ||
59 | my $c; | |
60 | while ( ++$c < 10 && !-e $path ) { sleep(1); } | |
61 | ||
62 | my $s = IO::Socket::UNIX->new(Peer => $path, Timeout => 120); | |
63 | ||
64 | die "unable to connect to socket '$path' - $!" if !$s; | |
65 | ||
f7d1505b | 66 | my $select = IO::Select->new(); |
f3e76e36 DM |
67 | |
68 | $select->add(\*STDIN); | |
69 | $select->add($s); | |
70 | ||
71 | my $timeout = 60*15; # 15 minutes | |
72 | ||
73 | my @handles; | |
74 | while ($select->count && | |
75 | scalar(@handles = $select->can_read ($timeout))) { | |
76 | foreach my $h (@handles) { | |
77 | my $buf; | |
78 | my $n = $h->sysread($buf, 4096); | |
79 | ||
80 | if ($h == \*STDIN) { | |
81 | if ($n) { | |
82 | syswrite($s, $buf); | |
83 | } else { | |
84 | exit(0); | |
85 | } | |
86 | } elsif ($h == $s) { | |
87 | if ($n) { | |
88 | syswrite(\*STDOUT, $buf); | |
89 | } else { | |
90 | exit(0); | |
91 | } | |
92 | } | |
93 | } | |
94 | } | |
95 | exit(0); | |
96 | } | |
97 | ||
81fff836 DC |
98 | sub print_recursive_hash { |
99 | my ($prefix, $hash, $key) = @_; | |
100 | ||
101 | if (ref($hash) eq 'HASH') { | |
102 | if (defined($key)) { | |
103 | print "$prefix$key:\n"; | |
104 | } | |
7f0285e1 | 105 | for my $itemkey (sort keys %$hash) { |
81fff836 DC |
106 | print_recursive_hash("\t$prefix", $hash->{$itemkey}, $itemkey); |
107 | } | |
108 | } elsif (ref($hash) eq 'ARRAY') { | |
109 | if (defined($key)) { | |
110 | print "$prefix$key:\n"; | |
111 | } | |
7f0285e1 | 112 | for my $item (@$hash) { |
81fff836 DC |
113 | print_recursive_hash("\t$prefix", $item); |
114 | } | |
6891fd70 | 115 | } elsif ((!ref($hash) && defined($hash)) || ref($hash) eq 'JSON::PP::Boolean') { |
81fff836 DC |
116 | if (defined($key)) { |
117 | print "$prefix$key: $hash\n"; | |
118 | } else { | |
119 | print "$prefix$hash\n"; | |
120 | } | |
121 | } | |
122 | } | |
123 | ||
f3e76e36 DM |
124 | __PACKAGE__->register_method ({ |
125 | name => 'showcmd', | |
126 | path => 'showcmd', | |
127 | method => 'GET', | |
128 | description => "Show command line which is used to start the VM (debug info).", | |
129 | parameters => { | |
130 | additionalProperties => 0, | |
131 | properties => { | |
335af808 | 132 | vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }), |
16a01738 TL |
133 | pretty => { |
134 | description => "Puts each option on a new line to enhance human readability", | |
135 | type => 'boolean', | |
136 | optional => 1, | |
137 | default => 0, | |
b14477e7 RV |
138 | }, |
139 | snapshot => get_standard_option('pve-snapshot-name', { | |
140 | description => "Fetch config values from given snapshot.", | |
141 | optional => 1, | |
142 | completion => sub { | |
143 | my ($cmd, $pname, $cur, $args) = @_; | |
144 | PVE::QemuConfig->snapshot_list($args->[0]); | |
145 | } | |
146 | }), | |
f3e76e36 DM |
147 | }, |
148 | }, | |
149 | returns => { type => 'null'}, | |
150 | code => sub { | |
151 | my ($param) = @_; | |
152 | ||
153 | my $storecfg = PVE::Storage::config(); | |
b14477e7 | 154 | my $cmdline = PVE::QemuServer::vm_commandline($storecfg, $param->{vmid}, $param->{snapshot}); |
16a01738 | 155 | |
108899b4 | 156 | $cmdline =~ s/ -/ \\\n -/g if $param->{pretty}; |
16a01738 TL |
157 | |
158 | print "$cmdline\n"; | |
f3e76e36 | 159 | |
d1c1af4b | 160 | return; |
f3e76e36 DM |
161 | }}); |
162 | ||
192bbfda FG |
163 | |
164 | __PACKAGE__->register_method({ | |
165 | name => 'remote_migrate_vm', | |
166 | path => 'remote_migrate_vm', | |
167 | method => 'POST', | |
168 | description => "Migrate virtual machine to a remote cluster. Creates a new migration task. EXPERIMENTAL feature!", | |
169 | permissions => { | |
170 | check => ['perm', '/vms/{vmid}', [ 'VM.Migrate' ]], | |
171 | }, | |
172 | parameters => { | |
173 | additionalProperties => 0, | |
174 | properties => { | |
175 | node => get_standard_option('pve-node'), | |
176 | vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }), | |
177 | 'target-vmid' => get_standard_option('pve-vmid', { optional => 1 }), | |
178 | 'target-endpoint' => get_standard_option('proxmox-remote', { | |
179 | description => "Remote target endpoint", | |
180 | }), | |
181 | online => { | |
182 | type => 'boolean', | |
183 | description => "Use online/live migration if VM is running. Ignored if VM is stopped.", | |
184 | optional => 1, | |
185 | }, | |
186 | delete => { | |
187 | type => 'boolean', | |
188 | description => "Delete the original VM and related data after successful migration. By default the original VM is kept on the source cluster in a stopped state.", | |
189 | optional => 1, | |
190 | default => 0, | |
191 | }, | |
192 | 'target-storage' => get_standard_option('pve-targetstorage', { | |
193 | completion => \&PVE::QemuServer::complete_migration_storage, | |
194 | optional => 0, | |
195 | }), | |
196 | 'target-bridge' => { | |
197 | type => 'string', | |
198 | description => "Mapping from source to target bridges. Providing only a single bridge ID maps all source bridges to that bridge. Providing the special value '1' will map each source bridge to itself.", | |
199 | format => 'bridge-pair-list', | |
200 | }, | |
201 | bwlimit => { | |
202 | description => "Override I/O bandwidth limit (in KiB/s).", | |
203 | optional => 1, | |
204 | type => 'integer', | |
205 | minimum => '0', | |
206 | default => 'migrate limit from datacenter or storage config', | |
207 | }, | |
208 | }, | |
209 | }, | |
210 | returns => { | |
211 | type => 'string', | |
212 | description => "the task ID.", | |
213 | }, | |
214 | code => sub { | |
215 | my ($param) = @_; | |
216 | ||
217 | my $rpcenv = PVE::RPCEnvironment::get(); | |
218 | my $authuser = $rpcenv->get_user(); | |
219 | ||
220 | my $source_vmid = $param->{vmid}; | |
221 | my $target_endpoint = $param->{'target-endpoint'}; | |
222 | my $target_vmid = $param->{'target-vmid'} // $source_vmid; | |
223 | ||
224 | my $remote = PVE::JSONSchema::parse_property_string('proxmox-remote', $target_endpoint); | |
225 | ||
226 | # TODO: move this as helper somewhere appropriate? | |
227 | my $conn_args = { | |
228 | protocol => 'https', | |
229 | host => $remote->{host}, | |
230 | port => $remote->{port} // 8006, | |
231 | apitoken => $remote->{apitoken}, | |
232 | }; | |
233 | ||
234 | $conn_args->{cached_fingerprints} = { uc($remote->{fingerprint}) => 1 } | |
235 | if defined($remote->{fingerprint}); | |
236 | ||
237 | my $api_client = PVE::APIClient::LWP->new(%$conn_args); | |
238 | my $resources = $api_client->get("/cluster/resources", { type => 'vm' }); | |
239 | if (grep { defined($_->{vmid}) && $_->{vmid} eq $target_vmid } @$resources) { | |
240 | raise_param_exc({ target_vmid => "Guest with ID '$target_vmid' already exists on remote cluster" }); | |
241 | } | |
242 | ||
243 | my $storages = $api_client->get("/nodes/localhost/storage", { enabled => 1 }); | |
244 | ||
245 | my $storecfg = PVE::Storage::config(); | |
246 | my $target_storage = $param->{'target-storage'}; | |
247 | my $storagemap = eval { PVE::JSONSchema::parse_idmap($target_storage, 'pve-storage-id') }; | |
248 | raise_param_exc({ 'target-storage' => "failed to parse storage map: $@" }) | |
249 | if $@; | |
250 | ||
251 | my $check_remote_storage = sub { | |
252 | my ($storage) = @_; | |
253 | my $found = [ grep { $_->{storage} eq $storage } @$storages ]; | |
254 | die "remote: storage '$storage' does not exist!\n" | |
255 | if !@$found; | |
256 | ||
257 | $found = @$found[0]; | |
258 | ||
259 | my $content_types = [ PVE::Tools::split_list($found->{content}) ]; | |
260 | die "remote: storage '$storage' cannot store images\n" | |
261 | if !grep { $_ eq 'images' } @$content_types; | |
262 | }; | |
263 | ||
264 | foreach my $target_sid (values %{$storagemap->{entries}}) { | |
265 | $check_remote_storage->($target_sid); | |
266 | } | |
267 | ||
268 | $check_remote_storage->($storagemap->{default}) | |
269 | if $storagemap->{default}; | |
270 | ||
271 | return PVE::API2::Qemu->remote_migrate_vm($param); | |
272 | }}); | |
273 | ||
f3e76e36 DM |
274 | __PACKAGE__->register_method ({ |
275 | name => 'status', | |
276 | path => 'status', | |
277 | method => 'GET', | |
278 | description => "Show VM status.", | |
279 | parameters => { | |
280 | additionalProperties => 0, | |
281 | properties => { | |
335af808 | 282 | vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }), |
f3e76e36 DM |
283 | verbose => { |
284 | description => "Verbose output format", | |
285 | type => 'boolean', | |
286 | optional => 1, | |
287 | } | |
288 | }, | |
289 | }, | |
290 | returns => { type => 'null'}, | |
291 | code => sub { | |
292 | my ($param) = @_; | |
293 | ||
294 | # test if VM exists | |
ffda963f | 295 | my $conf = PVE::QemuConfig->load_config ($param->{vmid}); |
f3e76e36 | 296 | |
12612b09 | 297 | my $vmstatus = PVE::QemuServer::vmstatus($param->{vmid}, 1); |
f3e76e36 DM |
298 | my $stat = $vmstatus->{$param->{vmid}}; |
299 | if ($param->{verbose}) { | |
300 | foreach my $k (sort (keys %$stat)) { | |
301 | next if $k eq 'cpu' || $k eq 'relcpu'; # always 0 | |
302 | my $v = $stat->{$k}; | |
81fff836 | 303 | print_recursive_hash("", $v, $k); |
f3e76e36 DM |
304 | } |
305 | } else { | |
12612b09 | 306 | my $status = $stat->{qmpstatus} || 'unknown'; |
f3e76e36 DM |
307 | print "status: $status\n"; |
308 | } | |
309 | ||
d1c1af4b | 310 | return; |
f3e76e36 DM |
311 | }}); |
312 | ||
313 | __PACKAGE__->register_method ({ | |
314 | name => 'vncproxy', | |
315 | path => 'vncproxy', | |
316 | method => 'PUT', | |
317 | description => "Proxy VM VNC traffic to stdin/stdout", | |
318 | parameters => { | |
319 | additionalProperties => 0, | |
320 | properties => { | |
335af808 | 321 | vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid_running }), |
f3e76e36 DM |
322 | }, |
323 | }, | |
324 | returns => { type => 'null'}, | |
325 | code => sub { | |
326 | my ($param) = @_; | |
327 | ||
328 | my $vmid = $param->{vmid}; | |
0a13e08e | 329 | PVE::QemuConfig::assert_config_exists_on_node($vmid); |
d036e418 | 330 | my $vnc_socket = PVE::QemuServer::Helpers::vnc_socket($vmid); |
f3e76e36 DM |
331 | |
332 | if (my $ticket = $ENV{LC_PVE_TICKET}) { # NOTE: ssh on debian only pass LC_* variables | |
0a13e08e SR |
333 | mon_cmd($vmid, "set_password", protocol => 'vnc', password => $ticket); |
334 | mon_cmd($vmid, "expire_password", protocol => 'vnc', time => "+30"); | |
f3e76e36 | 335 | } else { |
2dc0eb61 | 336 | die "LC_PVE_TICKET not set, VNC proxy without password is forbidden\n"; |
f3e76e36 DM |
337 | } |
338 | ||
339 | run_vnc_proxy($vnc_socket); | |
340 | ||
d1c1af4b | 341 | return; |
f3e76e36 DM |
342 | }}); |
343 | ||
344 | __PACKAGE__->register_method ({ | |
345 | name => 'unlock', | |
346 | path => 'unlock', | |
347 | method => 'PUT', | |
348 | description => "Unlock the VM.", | |
349 | parameters => { | |
350 | additionalProperties => 0, | |
351 | properties => { | |
335af808 | 352 | vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }), |
f3e76e36 DM |
353 | }, |
354 | }, | |
355 | returns => { type => 'null'}, | |
356 | code => sub { | |
357 | my ($param) = @_; | |
358 | ||
359 | my $vmid = $param->{vmid}; | |
360 | ||
04096e7b | 361 | PVE::QemuConfig->lock_config ($vmid, sub { |
ffda963f | 362 | my $conf = PVE::QemuConfig->load_config($vmid); |
f3e76e36 DM |
363 | delete $conf->{lock}; |
364 | delete $conf->{pending}->{lock} if $conf->{pending}; # just to be sure | |
ffda963f | 365 | PVE::QemuConfig->write_config($vmid, $conf); |
f3e76e36 DM |
366 | }); |
367 | ||
d1c1af4b | 368 | return; |
f3e76e36 DM |
369 | }}); |
370 | ||
63a09370 AD |
371 | __PACKAGE__->register_method ({ |
372 | name => 'nbdstop', | |
373 | path => 'nbdstop', | |
374 | method => 'PUT', | |
375 | description => "Stop embedded nbd server.", | |
376 | parameters => { | |
377 | additionalProperties => 0, | |
378 | properties => { | |
379 | vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }), | |
380 | }, | |
381 | }, | |
382 | returns => { type => 'null'}, | |
383 | code => sub { | |
384 | my ($param) = @_; | |
385 | ||
386 | my $vmid = $param->{vmid}; | |
387 | ||
aa6ebf6a TL |
388 | eval { PVE::QemuServer::nbd_stop($vmid) }; |
389 | warn $@ if $@; | |
63a09370 | 390 | |
d1c1af4b | 391 | return; |
63a09370 AD |
392 | }}); |
393 | ||
f3e76e36 DM |
394 | __PACKAGE__->register_method ({ |
395 | name => 'mtunnel', | |
396 | path => 'mtunnel', | |
397 | method => 'POST', | |
398 | description => "Used by qmigrate - do not use manually.", | |
399 | parameters => { | |
400 | additionalProperties => 0, | |
401 | properties => {}, | |
402 | }, | |
403 | returns => { type => 'null'}, | |
404 | code => sub { | |
405 | my ($param) = @_; | |
406 | ||
407 | if (!PVE::Cluster::check_cfs_quorum(1)) { | |
408 | print "no quorum\n"; | |
d1c1af4b | 409 | return; |
f3e76e36 DM |
410 | } |
411 | ||
79c9e079 FG |
412 | my $tunnel_write = sub { |
413 | my $text = shift; | |
414 | chomp $text; | |
415 | print "$text\n"; | |
416 | *STDOUT->flush(); | |
417 | }; | |
418 | ||
419 | $tunnel_write->("tunnel online"); | |
420 | $tunnel_write->("ver 1"); | |
d8518469 | 421 | |
e5caa02e | 422 | while (my $line = <STDIN>) { |
f3e76e36 | 423 | chomp $line; |
bcb51ae8 FG |
424 | if ($line =~ /^quit$/) { |
425 | $tunnel_write->("OK"); | |
426 | last; | |
1d5aaa1d FG |
427 | } elsif ($line =~ /^resume (\d+)$/) { |
428 | my $vmid = $1; | |
a20dc58a FG |
429 | # check_running and vm_resume with nocheck, since local node |
430 | # might not have processed config move/rename yet | |
1d5aaa1d FG |
431 | if (PVE::QemuServer::check_running($vmid, 1)) { |
432 | eval { PVE::QemuServer::vm_resume($vmid, 1, 1); }; | |
433 | if ($@) { | |
434 | $tunnel_write->("ERR: resume failed - $@"); | |
435 | } else { | |
436 | $tunnel_write->("OK"); | |
437 | } | |
438 | } else { | |
439 | $tunnel_write->("ERR: resume failed - VM $vmid not running"); | |
440 | } | |
bcb51ae8 | 441 | } |
f3e76e36 DM |
442 | } |
443 | ||
d1c1af4b | 444 | return; |
f3e76e36 DM |
445 | }}); |
446 | ||
447 | __PACKAGE__->register_method ({ | |
448 | name => 'wait', | |
449 | path => 'wait', | |
450 | method => 'GET', | |
451 | description => "Wait until the VM is stopped.", | |
452 | parameters => { | |
453 | additionalProperties => 0, | |
454 | properties => { | |
335af808 | 455 | vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid_running }), |
f3e76e36 DM |
456 | timeout => { |
457 | description => "Timeout in seconds. Default is to wait forever.", | |
458 | type => 'integer', | |
459 | minimum => 1, | |
460 | optional => 1, | |
461 | } | |
462 | }, | |
463 | }, | |
464 | returns => { type => 'null'}, | |
465 | code => sub { | |
466 | my ($param) = @_; | |
467 | ||
468 | my $vmid = $param->{vmid}; | |
469 | my $timeout = $param->{timeout}; | |
470 | ||
471 | my $pid = PVE::QemuServer::check_running ($vmid); | |
472 | return if !$pid; | |
473 | ||
474 | print "waiting until VM $vmid stopps (PID $pid)\n"; | |
475 | ||
476 | my $count = 0; | |
477 | while ((!$timeout || ($count < $timeout)) && PVE::QemuServer::check_running ($vmid)) { | |
478 | $count++; | |
479 | sleep 1; | |
480 | } | |
481 | ||
482 | die "wait failed - got timeout\n" if PVE::QemuServer::check_running ($vmid); | |
483 | ||
d1c1af4b | 484 | return; |
f3e76e36 DM |
485 | }}); |
486 | ||
487 | __PACKAGE__->register_method ({ | |
488 | name => 'monitor', | |
489 | path => 'monitor', | |
490 | method => 'POST', | |
491 | description => "Enter Qemu Monitor interface.", | |
492 | parameters => { | |
493 | additionalProperties => 0, | |
494 | properties => { | |
335af808 | 495 | vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid_running }), |
f3e76e36 DM |
496 | }, |
497 | }, | |
498 | returns => { type => 'null'}, | |
499 | code => sub { | |
500 | my ($param) = @_; | |
501 | ||
502 | my $vmid = $param->{vmid}; | |
503 | ||
ffda963f | 504 | my $conf = PVE::QemuConfig->load_config ($vmid); # check if VM exists |
f3e76e36 DM |
505 | |
506 | print "Entering Qemu Monitor for VM $vmid - type 'help' for help\n"; | |
507 | ||
f7d1505b | 508 | my $term = Term::ReadLine->new('qm'); |
f3e76e36 | 509 | |
f7d1505b | 510 | while (defined(my $input = $term->readline('qm> '))) { |
f3e76e36 | 511 | chomp $input; |
f3e76e36 | 512 | next if $input =~ m/^\s*$/; |
f3e76e36 DM |
513 | last if $input =~ m/^\s*q(uit)?\s*$/; |
514 | ||
f7d1505b | 515 | eval { print PVE::QemuServer::Monitor::hmp_cmd($vmid, $input) }; |
f3e76e36 DM |
516 | print "ERROR: $@" if $@; |
517 | } | |
518 | ||
d1c1af4b | 519 | return; |
f3e76e36 DM |
520 | |
521 | }}); | |
522 | ||
523 | __PACKAGE__->register_method ({ | |
524 | name => 'rescan', | |
525 | path => 'rescan', | |
526 | method => 'POST', | |
527 | description => "Rescan all storages and update disk sizes and unused disk images.", | |
528 | parameters => { | |
529 | additionalProperties => 0, | |
530 | properties => { | |
335af808 DM |
531 | vmid => get_standard_option('pve-vmid', { |
532 | optional => 1, | |
533 | completion => \&PVE::QemuServer::complete_vmid, | |
534 | }), | |
9224dcee TL |
535 | dryrun => { |
536 | type => 'boolean', | |
537 | optional => 1, | |
538 | default => 0, | |
dc02254e | 539 | description => 'Do not actually write changes out to VM config(s).', |
9224dcee | 540 | }, |
f3e76e36 DM |
541 | }, |
542 | }, | |
543 | returns => { type => 'null'}, | |
544 | code => sub { | |
545 | my ($param) = @_; | |
546 | ||
9224dcee TL |
547 | my $dryrun = $param->{dryrun}; |
548 | ||
549 | print "NOTE: running in dry-run mode, won't write changes out!\n" if $dryrun; | |
550 | ||
551 | PVE::QemuServer::rescan($param->{vmid}, 0, $dryrun); | |
f3e76e36 | 552 | |
d1c1af4b | 553 | return; |
f3e76e36 DM |
554 | }}); |
555 | ||
8653feeb EK |
556 | __PACKAGE__->register_method ({ |
557 | name => 'importdisk', | |
558 | path => 'importdisk', | |
559 | method => 'POST', | |
560 | description => "Import an external disk image as an unused disk in a VM. The | |
561 | image format has to be supported by qemu-img(1).", | |
562 | parameters => { | |
563 | additionalProperties => 0, | |
564 | properties => { | |
565 | vmid => get_standard_option('pve-vmid', {completion => \&PVE::QemuServer::complete_vmid}), | |
566 | source => { | |
567 | description => 'Path to the disk image to import', | |
568 | type => 'string', | |
569 | optional => 0, | |
570 | }, | |
571 | storage => get_standard_option('pve-storage-id', { | |
572 | description => 'Target storage ID', | |
573 | completion => \&PVE::QemuServer::complete_storage, | |
574 | optional => 0, | |
575 | }), | |
576 | format => { | |
577 | type => 'string', | |
578 | description => 'Target format', | |
579 | enum => [ 'raw', 'qcow2', 'vmdk' ], | |
580 | optional => 1, | |
581 | }, | |
582 | }, | |
583 | }, | |
584 | returns => { type => 'null'}, | |
585 | code => sub { | |
586 | my ($param) = @_; | |
587 | ||
588 | my $vmid = extract_param($param, 'vmid'); | |
589 | my $source = extract_param($param, 'source'); | |
590 | my $storeid = extract_param($param, 'storage'); | |
591 | my $format = extract_param($param, 'format'); | |
592 | ||
593 | my $vm_conf = PVE::QemuConfig->load_config($vmid); | |
594 | PVE::QemuConfig->check_lock($vm_conf); | |
595 | die "$source: non-existent or non-regular file\n" if (! -f $source); | |
c7db1e40 | 596 | |
8653feeb EK |
597 | my $storecfg = PVE::Storage::config(); |
598 | PVE::Storage::storage_check_enabled($storecfg, $storeid); | |
599 | ||
c75bf161 | 600 | my $target_storage_config = PVE::Storage::storage_config($storecfg, $storeid); |
c7db1e40 EK |
601 | die "storage $storeid does not support vm images\n" |
602 | if !$target_storage_config->{content}->{images}; | |
603 | ||
c75bf161 TL |
604 | print "importing disk '$source' to VM $vmid ...\n"; |
605 | my ($drive_id, $volid) = PVE::QemuServer::ImportDisk::do_import($source, $vmid, $storeid, { format => $format }); | |
606 | print "Successfully imported disk as '$drive_id:$volid'\n"; | |
8653feeb | 607 | |
d1c1af4b | 608 | return; |
8653feeb EK |
609 | }}); |
610 | ||
f3e76e36 DM |
611 | __PACKAGE__->register_method ({ |
612 | name => 'terminal', | |
613 | path => 'terminal', | |
614 | method => 'POST', | |
615 | description => "Open a terminal using a serial device (The VM need to have a serial device configured, for example 'serial0: socket')", | |
616 | parameters => { | |
617 | additionalProperties => 0, | |
618 | properties => { | |
335af808 | 619 | vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid_running }), |
f3e76e36 DM |
620 | iface => { |
621 | description => "Select the serial device. By default we simply use the first suitable device.", | |
622 | type => 'string', | |
623 | optional => 1, | |
624 | enum => [qw(serial0 serial1 serial2 serial3)], | |
aa320bcd WB |
625 | }, |
626 | escape => { | |
627 | description => "Escape character.", | |
628 | type => 'string', | |
629 | optional => 1, | |
630 | default => '^O', | |
631 | }, | |
f3e76e36 DM |
632 | }, |
633 | }, | |
634 | returns => { type => 'null'}, | |
635 | code => sub { | |
636 | my ($param) = @_; | |
637 | ||
638 | my $vmid = $param->{vmid}; | |
639 | ||
aa320bcd WB |
640 | my $escape = $param->{escape} // '^O'; |
641 | if ($escape =~ /^\^([\x40-\x7a])$/) { | |
642 | $escape = ord($1) & 0x1F; | |
643 | } elsif ($escape =~ /^0x[0-9a-f]+$/i) { | |
644 | $escape = hex($escape); | |
645 | } elsif ($escape =~ /^[0-9]+$/) { | |
646 | $escape = int($escape); | |
647 | } else { | |
648 | die "invalid escape character definition: $escape\n"; | |
649 | } | |
650 | my $escapemsg = ''; | |
651 | if ($escape) { | |
652 | $escapemsg = sprintf(' (press Ctrl+%c to exit)', $escape+0x40); | |
653 | $escape = sprintf(',escape=0x%x', $escape); | |
654 | } else { | |
655 | $escape = ''; | |
656 | } | |
657 | ||
ffda963f | 658 | my $conf = PVE::QemuConfig->load_config ($vmid); # check if VM exists |
f3e76e36 DM |
659 | |
660 | my $iface = $param->{iface}; | |
661 | ||
662 | if ($iface) { | |
663 | die "serial interface '$iface' is not configured\n" if !$conf->{$iface}; | |
664 | die "wrong serial type on interface '$iface'\n" if $conf->{$iface} ne 'socket'; | |
665 | } else { | |
666 | foreach my $opt (qw(serial0 serial1 serial2 serial3)) { | |
667 | if ($conf->{$opt} && ($conf->{$opt} eq 'socket')) { | |
668 | $iface = $opt; | |
669 | last; | |
670 | } | |
671 | } | |
672 | die "unable to find a serial interface\n" if !$iface; | |
673 | } | |
674 | ||
675 | die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid); | |
676 | ||
677 | my $socket = "/var/run/qemu-server/${vmid}.$iface"; | |
678 | ||
aa320bcd | 679 | my $cmd = "socat UNIX-CONNECT:$socket STDIO,raw,echo=0$escape"; |
f3e76e36 | 680 | |
aa320bcd | 681 | print "starting serial terminal on interface ${iface}${escapemsg}\n"; |
f3e76e36 DM |
682 | |
683 | system($cmd); | |
684 | ||
d1c1af4b | 685 | return; |
f3e76e36 DM |
686 | }}); |
687 | ||
7cd9f6d7 EK |
688 | __PACKAGE__->register_method ({ |
689 | name => 'importovf', | |
690 | path => 'importovf', | |
691 | description => "Create a new VM using parameters read from an OVF manifest", | |
692 | parameters => { | |
693 | additionalProperties => 0, | |
694 | properties => { | |
695 | vmid => get_standard_option('pve-vmid', { completion => \&PVE::Cluster::complete_next_vmid }), | |
696 | manifest => { | |
697 | type => 'string', | |
698 | description => 'path to the ovf file', | |
699 | }, | |
700 | storage => get_standard_option('pve-storage-id', { | |
701 | description => 'Target storage ID', | |
702 | completion => \&PVE::QemuServer::complete_storage, | |
703 | optional => 0, | |
704 | }), | |
705 | format => { | |
706 | type => 'string', | |
707 | description => 'Target format', | |
708 | enum => [ 'raw', 'qcow2', 'vmdk' ], | |
709 | optional => 1, | |
710 | }, | |
711 | dryrun => { | |
712 | type => 'boolean', | |
713 | description => 'Print a parsed representation of the extracted OVF parameters, but do not create a VM', | |
714 | optional => 1, | |
f6306646 | 715 | } |
7cd9f6d7 EK |
716 | }, |
717 | }, | |
b533b995 | 718 | returns => { type => 'null' }, |
7cd9f6d7 EK |
719 | code => sub { |
720 | my ($param) = @_; | |
721 | ||
722 | my $vmid = PVE::Tools::extract_param($param, 'vmid'); | |
723 | my $ovf_file = PVE::Tools::extract_param($param, 'manifest'); | |
724 | my $storeid = PVE::Tools::extract_param($param, 'storage'); | |
725 | my $format = PVE::Tools::extract_param($param, 'format'); | |
726 | my $dryrun = PVE::Tools::extract_param($param, 'dryrun'); | |
727 | ||
728 | die "$ovf_file: non-existent or non-regular file\n" if (! -f $ovf_file); | |
729 | my $storecfg = PVE::Storage::config(); | |
730 | PVE::Storage::storage_check_enabled($storecfg, $storeid); | |
731 | ||
732 | my $parsed = PVE::QemuServer::OVF::parse_ovf($ovf_file); | |
733 | ||
734 | if ($dryrun) { | |
0f80f1ab WB |
735 | print to_json($parsed, { pretty => 1, canonical => 1}); |
736 | return; | |
7cd9f6d7 EK |
737 | } |
738 | ||
73a4470a TL |
739 | eval { PVE::QemuConfig->create_and_lock_config($vmid) }; |
740 | die "Reserving empty config for OVF import to VM $vmid failed: $@" if $@; | |
7cd9f6d7 | 741 | |
439390e8 DJ |
742 | my $conf = PVE::QemuConfig->load_config($vmid); |
743 | die "Internal error: Expected 'create' lock in config of VM $vmid!" | |
744 | if !PVE::QemuConfig->has_lock($conf, "create"); | |
7cd9f6d7 | 745 | |
439390e8 DJ |
746 | $conf->{name} = $parsed->{qm}->{name} if defined($parsed->{qm}->{name}); |
747 | $conf->{memory} = $parsed->{qm}->{memory} if defined($parsed->{qm}->{memory}); | |
748 | $conf->{cores} = $parsed->{qm}->{cores} if defined($parsed->{qm}->{cores}); | |
7cd9f6d7 | 749 | |
4405703d | 750 | my $imported_disks = []; |
439390e8 DJ |
751 | eval { |
752 | # order matters, as do_import() will load_config() internally | |
753 | $conf->{vmgenid} = PVE::QemuServer::generate_uuid(); | |
754 | $conf->{smbios1} = PVE::QemuServer::generate_smbios1_uuid(); | |
755 | PVE::QemuConfig->write_config($vmid, $conf); | |
7cd9f6d7 | 756 | |
439390e8 DJ |
757 | foreach my $disk (@{ $parsed->{disks} }) { |
758 | my ($file, $drive) = ($disk->{backing_file}, $disk->{disk_address}); | |
4405703d | 759 | my ($name, $volid) = PVE::QemuServer::ImportDisk::do_import($file, $vmid, $storeid, { |
5600c5b2 TL |
760 | drive_name => $drive, |
761 | format => $format, | |
762 | skiplock => 1, | |
763 | }); | |
4405703d TL |
764 | # for cleanup on (later) error |
765 | push @$imported_disks, $volid; | |
7cd9f6d7 | 766 | } |
439390e8 DJ |
767 | |
768 | # reload after disks entries have been created | |
769 | $conf = PVE::QemuConfig->load_config($vmid); | |
2141a802 SR |
770 | my $devs = PVE::QemuServer::get_default_bootdevices($conf); |
771 | $conf->{boot} = PVE::QemuServer::print_bootorder($devs); | |
439390e8 | 772 | PVE::QemuConfig->write_config($vmid, $conf); |
7cd9f6d7 EK |
773 | }; |
774 | ||
4405703d | 775 | if (my $err = $@) { |
439390e8 | 776 | my $skiplock = 1; |
4405703d TL |
777 | warn "error during import, cleaning up created resources...\n"; |
778 | for my $volid (@$imported_disks) { | |
779 | eval { PVE::Storage::vdisk_free($storecfg, $volid) }; | |
780 | warn "cleanup of $volid failed: $@\n" if $@; | |
781 | } | |
b04ea584 | 782 | eval { PVE::QemuServer::destroy_vm($storecfg, $vmid, $skiplock) }; |
439390e8 DJ |
783 | warn "Could not destroy VM $vmid: $@" if "$@"; |
784 | die "import failed - $err"; | |
785 | } | |
73a4470a TL |
786 | |
787 | PVE::QemuConfig->remove_lock($vmid, "create"); | |
5d942f5a | 788 | |
d1c1af4b | 789 | return; |
7cd9f6d7 EK |
790 | |
791 | } | |
792 | }); | |
788a6a35 | 793 | |
520884de DC |
794 | __PACKAGE__->register_method({ |
795 | name => 'exec', | |
796 | path => 'exec', | |
797 | method => 'POST', | |
798 | protected => 1, | |
799 | description => "Executes the given command via the guest agent", | |
800 | parameters => { | |
801 | additionalProperties => 0, | |
802 | properties => { | |
803 | node => get_standard_option('pve-node'), | |
804 | vmid => get_standard_option('pve-vmid', { | |
805 | completion => \&PVE::QemuServer::complete_vmid_running }), | |
806 | synchronous => { | |
807 | type => 'boolean', | |
808 | optional => 1, | |
809 | default => 1, | |
810 | description => "If set to off, returns the pid immediately instead of waiting for the commmand to finish or the timeout.", | |
811 | }, | |
812 | 'timeout' => { | |
813 | type => 'integer', | |
814 | description => "The maximum time to wait synchronously for the command to finish. If reached, the pid gets returned. Set to 0 to deactivate", | |
815 | minimum => 0, | |
816 | optional => 1, | |
817 | default => 30, | |
818 | }, | |
d8f61794 SR |
819 | 'pass-stdin' => { |
820 | type => 'boolean', | |
109a0950 | 821 | description => "When set, read STDIN until EOF and forward to guest agent via 'input-data' (usually treated as STDIN to process launched by guest agent). Allows maximal 1 MiB.", |
d8f61794 SR |
822 | optional => 1, |
823 | default => 0, | |
824 | }, | |
520884de DC |
825 | 'extra-args' => get_standard_option('extra-args'), |
826 | }, | |
827 | }, | |
828 | returns => { | |
829 | type => 'object', | |
830 | }, | |
831 | code => sub { | |
832 | my ($param) = @_; | |
833 | ||
834 | my $vmid = $param->{vmid}; | |
835 | my $sync = $param->{synchronous} // 1; | |
d8f61794 | 836 | my $pass_stdin = $param->{'pass-stdin'}; |
520884de DC |
837 | if (defined($param->{timeout}) && !$sync) { |
838 | raise_param_exc({ synchronous => "needs to be set for 'timeout'"}); | |
839 | } | |
840 | ||
d8f61794 SR |
841 | my $input_data = undef; |
842 | if ($pass_stdin) { | |
843 | $input_data = ''; | |
844 | while (my $line = <STDIN>) { | |
845 | $input_data .= $line; | |
846 | if (length($input_data) > 1024*1024) { | |
847 | # not sure how QEMU handles large amounts of data being | |
848 | # passed into the QMP socket, so limit to be safe | |
849 | die "'input-data' (STDIN) is limited to 1 MiB, aborting\n"; | |
850 | } | |
851 | } | |
852 | } | |
853 | ||
854 | my $args = $param->{'extra-args'}; | |
855 | $args = undef if !$args || !@$args; | |
856 | ||
857 | my $res = PVE::QemuServer::Agent::qemu_exec($vmid, $input_data, $args); | |
520884de DC |
858 | |
859 | if ($sync) { | |
860 | my $pid = $res->{pid}; | |
861 | my $timeout = $param->{timeout} // 30; | |
862 | my $starttime = time(); | |
863 | ||
864 | while ($timeout == 0 || (time() - $starttime) < $timeout) { | |
865 | my $out = PVE::QemuServer::Agent::qemu_exec_status($vmid, $pid); | |
866 | if ($out->{exited}) { | |
867 | $res = $out; | |
868 | last; | |
869 | } | |
870 | sleep 1; | |
871 | } | |
872 | ||
873 | if (!$res->{exited}) { | |
874 | warn "timeout reached, returning pid\n"; | |
875 | } | |
876 | } | |
877 | ||
878 | return { result => $res }; | |
879 | }}); | |
880 | ||
3ea84aeb DC |
881 | __PACKAGE__->register_method({ |
882 | name => 'cleanup', | |
883 | path => 'cleanup', | |
884 | method => 'POST', | |
885 | protected => 1, | |
886 | description => "Cleans up resources like tap devices, vgpus, etc. Called after a vm shuts down, crashes, etc.", | |
887 | parameters => { | |
888 | additionalProperties => 0, | |
889 | properties => { | |
890 | node => get_standard_option('pve-node'), | |
891 | vmid => get_standard_option('pve-vmid', { | |
892 | completion => \&PVE::QemuServer::complete_vmid_running }), | |
893 | 'clean-shutdown' => { | |
894 | type => 'boolean', | |
895 | description => "Indicates if qemu shutdown cleanly.", | |
896 | }, | |
897 | 'guest-requested' => { | |
898 | type => 'boolean', | |
899 | description => "Indicates if the shutdown was requested by the guest or via qmp.", | |
900 | }, | |
901 | }, | |
902 | }, | |
903 | returns => { type => 'null', }, | |
904 | code => sub { | |
905 | my ($param) = @_; | |
906 | ||
907 | my $vmid = $param->{vmid}; | |
908 | my $clean = $param->{'clean-shutdown'}; | |
909 | my $guest = $param->{'guest-requested'}; | |
64457ed4 | 910 | my $restart = 0; |
3ea84aeb | 911 | |
0f56fff2 DC |
912 | # return if we do not have the config anymore |
913 | return if !-f PVE::QemuConfig->config_file($vmid); | |
914 | ||
3ea84aeb DC |
915 | my $storecfg = PVE::Storage::config(); |
916 | warn "Starting cleanup for $vmid\n"; | |
917 | ||
918 | PVE::QemuConfig->lock_config($vmid, sub { | |
919 | my $conf = PVE::QemuConfig->load_config ($vmid); | |
920 | my $pid = PVE::QemuServer::check_running ($vmid); | |
921 | die "vm still running\n" if $pid; | |
922 | ||
923 | if (!$clean) { | |
924 | # we have to cleanup the tap devices after a crash | |
925 | ||
926 | foreach my $opt (keys %$conf) { | |
702c2f6e | 927 | next if $opt !~ m/^net(\d+)$/; |
3ea84aeb DC |
928 | my $interface = $1; |
929 | PVE::Network::tap_unplug("tap${vmid}i${interface}"); | |
930 | } | |
931 | } | |
932 | ||
933 | if (!$clean || $guest) { | |
934 | # vm was shutdown from inside the guest or crashed, doing api cleanup | |
935 | PVE::QemuServer::vm_stop_cleanup($storecfg, $vmid, $conf, 0, 0); | |
936 | } | |
9e784b11 | 937 | PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-stop'); |
64457ed4 DC |
938 | |
939 | $restart = eval { PVE::QemuServer::clear_reboot_request($vmid) }; | |
940 | warn $@ if $@; | |
3ea84aeb DC |
941 | }); |
942 | ||
943 | warn "Finished cleanup for $vmid\n"; | |
944 | ||
64457ed4 DC |
945 | if ($restart) { |
946 | warn "Restarting VM $vmid\n"; | |
947 | PVE::API2::Qemu->vm_start({ | |
948 | vmid => $vmid, | |
10ff4fe7 | 949 | %node, |
64457ed4 DC |
950 | }); |
951 | } | |
952 | ||
d1c1af4b | 953 | return; |
3ea84aeb DC |
954 | }}); |
955 | ||
788a6a35 DM |
956 | my $print_agent_result = sub { |
957 | my ($data) = @_; | |
958 | ||
520884de | 959 | my $result = $data->{result} // $data; |
788a6a35 DM |
960 | return if !defined($result); |
961 | ||
962 | my $class = ref($result); | |
963 | ||
964 | if (!$class) { | |
965 | chomp $result; | |
966 | return if $result =~ m/^\s*$/; | |
967 | print "$result\n"; | |
968 | return; | |
969 | } | |
970 | ||
971 | if (($class eq 'HASH') && !scalar(keys %$result)) { # empty hash | |
972 | return; | |
973 | } | |
974 | ||
3b6479ff | 975 | print to_json($result, { pretty => 1, canonical => 1, utf8 => 1}); |
788a6a35 DM |
976 | }; |
977 | ||
3351aacc WB |
978 | sub param_mapping { |
979 | my ($name) = @_; | |
980 | ||
981 | my $ssh_key_map = ['sshkeys', sub { | |
982 | return URI::Escape::uri_escape(PVE::Tools::file_get_contents($_[0])); | |
983 | }]; | |
3dba118c | 984 | my $cipassword_map = PVE::CLIHandler::get_standard_mapping('pve-password', { name => 'cipassword' }); |
8593cbe4 | 985 | my $password_map = PVE::CLIHandler::get_standard_mapping('pve-password'); |
3351aacc | 986 | my $mapping = { |
29d1f147 WB |
987 | 'update_vm' => [$ssh_key_map, $cipassword_map], |
988 | 'create_vm' => [$ssh_key_map, $cipassword_map], | |
8593cbe4 | 989 | 'set-user-password' => [$password_map], |
3351aacc WB |
990 | }; |
991 | ||
992 | return $mapping->{$name}; | |
993 | } | |
994 | ||
f3e76e36 | 995 | our $cmddef = { |
10ff4fe7 | 996 | list=> [ "PVE::API2::Qemu", 'vmlist', [], { %node }, sub { |
e849ff6f | 997 | my $vmlist = shift; |
e849ff6f | 998 | exit 0 if (!scalar(@$vmlist)); |
f3e76e36 | 999 | |
e849ff6f TL |
1000 | printf "%10s %-20s %-10s %-10s %12s %-10s\n", |
1001 | qw(VMID NAME STATUS MEM(MB) BOOTDISK(GB) PID); | |
f3e76e36 | 1002 | |
e849ff6f TL |
1003 | foreach my $rec (sort { $a->{vmid} <=> $b->{vmid} } @$vmlist) { |
1004 | printf "%10s %-20s %-10s %-10s %12.2f %-10s\n", $rec->{vmid}, $rec->{name}, | |
1005 | $rec->{qmpstatus} || $rec->{status}, | |
1006 | ($rec->{maxmem} || 0)/(1024*1024), | |
1007 | ($rec->{maxdisk} || 0)/(1024*1024*1024), | |
1008 | $rec->{pid} || 0; | |
1009 | } | |
1010 | }], | |
f3e76e36 | 1011 | |
10ff4fe7 TL |
1012 | create => [ "PVE::API2::Qemu", 'create_vm', ['vmid'], { %node }, $upid_exit ], |
1013 | destroy => [ "PVE::API2::Qemu", 'destroy_vm', ['vmid'], { %node }, $upid_exit ], | |
1014 | clone => [ "PVE::API2::Qemu", 'clone_vm', ['vmid', 'newid'], { %node }, $upid_exit ], | |
f3e76e36 | 1015 | |
10ff4fe7 | 1016 | migrate => [ "PVE::API2::Qemu", 'migrate_vm', ['vmid', 'target'], { %node }, $upid_exit ], |
192bbfda | 1017 | 'remote-migrate' => [ __PACKAGE__, 'remote_migrate_vm', ['vmid', 'target-vmid', 'target-endpoint'], { %node }, $upid_exit ], |
f3e76e36 | 1018 | |
10ff4fe7 | 1019 | set => [ "PVE::API2::Qemu", 'update_vm', ['vmid'], { %node } ], |
f3e76e36 | 1020 | |
10ff4fe7 | 1021 | config => [ "PVE::API2::Qemu", 'vm_config', ['vmid'], { %node }, sub { |
e849ff6f TL |
1022 | my $config = shift; |
1023 | foreach my $k (sort (keys %$config)) { | |
1024 | next if $k eq 'digest'; | |
1025 | my $v = $config->{$k}; | |
1026 | if ($k eq 'description') { | |
1027 | $v = PVE::Tools::encode_text($v); | |
1028 | } | |
1029 | print "$k: $v\n"; | |
1030 | } | |
1031 | }], | |
f3e76e36 | 1032 | |
10ff4fe7 | 1033 | pending => [ "PVE::API2::Qemu", 'vm_pending', ['vmid'], { %node }, \&PVE::GuestHelpers::format_pending ], |
f3e76e36 DM |
1034 | showcmd => [ __PACKAGE__, 'showcmd', ['vmid']], |
1035 | ||
1036 | status => [ __PACKAGE__, 'status', ['vmid']], | |
1037 | ||
e849ff6f | 1038 | # FIXME: for 8.0 move to command group snapshot { create, list, destroy, rollback } |
10ff4fe7 | 1039 | snapshot => [ "PVE::API2::Qemu", 'snapshot', ['vmid', 'snapname'], { %node } , $upid_exit ], |
10ff4fe7 | 1040 | delsnapshot => [ "PVE::API2::Qemu", 'delsnapshot', ['vmid', 'snapname'], { %node } , $upid_exit ], |
10ff4fe7 | 1041 | listsnapshot => [ "PVE::API2::Qemu", 'snapshot_list', ['vmid'], { %node }, \&PVE::GuestHelpers::print_snapshot_tree], |
10ff4fe7 | 1042 | rollback => [ "PVE::API2::Qemu", 'rollback', ['vmid', 'snapname'], { %node } , $upid_exit ], |
f3e76e36 | 1043 | |
10ff4fe7 | 1044 | template => [ "PVE::API2::Qemu", 'template', ['vmid'], { %node }], |
f3e76e36 | 1045 | |
e849ff6f | 1046 | # FIXME: should be in a power command group? |
10ff4fe7 TL |
1047 | start => [ "PVE::API2::Qemu", 'vm_start', ['vmid'], { %node } , $upid_exit ], |
1048 | stop => [ "PVE::API2::Qemu", 'vm_stop', ['vmid'], { %node }, $upid_exit ], | |
1049 | reset => [ "PVE::API2::Qemu", 'vm_reset', ['vmid'], { %node }, $upid_exit ], | |
1050 | shutdown => [ "PVE::API2::Qemu", 'vm_shutdown', ['vmid'], { %node }, $upid_exit ], | |
1051 | reboot => [ "PVE::API2::Qemu", 'vm_reboot', ['vmid'], { %node }, $upid_exit ], | |
1052 | suspend => [ "PVE::API2::Qemu", 'vm_suspend', ['vmid'], { %node }, $upid_exit ], | |
1053 | resume => [ "PVE::API2::Qemu", 'vm_resume', ['vmid'], { %node }, $upid_exit ], | |
f3e76e36 | 1054 | |
10ff4fe7 | 1055 | sendkey => [ "PVE::API2::Qemu", 'vm_sendkey', ['vmid', 'key'], { %node } ], |
f3e76e36 DM |
1056 | |
1057 | vncproxy => [ __PACKAGE__, 'vncproxy', ['vmid']], | |
1058 | ||
1059 | wait => [ __PACKAGE__, 'wait', ['vmid']], | |
1060 | ||
1061 | unlock => [ __PACKAGE__, 'unlock', ['vmid']], | |
1062 | ||
e79cf17d TL |
1063 | # TODO: evluate dropping below aliases for 8.0, if no usage is left |
1064 | importdisk => { alias => 'disk import' }, | |
1065 | 'move-disk' => { alias => 'disk move' }, | |
1066 | move_disk => { alias => 'disk move' }, | |
1067 | rescan => { alias => 'disk rescan' }, | |
1068 | resize => { alias => 'disk resize' }, | |
49063d76 | 1069 | unlink => { alias => 'disk unlink' }, |
e79cf17d TL |
1070 | |
1071 | disk => { | |
1072 | import => [ __PACKAGE__, 'importdisk', ['vmid', 'source', 'storage']], | |
1073 | 'move' => [ "PVE::API2::Qemu", 'move_vm_disk', ['vmid', 'disk', 'storage'], { %node }, $upid_exit ], | |
1074 | rescan => [ __PACKAGE__, 'rescan', []], | |
1075 | resize => [ "PVE::API2::Qemu", 'resize_vm', ['vmid', 'disk', 'size'], { %node } ], | |
49063d76 | 1076 | unlink => [ "PVE::API2::Qemu", 'unlink', ['vmid'], { %node } ], |
e79cf17d | 1077 | }, |
f3e76e36 DM |
1078 | |
1079 | monitor => [ __PACKAGE__, 'monitor', ['vmid']], | |
1080 | ||
10ff4fe7 | 1081 | agent => { alias => 'guest cmd' }, # FIXME: remove with PVE 8.0 |
d1a47427 | 1082 | |
34e4c0aa | 1083 | guest => { |
10ff4fe7 TL |
1084 | cmd => [ "PVE::API2::Qemu::Agent", 'agent', ['vmid', 'command'], { %node }, $print_agent_result ], |
1085 | passwd => [ "PVE::API2::Qemu::Agent", 'set-user-password', [ 'vmid', 'username' ], { %node }], | |
1086 | exec => [ __PACKAGE__, 'exec', [ 'vmid', 'extra-args' ], { %node }, $print_agent_result], | |
1087 | 'exec-status' => [ "PVE::API2::Qemu::Agent", 'exec-status', [ 'vmid', 'pid' ], { %node }, $print_agent_result], | |
8593cbe4 DC |
1088 | }, |
1089 | ||
f3e76e36 DM |
1090 | mtunnel => [ __PACKAGE__, 'mtunnel', []], |
1091 | ||
63a09370 AD |
1092 | nbdstop => [ __PACKAGE__, 'nbdstop', ['vmid']], |
1093 | ||
f3e76e36 | 1094 | terminal => [ __PACKAGE__, 'terminal', ['vmid']], |
8653feeb | 1095 | |
7cd9f6d7 EK |
1096 | importovf => [ __PACKAGE__, 'importovf', ['vmid', 'manifest', 'storage']], |
1097 | ||
10ff4fe7 | 1098 | cleanup => [ __PACKAGE__, 'cleanup', ['vmid', 'clean-shutdown', 'guest-requested'], { %node }], |
3ea84aeb | 1099 | |
1e1763e9 | 1100 | cloudinit => { |
10ff4fe7 | 1101 | dump => [ "PVE::API2::Qemu", 'cloudinit_generated_config_dump', ['vmid', 'type'], { %node }, sub { print "$_[0]\n"; }], |
9687287b AD |
1102 | pending => [ "PVE::API2::Qemu", 'cloudinit_pending', ['vmid'], { %node }, \&PVE::GuestHelpers::format_pending ], |
1103 | update => [ "PVE::API2::Qemu", 'cloudinit_update', ['vmid'], { node => $nodename }], | |
1e1763e9 ML |
1104 | }, |
1105 | ||
f3e76e36 DM |
1106 | }; |
1107 | ||
1108 | 1; |