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