]> git.proxmox.com Git - qemu-server.git/blame - PVE/CLI/qm.pm
qm showcmd --pretty: indent new lines by 2 spaces
[qemu-server.git] / PVE / CLI / qm.pm
CommitLineData
f3e76e36
DM
1package PVE::CLI::qm;
2
3use strict;
4use warnings;
5
6# Note: disable '+' prefix for Getopt::Long (for resize command)
7use Getopt::Long qw(:config no_getopt_compat);
8
9use Fcntl ':flock';
10use File::Path;
11use IO::Socket::UNIX;
12use IO::Select;
13
14use PVE::Tools qw(extract_param);
15use PVE::Cluster;
16use PVE::SafeSyslog;
17use PVE::INotify;
18use PVE::RPCEnvironment;
19use PVE::QemuServer;
8653feeb 20use PVE::QemuServer::ImportDisk;
7cd9f6d7 21use PVE::QemuServer::OVF;
f3e76e36 22use PVE::API2::Qemu;
788a6a35 23use JSON;
f3e76e36
DM
24use PVE::JSONSchema qw(get_standard_option);
25use Term::ReadLine;
26
27use PVE::CLIHandler;
28
29use base qw(PVE::CLIHandler);
30
31my $upid_exit = sub {
32 my $upid = shift;
33 my $status = PVE::Tools::upid_read_status($upid);
34 exit($status eq 'OK' ? 0 : -1);
35};
36
37my $nodename = PVE::INotify::nodename();
38
5e4035c7
DM
39sub setup_environment {
40 PVE::RPCEnvironment->setup_default_cli_env();
41}
42
f3e76e36
DM
43sub run_vnc_proxy {
44 my ($path) = @_;
45
46 my $c;
47 while ( ++$c < 10 && !-e $path ) { sleep(1); }
48
49 my $s = IO::Socket::UNIX->new(Peer => $path, Timeout => 120);
50
51 die "unable to connect to socket '$path' - $!" if !$s;
52
53 my $select = new IO::Select;
54
55 $select->add(\*STDIN);
56 $select->add($s);
57
58 my $timeout = 60*15; # 15 minutes
59
60 my @handles;
61 while ($select->count &&
62 scalar(@handles = $select->can_read ($timeout))) {
63 foreach my $h (@handles) {
64 my $buf;
65 my $n = $h->sysread($buf, 4096);
66
67 if ($h == \*STDIN) {
68 if ($n) {
69 syswrite($s, $buf);
70 } else {
71 exit(0);
72 }
73 } elsif ($h == $s) {
74 if ($n) {
75 syswrite(\*STDOUT, $buf);
76 } else {
77 exit(0);
78 }
79 }
80 }
81 }
82 exit(0);
83}
84
81fff836
DC
85sub print_recursive_hash {
86 my ($prefix, $hash, $key) = @_;
87
88 if (ref($hash) eq 'HASH') {
89 if (defined($key)) {
90 print "$prefix$key:\n";
91 }
92 foreach my $itemkey (keys %$hash) {
93 print_recursive_hash("\t$prefix", $hash->{$itemkey}, $itemkey);
94 }
95 } elsif (ref($hash) eq 'ARRAY') {
96 if (defined($key)) {
97 print "$prefix$key:\n";
98 }
99 foreach my $item (@$hash) {
100 print_recursive_hash("\t$prefix", $item);
101 }
102 } elsif (!ref($hash) && defined($hash)) {
103 if (defined($key)) {
104 print "$prefix$key: $hash\n";
105 } else {
106 print "$prefix$hash\n";
107 }
108 }
109}
110
f3e76e36
DM
111__PACKAGE__->register_method ({
112 name => 'showcmd',
113 path => 'showcmd',
114 method => 'GET',
115 description => "Show command line which is used to start the VM (debug info).",
116 parameters => {
117 additionalProperties => 0,
118 properties => {
335af808 119 vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
16a01738
TL
120 pretty => {
121 description => "Puts each option on a new line to enhance human readability",
122 type => 'boolean',
123 optional => 1,
124 default => 0,
125 }
f3e76e36
DM
126 },
127 },
128 returns => { type => 'null'},
129 code => sub {
130 my ($param) = @_;
131
132 my $storecfg = PVE::Storage::config();
16a01738
TL
133 my $cmdline = PVE::QemuServer::vm_commandline($storecfg, $param->{vmid});
134
108899b4 135 $cmdline =~ s/ -/ \\\n -/g if $param->{pretty};
16a01738
TL
136
137 print "$cmdline\n";
f3e76e36
DM
138
139 return undef;
140 }});
141
142__PACKAGE__->register_method ({
143 name => 'status',
144 path => 'status',
145 method => 'GET',
146 description => "Show VM status.",
147 parameters => {
148 additionalProperties => 0,
149 properties => {
335af808 150 vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
f3e76e36
DM
151 verbose => {
152 description => "Verbose output format",
153 type => 'boolean',
154 optional => 1,
155 }
156 },
157 },
158 returns => { type => 'null'},
159 code => sub {
160 my ($param) = @_;
161
162 # test if VM exists
ffda963f 163 my $conf = PVE::QemuConfig->load_config ($param->{vmid});
f3e76e36 164
12612b09 165 my $vmstatus = PVE::QemuServer::vmstatus($param->{vmid}, 1);
f3e76e36
DM
166 my $stat = $vmstatus->{$param->{vmid}};
167 if ($param->{verbose}) {
168 foreach my $k (sort (keys %$stat)) {
169 next if $k eq 'cpu' || $k eq 'relcpu'; # always 0
170 my $v = $stat->{$k};
81fff836 171 print_recursive_hash("", $v, $k);
f3e76e36
DM
172 }
173 } else {
12612b09 174 my $status = $stat->{qmpstatus} || 'unknown';
f3e76e36
DM
175 print "status: $status\n";
176 }
177
178 return undef;
179 }});
180
181__PACKAGE__->register_method ({
182 name => 'vncproxy',
183 path => 'vncproxy',
184 method => 'PUT',
185 description => "Proxy VM VNC traffic to stdin/stdout",
186 parameters => {
187 additionalProperties => 0,
188 properties => {
335af808 189 vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid_running }),
f3e76e36
DM
190 },
191 },
192 returns => { type => 'null'},
193 code => sub {
194 my ($param) = @_;
195
196 my $vmid = $param->{vmid};
197 my $vnc_socket = PVE::QemuServer::vnc_socket($vmid);
198
199 if (my $ticket = $ENV{LC_PVE_TICKET}) { # NOTE: ssh on debian only pass LC_* variables
200 PVE::QemuServer::vm_mon_cmd($vmid, "change", device => 'vnc', target => "unix:$vnc_socket,password");
201 PVE::QemuServer::vm_mon_cmd($vmid, "set_password", protocol => 'vnc', password => $ticket);
202 PVE::QemuServer::vm_mon_cmd($vmid, "expire_password", protocol => 'vnc', time => "+30");
203 } else {
204 PVE::QemuServer::vm_mon_cmd($vmid, "change", device => 'vnc', target => "unix:$vnc_socket,x509,password");
205 }
206
207 run_vnc_proxy($vnc_socket);
208
209 return undef;
210 }});
211
212__PACKAGE__->register_method ({
213 name => 'unlock',
214 path => 'unlock',
215 method => 'PUT',
216 description => "Unlock the VM.",
217 parameters => {
218 additionalProperties => 0,
219 properties => {
335af808 220 vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
f3e76e36
DM
221 },
222 },
223 returns => { type => 'null'},
224 code => sub {
225 my ($param) = @_;
226
227 my $vmid = $param->{vmid};
228
04096e7b 229 PVE::QemuConfig->lock_config ($vmid, sub {
ffda963f 230 my $conf = PVE::QemuConfig->load_config($vmid);
f3e76e36
DM
231 delete $conf->{lock};
232 delete $conf->{pending}->{lock} if $conf->{pending}; # just to be sure
ffda963f 233 PVE::QemuConfig->write_config($vmid, $conf);
f3e76e36
DM
234 });
235
236 return undef;
237 }});
238
63a09370
AD
239__PACKAGE__->register_method ({
240 name => 'nbdstop',
241 path => 'nbdstop',
242 method => 'PUT',
243 description => "Stop embedded nbd server.",
244 parameters => {
245 additionalProperties => 0,
246 properties => {
247 vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
248 },
249 },
250 returns => { type => 'null'},
251 code => sub {
252 my ($param) = @_;
253
254 my $vmid = $param->{vmid};
255
256 PVE::QemuServer::nbd_stop($vmid);
257
258 return undef;
259 }});
260
f3e76e36
DM
261__PACKAGE__->register_method ({
262 name => 'mtunnel',
263 path => 'mtunnel',
264 method => 'POST',
265 description => "Used by qmigrate - do not use manually.",
266 parameters => {
267 additionalProperties => 0,
268 properties => {},
269 },
270 returns => { type => 'null'},
271 code => sub {
272 my ($param) = @_;
273
274 if (!PVE::Cluster::check_cfs_quorum(1)) {
275 print "no quorum\n";
276 return undef;
277 }
278
79c9e079
FG
279 my $tunnel_write = sub {
280 my $text = shift;
281 chomp $text;
282 print "$text\n";
283 *STDOUT->flush();
284 };
285
286 $tunnel_write->("tunnel online");
287 $tunnel_write->("ver 1");
d8518469 288
f3e76e36
DM
289 while (my $line = <>) {
290 chomp $line;
bcb51ae8
FG
291 if ($line =~ /^quit$/) {
292 $tunnel_write->("OK");
293 last;
1d5aaa1d
FG
294 } elsif ($line =~ /^resume (\d+)$/) {
295 my $vmid = $1;
296 if (PVE::QemuServer::check_running($vmid, 1)) {
297 eval { PVE::QemuServer::vm_resume($vmid, 1, 1); };
298 if ($@) {
299 $tunnel_write->("ERR: resume failed - $@");
300 } else {
301 $tunnel_write->("OK");
302 }
303 } else {
304 $tunnel_write->("ERR: resume failed - VM $vmid not running");
305 }
bcb51ae8 306 }
f3e76e36
DM
307 }
308
309 return undef;
310 }});
311
312__PACKAGE__->register_method ({
313 name => 'wait',
314 path => 'wait',
315 method => 'GET',
316 description => "Wait until the VM is stopped.",
317 parameters => {
318 additionalProperties => 0,
319 properties => {
335af808 320 vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid_running }),
f3e76e36
DM
321 timeout => {
322 description => "Timeout in seconds. Default is to wait forever.",
323 type => 'integer',
324 minimum => 1,
325 optional => 1,
326 }
327 },
328 },
329 returns => { type => 'null'},
330 code => sub {
331 my ($param) = @_;
332
333 my $vmid = $param->{vmid};
334 my $timeout = $param->{timeout};
335
336 my $pid = PVE::QemuServer::check_running ($vmid);
337 return if !$pid;
338
339 print "waiting until VM $vmid stopps (PID $pid)\n";
340
341 my $count = 0;
342 while ((!$timeout || ($count < $timeout)) && PVE::QemuServer::check_running ($vmid)) {
343 $count++;
344 sleep 1;
345 }
346
347 die "wait failed - got timeout\n" if PVE::QemuServer::check_running ($vmid);
348
349 return undef;
350 }});
351
352__PACKAGE__->register_method ({
353 name => 'monitor',
354 path => 'monitor',
355 method => 'POST',
356 description => "Enter Qemu Monitor interface.",
357 parameters => {
358 additionalProperties => 0,
359 properties => {
335af808 360 vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid_running }),
f3e76e36
DM
361 },
362 },
363 returns => { type => 'null'},
364 code => sub {
365 my ($param) = @_;
366
367 my $vmid = $param->{vmid};
368
ffda963f 369 my $conf = PVE::QemuConfig->load_config ($vmid); # check if VM exists
f3e76e36
DM
370
371 print "Entering Qemu Monitor for VM $vmid - type 'help' for help\n";
372
373 my $term = new Term::ReadLine ('qm');
374
375 my $input;
376 while (defined ($input = $term->readline('qm> '))) {
377 chomp $input;
378
379 next if $input =~ m/^\s*$/;
380
381 last if $input =~ m/^\s*q(uit)?\s*$/;
382
383 eval {
384 print PVE::QemuServer::vm_human_monitor_command ($vmid, $input);
385 };
386 print "ERROR: $@" if $@;
387 }
388
389 return undef;
390
391 }});
392
393__PACKAGE__->register_method ({
394 name => 'rescan',
395 path => 'rescan',
396 method => 'POST',
397 description => "Rescan all storages and update disk sizes and unused disk images.",
398 parameters => {
399 additionalProperties => 0,
400 properties => {
335af808
DM
401 vmid => get_standard_option('pve-vmid', {
402 optional => 1,
403 completion => \&PVE::QemuServer::complete_vmid,
404 }),
f3e76e36
DM
405 },
406 },
407 returns => { type => 'null'},
408 code => sub {
409 my ($param) = @_;
410
411 PVE::QemuServer::rescan($param->{vmid});
412
413 return undef;
414 }});
415
8653feeb
EK
416__PACKAGE__->register_method ({
417 name => 'importdisk',
418 path => 'importdisk',
419 method => 'POST',
420 description => "Import an external disk image as an unused disk in a VM. The
421 image format has to be supported by qemu-img(1).",
422 parameters => {
423 additionalProperties => 0,
424 properties => {
425 vmid => get_standard_option('pve-vmid', {completion => \&PVE::QemuServer::complete_vmid}),
426 source => {
427 description => 'Path to the disk image to import',
428 type => 'string',
429 optional => 0,
430 },
431 storage => get_standard_option('pve-storage-id', {
432 description => 'Target storage ID',
433 completion => \&PVE::QemuServer::complete_storage,
434 optional => 0,
435 }),
436 format => {
437 type => 'string',
438 description => 'Target format',
439 enum => [ 'raw', 'qcow2', 'vmdk' ],
440 optional => 1,
441 },
442 },
443 },
444 returns => { type => 'null'},
445 code => sub {
446 my ($param) = @_;
447
448 my $vmid = extract_param($param, 'vmid');
449 my $source = extract_param($param, 'source');
450 my $storeid = extract_param($param, 'storage');
451 my $format = extract_param($param, 'format');
452
453 my $vm_conf = PVE::QemuConfig->load_config($vmid);
454 PVE::QemuConfig->check_lock($vm_conf);
455 die "$source: non-existent or non-regular file\n" if (! -f $source);
c7db1e40 456
8653feeb
EK
457 my $storecfg = PVE::Storage::config();
458 PVE::Storage::storage_check_enabled($storecfg, $storeid);
459
c7db1e40
EK
460 my $target_storage_config =
461 PVE::Storage::storage_config($storecfg, $storeid);
462 die "storage $storeid does not support vm images\n"
463 if !$target_storage_config->{content}->{images};
464
8653feeb
EK
465 PVE::QemuServer::ImportDisk::do_import($source, $vmid, $storeid, { format => $format });
466
467 return undef;
468 }});
469
f3e76e36
DM
470__PACKAGE__->register_method ({
471 name => 'terminal',
472 path => 'terminal',
473 method => 'POST',
474 description => "Open a terminal using a serial device (The VM need to have a serial device configured, for example 'serial0: socket')",
475 parameters => {
476 additionalProperties => 0,
477 properties => {
335af808 478 vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid_running }),
f3e76e36
DM
479 iface => {
480 description => "Select the serial device. By default we simply use the first suitable device.",
481 type => 'string',
482 optional => 1,
483 enum => [qw(serial0 serial1 serial2 serial3)],
aa320bcd
WB
484 },
485 escape => {
486 description => "Escape character.",
487 type => 'string',
488 optional => 1,
489 default => '^O',
490 },
f3e76e36
DM
491 },
492 },
493 returns => { type => 'null'},
494 code => sub {
495 my ($param) = @_;
496
497 my $vmid = $param->{vmid};
498
aa320bcd
WB
499 my $escape = $param->{escape} // '^O';
500 if ($escape =~ /^\^([\x40-\x7a])$/) {
501 $escape = ord($1) & 0x1F;
502 } elsif ($escape =~ /^0x[0-9a-f]+$/i) {
503 $escape = hex($escape);
504 } elsif ($escape =~ /^[0-9]+$/) {
505 $escape = int($escape);
506 } else {
507 die "invalid escape character definition: $escape\n";
508 }
509 my $escapemsg = '';
510 if ($escape) {
511 $escapemsg = sprintf(' (press Ctrl+%c to exit)', $escape+0x40);
512 $escape = sprintf(',escape=0x%x', $escape);
513 } else {
514 $escape = '';
515 }
516
ffda963f 517 my $conf = PVE::QemuConfig->load_config ($vmid); # check if VM exists
f3e76e36
DM
518
519 my $iface = $param->{iface};
520
521 if ($iface) {
522 die "serial interface '$iface' is not configured\n" if !$conf->{$iface};
523 die "wrong serial type on interface '$iface'\n" if $conf->{$iface} ne 'socket';
524 } else {
525 foreach my $opt (qw(serial0 serial1 serial2 serial3)) {
526 if ($conf->{$opt} && ($conf->{$opt} eq 'socket')) {
527 $iface = $opt;
528 last;
529 }
530 }
531 die "unable to find a serial interface\n" if !$iface;
532 }
533
534 die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid);
535
536 my $socket = "/var/run/qemu-server/${vmid}.$iface";
537
aa320bcd 538 my $cmd = "socat UNIX-CONNECT:$socket STDIO,raw,echo=0$escape";
f3e76e36 539
aa320bcd 540 print "starting serial terminal on interface ${iface}${escapemsg}\n";
f3e76e36
DM
541
542 system($cmd);
543
544 return undef;
545 }});
546
7cd9f6d7
EK
547__PACKAGE__->register_method ({
548 name => 'importovf',
549 path => 'importovf',
550 description => "Create a new VM using parameters read from an OVF manifest",
551 parameters => {
552 additionalProperties => 0,
553 properties => {
554 vmid => get_standard_option('pve-vmid', { completion => \&PVE::Cluster::complete_next_vmid }),
555 manifest => {
556 type => 'string',
557 description => 'path to the ovf file',
558 },
559 storage => get_standard_option('pve-storage-id', {
560 description => 'Target storage ID',
561 completion => \&PVE::QemuServer::complete_storage,
562 optional => 0,
563 }),
564 format => {
565 type => 'string',
566 description => 'Target format',
567 enum => [ 'raw', 'qcow2', 'vmdk' ],
568 optional => 1,
569 },
570 dryrun => {
571 type => 'boolean',
572 description => 'Print a parsed representation of the extracted OVF parameters, but do not create a VM',
573 optional => 1,
f6306646 574 }
7cd9f6d7
EK
575 },
576 },
b533b995 577 returns => { type => 'null' },
7cd9f6d7
EK
578 code => sub {
579 my ($param) = @_;
580
581 my $vmid = PVE::Tools::extract_param($param, 'vmid');
582 my $ovf_file = PVE::Tools::extract_param($param, 'manifest');
583 my $storeid = PVE::Tools::extract_param($param, 'storage');
584 my $format = PVE::Tools::extract_param($param, 'format');
585 my $dryrun = PVE::Tools::extract_param($param, 'dryrun');
586
587 die "$ovf_file: non-existent or non-regular file\n" if (! -f $ovf_file);
588 my $storecfg = PVE::Storage::config();
589 PVE::Storage::storage_check_enabled($storecfg, $storeid);
590
591 my $parsed = PVE::QemuServer::OVF::parse_ovf($ovf_file);
592
593 if ($dryrun) {
0f80f1ab
WB
594 print to_json($parsed, { pretty => 1, canonical => 1});
595 return;
7cd9f6d7
EK
596 }
597
598 $param->{name} = $parsed->{qm}->{name} if defined($parsed->{qm}->{name});
599 $param->{memory} = $parsed->{qm}->{memory} if defined($parsed->{qm}->{memory});
600 $param->{cores} = $parsed->{qm}->{cores} if defined($parsed->{qm}->{cores});
601
602 my $importfn = sub {
603
604 PVE::Cluster::check_vmid_unused($vmid);
605
606 my $conf = $param;
607
608 eval {
609 # order matters, as do_import() will load_config() internally
610 $conf->{smbios1} = PVE::QemuServer::generate_smbios1_uuid();
611 PVE::QemuConfig->write_config($vmid, $conf);
612
613 foreach my $disk (@{ $parsed->{disks} }) {
614 my ($file, $drive) = ($disk->{backing_file}, $disk->{disk_address});
615 PVE::QemuServer::ImportDisk::do_import($file, $vmid, $storeid,
616 { drive_name => $drive, format => $format });
617 }
618
619 # reload after disks entries have been created
620 $conf = PVE::QemuConfig->load_config($vmid);
621 PVE::QemuConfig->check_lock($conf);
622 my $firstdisk = PVE::QemuServer::resolve_first_disk($conf);
623 $conf->{bootdisk} = $firstdisk if $firstdisk;
624 PVE::QemuConfig->write_config($vmid, $conf);
f6306646 625 };
7cd9f6d7
EK
626
627 my $err = $@;
628 if ($err) {
629 my $skiplock = 1;
630 eval { PVE::QemuServer::vm_destroy($storecfg, $vmid, $skiplock); };
631 die "import failed - $err";
632 }
7cd9f6d7
EK
633 };
634
635 my $wait_for_lock = 1;
5d942f5a
EK
636 PVE::QemuConfig->lock_config_full($vmid, $wait_for_lock, $importfn);
637
638 return undef;
7cd9f6d7
EK
639
640 }
641});
788a6a35
DM
642
643my $print_agent_result = sub {
644 my ($data) = @_;
645
646 my $result = $data->{result};
647 return if !defined($result);
648
649 my $class = ref($result);
650
651 if (!$class) {
652 chomp $result;
653 return if $result =~ m/^\s*$/;
654 print "$result\n";
655 return;
656 }
657
658 if (($class eq 'HASH') && !scalar(keys %$result)) { # empty hash
659 return;
660 }
661
662 print to_json($result, { pretty => 1, canonical => 1});
663};
664
f3e76e36
DM
665our $cmddef = {
666 list => [ "PVE::API2::Qemu", 'vmlist', [],
667 { node => $nodename }, sub {
668 my $vmlist = shift;
669
670 exit 0 if (!scalar(@$vmlist));
671
672 printf "%10s %-20s %-10s %-10s %12s %-10s\n",
673 qw(VMID NAME STATUS MEM(MB) BOOTDISK(GB) PID);
674
675 foreach my $rec (sort { $a->{vmid} <=> $b->{vmid} } @$vmlist) {
676 printf "%10s %-20s %-10s %-10s %12.2f %-10s\n", $rec->{vmid}, $rec->{name},
12612b09 677 $rec->{qmpstatus} || $rec->{status},
f3e76e36
DM
678 ($rec->{maxmem} || 0)/(1024*1024),
679 ($rec->{maxdisk} || 0)/(1024*1024*1024),
680 $rec->{pid}||0;
681 }
682
683
684 } ],
685
686 create => [ "PVE::API2::Qemu", 'create_vm', ['vmid'], { node => $nodename }, $upid_exit ],
687
688 destroy => [ "PVE::API2::Qemu", 'destroy_vm', ['vmid'], { node => $nodename }, $upid_exit ],
689
690 clone => [ "PVE::API2::Qemu", 'clone_vm', ['vmid', 'newid'], { node => $nodename }, $upid_exit ],
691
692 migrate => [ "PVE::API2::Qemu", 'migrate_vm', ['vmid', 'target'], { node => $nodename }, $upid_exit ],
693
694 set => [ "PVE::API2::Qemu", 'update_vm', ['vmid'], { node => $nodename } ],
695
696 resize => [ "PVE::API2::Qemu", 'resize_vm', ['vmid', 'disk', 'size'], { node => $nodename } ],
697
698 move_disk => [ "PVE::API2::Qemu", 'move_vm_disk', ['vmid', 'disk', 'storage'], { node => $nodename }, $upid_exit ],
699
700 unlink => [ "PVE::API2::Qemu", 'unlink', ['vmid'], { node => $nodename } ],
701
702 config => [ "PVE::API2::Qemu", 'vm_config', ['vmid'],
703 { node => $nodename }, sub {
704 my $config = shift;
705 foreach my $k (sort (keys %$config)) {
706 next if $k eq 'digest';
707 my $v = $config->{$k};
708 if ($k eq 'description') {
709 $v = PVE::Tools::encode_text($v);
710 }
711 print "$k: $v\n";
712 }
713 }],
714
715 pending => [ "PVE::API2::Qemu", 'vm_pending', ['vmid'],
716 { node => $nodename }, sub {
717 my $data = shift;
718 foreach my $item (sort { $a->{key} cmp $b->{key}} @$data) {
719 my $k = $item->{key};
720 next if $k eq 'digest';
721 my $v = $item->{value};
722 my $p = $item->{pending};
723 if ($k eq 'description') {
724 $v = PVE::Tools::encode_text($v) if defined($v);
725 $p = PVE::Tools::encode_text($p) if defined($p);
726 }
727 if (defined($v)) {
728 if ($item->{delete}) {
729 print "del $k: $v\n";
730 } elsif (defined($p)) {
731 print "cur $k: $v\n";
732 print "new $k: $p\n";
733 } else {
734 print "cur $k: $v\n";
735 }
736 } elsif (defined($p)) {
737 print "new $k: $p\n";
738 }
739 }
740 }],
741
742 showcmd => [ __PACKAGE__, 'showcmd', ['vmid']],
743
744 status => [ __PACKAGE__, 'status', ['vmid']],
745
746 snapshot => [ "PVE::API2::Qemu", 'snapshot', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
747
748 delsnapshot => [ "PVE::API2::Qemu", 'delsnapshot', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
749
265db461
DC
750 listsnapshot => [ "PVE::API2::Qemu", 'snapshot_list', ['vmid'], { node => $nodename },
751 sub {
752 my $res = shift;
753 foreach my $e (@$res) {
754 my $headline = $e->{description} || 'no-description';
755 $headline =~ s/\n.*//sg;
756 my $parent = $e->{parent} // 'no-parent';
757 printf("%-20s %-20s %s\n", $e->{name}, $parent, $headline);
758 }
759 }],
760
f3e76e36
DM
761 rollback => [ "PVE::API2::Qemu", 'rollback', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
762
763 template => [ "PVE::API2::Qemu", 'template', ['vmid'], { node => $nodename }],
764
765 start => [ "PVE::API2::Qemu", 'vm_start', ['vmid'], { node => $nodename } , $upid_exit ],
766
767 stop => [ "PVE::API2::Qemu", 'vm_stop', ['vmid'], { node => $nodename }, $upid_exit ],
768
769 reset => [ "PVE::API2::Qemu", 'vm_reset', ['vmid'], { node => $nodename }, $upid_exit ],
770
771 shutdown => [ "PVE::API2::Qemu", 'vm_shutdown', ['vmid'], { node => $nodename }, $upid_exit ],
772
773 suspend => [ "PVE::API2::Qemu", 'vm_suspend', ['vmid'], { node => $nodename }, $upid_exit ],
774
775 resume => [ "PVE::API2::Qemu", 'vm_resume', ['vmid'], { node => $nodename }, $upid_exit ],
776
777 sendkey => [ "PVE::API2::Qemu", 'vm_sendkey', ['vmid', 'key'], { node => $nodename } ],
778
779 vncproxy => [ __PACKAGE__, 'vncproxy', ['vmid']],
780
781 wait => [ __PACKAGE__, 'wait', ['vmid']],
782
783 unlock => [ __PACKAGE__, 'unlock', ['vmid']],
784
785 rescan => [ __PACKAGE__, 'rescan', []],
786
787 monitor => [ __PACKAGE__, 'monitor', ['vmid']],
788
ee2ff074 789 agent => [ "PVE::API2::Qemu", 'agent', ['vmid', 'command'],
788a6a35 790 { node => $nodename }, $print_agent_result ],
d1a47427 791
f3e76e36
DM
792 mtunnel => [ __PACKAGE__, 'mtunnel', []],
793
63a09370
AD
794 nbdstop => [ __PACKAGE__, 'nbdstop', ['vmid']],
795
f3e76e36 796 terminal => [ __PACKAGE__, 'terminal', ['vmid']],
8653feeb
EK
797
798 importdisk => [ __PACKAGE__, 'importdisk', ['vmid', 'source', 'storage']],
7cd9f6d7
EK
799
800 importovf => [ __PACKAGE__, 'importovf', ['vmid', 'manifest', 'storage']],
801
f3e76e36
DM
802};
803
8041;