1 package PVE
::API2
::Qemu
;
8 use PVE
::Tools
qw(extract_param);
9 use PVE
::Exception
qw(raise raise_param_exc);
11 use PVE
::JSONSchema
qw(get_standard_option);
15 use PVE
::RPCEnvironment
;
16 use PVE
::AccessControl
;
19 use Data
::Dumper
; # fixme: remove
21 use base
qw(PVE::RESTHandler);
23 my $opt_force_description = "Force physical removal. Without this, we simple remove the disk from the config file and create an additional configuration entry called 'unused[n]', which contains the volume ID. Unlink of unused[n] always cause physical removal.";
25 my $resolve_cdrom_alias = sub {
28 if (my $value = $param->{cdrom
}) {
29 $value .= ",media=cdrom" if $value !~ m/media=/;
30 $param->{ide2
} = $value;
31 delete $param->{cdrom
};
35 __PACKAGE__-
>register_method({
39 description
=> "Virtual machine index (per node).",
41 protected
=> 1, # qemu pid files are only readable by root
43 additionalProperties
=> 0,
45 node
=> get_standard_option
('pve-node'),
54 links
=> [ { rel
=> 'child', href
=> "{vmid}" } ],
59 my $vmstatus = PVE
::QemuServer
::vmstatus
();
61 return PVE
::RESTHandler
::hash_to_array
($vmstatus, 'vmid');
65 __PACKAGE__-
>register_method({
69 description
=> "Create or restore a virtual machine.",
73 additionalProperties
=> 0,
74 properties
=> PVE
::QemuServer
::json_config_properties
(
76 node
=> get_standard_option
('pve-node'),
77 vmid
=> get_standard_option
('pve-vmid'),
79 description
=> "The backup file.",
84 storage
=> get_standard_option
('pve-storage-id', {
85 description
=> "Default storage.",
91 description
=> "Allow to overwrite existing VM.",
101 my $rpcenv = PVE
::RPCEnvironment
::get
();
103 my $user = $rpcenv->get_user();
105 my $node = extract_param
($param, 'node');
107 my $vmid = extract_param
($param, 'vmid');
109 my $archive = extract_param
($param, 'archive');
111 my $storage = extract_param
($param, 'storage');
113 my $filename = PVE
::QemuServer
::config_file
($vmid);
115 my $storecfg = PVE
::Storage
::config
();
117 PVE
::Cluster
::check_cfs_quorum
();
120 &$resolve_cdrom_alias($param);
122 foreach my $opt (keys %$param) {
123 if (PVE
::QemuServer
::valid_drivename
($opt)) {
124 my $drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
125 raise_param_exc
({ $opt => "unable to parse drive options" }) if !$drive;
127 PVE
::QemuServer
::cleanup_drive_path
($opt, $storecfg, $drive);
128 $param->{$opt} = PVE
::QemuServer
::print_drive
($vmid, $drive);
132 PVE
::QemuServer
::add_random_macs
($param);
135 # fixme: archive eq '-' (read from stdin)
137 my $restorefn = sub {
140 die "unable to restore vm $vmid: config file already exists\n"
143 die "unable to restore vm $vmid: vm is running\n"
144 if PVE
::QemuServer
::check_running
($vmid);
146 # destroy existing data - keep empty config
147 PVE
::QemuServer
::destroy_vm
($storecfg, $vmid, 1);
151 PVE
::QemuServer
::restore_archive
($archive, $vmid, { storage
=> $storage});
154 return $rpcenv->fork_worker('qmrestore', $vmid, $user, $realcmd);
159 # second test (after locking test is accurate)
160 die "unable to create vm $vmid: config file already exists\n"
168 $vollist = PVE
::QemuServer
::create_disks
($storecfg, $vmid, $param, $storage);
170 # try to be smart about bootdisk
171 my @disks = PVE
::QemuServer
::disknames
();
173 foreach my $ds (reverse @disks) {
174 next if !$param->{$ds};
175 my $disk = PVE
::QemuServer
::parse_drive
($ds, $param->{$ds});
176 next if PVE
::QemuServer
::drive_is_cdrom
($disk);
180 if (!$param->{bootdisk
} && $firstdisk) {
181 $param->{bootdisk
} = $firstdisk;
184 PVE
::QemuServer
::create_conf_nolock
($vmid, $param);
189 foreach my $volid (@$vollist) {
190 eval { PVE
::Storage
::vdisk_free
($storecfg, $volid); };
193 die "create failed - $err";
197 return $rpcenv->fork_worker('qmcreate', $vmid, $user, $realcmd);
200 return PVE
::QemuServer
::lock_config
($vmid, $archive ?
$restorefn : $createfn);
203 __PACKAGE__-
>register_method({
208 description
=> "Directory index",
210 additionalProperties
=> 0,
212 node
=> get_standard_option
('pve-node'),
213 vmid
=> get_standard_option
('pve-vmid'),
221 subdir
=> { type
=> 'string' },
224 links
=> [ { rel
=> 'child', href
=> "{subdir}" } ],
230 { subdir
=> 'config' },
231 { subdir
=> 'status' },
232 { subdir
=> 'unlink' },
233 { subdir
=> 'vncproxy' },
234 { subdir
=> 'migrate' },
236 { subdir
=> 'rrddata' },
242 __PACKAGE__-
>register_method({
244 path
=> '{vmid}/rrd',
246 protected
=> 1, # fixme: can we avoid that?
248 path
=> '/vms/{vmid}',
249 privs
=> [ 'VM.Audit' ],
251 description
=> "Read VM RRD statistics (returns PNG)",
253 additionalProperties
=> 0,
255 node
=> get_standard_option
('pve-node'),
256 vmid
=> get_standard_option
('pve-vmid'),
258 description
=> "Specify the time frame you are interested in.",
260 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
263 description
=> "The list of datasources you want to display.",
264 type
=> 'string', format
=> 'pve-configid-list',
267 description
=> "The RRD consolidation function",
269 enum
=> [ 'AVERAGE', 'MAX' ],
277 filename
=> { type
=> 'string' },
283 return PVE
::Cluster
::create_rrd_graph
(
284 "pve2-vm/$param->{vmid}", $param->{timeframe
},
285 $param->{ds
}, $param->{cf
});
289 __PACKAGE__-
>register_method({
291 path
=> '{vmid}/rrddata',
293 protected
=> 1, # fixme: can we avoid that?
295 path
=> '/vms/{vmid}',
296 privs
=> [ 'VM.Audit' ],
298 description
=> "Read VM RRD statistics",
300 additionalProperties
=> 0,
302 node
=> get_standard_option
('pve-node'),
303 vmid
=> get_standard_option
('pve-vmid'),
305 description
=> "Specify the time frame you are interested in.",
307 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
310 description
=> "The RRD consolidation function",
312 enum
=> [ 'AVERAGE', 'MAX' ],
327 return PVE
::Cluster
::create_rrd_data
(
328 "pve2-vm/$param->{vmid}", $param->{timeframe
}, $param->{cf
});
332 __PACKAGE__-
>register_method({
334 path
=> '{vmid}/config',
337 description
=> "Get virtual machine configuration.",
339 additionalProperties
=> 0,
341 node
=> get_standard_option
('pve-node'),
342 vmid
=> get_standard_option
('pve-vmid'),
350 description
=> 'SHA1 digest of configuration file. This can be used to prevent concurrent modifications.',
357 my $conf = PVE
::QemuServer
::load_config
($param->{vmid
});
362 __PACKAGE__-
>register_method({
364 path
=> '{vmid}/config',
368 description
=> "Set virtual machine options.",
370 additionalProperties
=> 0,
371 properties
=> PVE
::QemuServer
::json_config_properties
(
373 node
=> get_standard_option
('pve-node'),
374 vmid
=> get_standard_option
('pve-vmid'),
375 skiplock
=> get_standard_option
('skiplock'),
377 type
=> 'string', format
=> 'pve-configid-list',
378 description
=> "A list of settings you want to delete.",
383 description
=> $opt_force_description,
385 requires
=> 'delete',
389 description
=> 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
395 returns
=> { type
=> 'null'},
399 my $rpcenv = PVE
::RPCEnvironment
::get
();
401 my $user = $rpcenv->get_user();
403 my $node = extract_param
($param, 'node');
405 my $vmid = extract_param
($param, 'vmid');
407 my $digest = extract_param
($param, 'digest');
409 my @paramarr = (); # used for log message
410 foreach my $key (keys %$param) {
411 push @paramarr, "-$key", $param->{$key};
414 my $skiplock = extract_param
($param, 'skiplock');
415 raise_param_exc
({ skiplock
=> "Only root may use this option." })
416 if $skiplock && $user ne 'root@pam';
418 my $delete = extract_param
($param, 'delete');
419 my $force = extract_param
($param, 'force');
421 die "no options specified\n" if !$delete && !scalar(keys %$param);
423 my $storecfg = PVE
::Storage
::config
();
425 &$resolve_cdrom_alias($param);
430 foreach my $opt (keys %$param) {
431 if (PVE
::QemuServer
::valid_drivename
($opt)) {
432 my $drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
433 raise_param_exc
({ $opt => "unable to parse drive options" }) if !$drive;
434 if ($drive->{file
} eq 'eject') {
436 delete $param->{$opt};
440 PVE
::QemuServer
::cleanup_drive_path
($opt, $storecfg, $drive);
441 $param->{$opt} = PVE
::QemuServer
::print_drive
($vmid, $drive);
443 if (PVE
::QemuServer
::drive_is_cdrom
($drive)) {
444 $cdchange->{$opt} = PVE
::QemuServer
::get_iso_path
($storecfg, $vmid, $drive->{file
});
449 foreach my $opt (PVE
::Tools
::split_list
($delete)) {
450 $opt = 'ide2' if $opt eq 'cdrom';
451 die "you can't use '-$opt' and '-delete $opt' at the same time\n"
452 if defined($param->{$opt});
455 PVE
::QemuServer
::add_random_macs
($param);
461 my $conf = PVE
::QemuServer
::load_config
($vmid);
463 die "checksum missmatch (file change by other user?)\n"
464 if $digest && $digest ne $conf->{digest
};
466 PVE
::QemuServer
::check_lock
($conf) if !$skiplock;
468 PVE
::Cluster
::log_msg
('info', $user, "update VM $vmid: " . join (' ', @paramarr));
470 foreach my $opt (keys %$eject) {
472 my $drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
473 $cdchange->{$opt} = undef if PVE
::QemuServer
::drive_is_cdrom
($drive);
475 raise_param_exc
({ $opt => "eject failed - drive does not exist." });
479 foreach my $opt (keys %$param) {
480 next if !PVE
::QemuServer
::valid_drivename
($opt);
481 next if !$conf->{$opt};
482 my $old_drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
483 next if PVE
::QemuServer
::drive_is_cdrom
($old_drive);
484 my $new_drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
485 if ($new_drive->{file
} ne $old_drive->{file
}) {
487 eval { ($path, $owner) = PVE
::Storage
::path
($storecfg, $old_drive->{file
}); };
488 if ($owner && ($owner == $vmid)) {
489 PVE
::QemuServer
::add_unused_volume
($conf, $param, $old_drive->{file
});
496 foreach my $opt (PVE
::Tools
::split_list
($delete)) {
497 $opt = 'ide2' if $opt eq 'cdrom';
498 if (!PVE
::QemuServer
::option_exists
($opt)) {
499 raise_param_exc
({ delete => "unknown option '$opt'" });
501 next if !defined($conf->{$opt});
502 if (PVE
::QemuServer
::valid_drivename
($opt)) {
503 PVE
::QemuServer
::vm_devicedel
($vmid, $conf, $opt);
504 my $drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
505 if (PVE
::QemuServer
::drive_is_cdrom
($drive)) {
506 $cdchange->{$opt} = undef;
508 my $volid = $drive->{file
};
510 if ($volid !~ m
|^/|) {
512 eval { ($path, $owner) = PVE
::Storage
::path
($storecfg, $volid); };
513 if ($owner && ($owner == $vmid)) {
515 push @$vollist, $volid;
517 PVE
::QemuServer
::add_unused_volume
($conf, $param, $volid);
522 } elsif ($opt =~ m/^unused/) {
523 push @$vollist, $conf->{$opt};
529 PVE
::QemuServer
::create_disks
($storecfg, $vmid, $param, $conf);
531 PVE
::QemuServer
::change_config_nolock
($vmid, $param, $unset, 1);
533 return if !PVE
::QemuServer
::check_running
($vmid);
535 foreach my $opt (keys %$cdchange) {
536 my $qdn = PVE
::QemuServer
::qemu_drive_name
($opt, 'cdrom');
537 my $path = $cdchange->{$opt};
538 PVE
::QemuServer
::vm_monitor_command
($vmid, "eject $qdn", 0);
539 PVE
::QemuServer
::vm_monitor_command
($vmid, "change $qdn \"$path\"", 0) if $path;
543 PVE::QemuServer::lock_config($vmid, $updatefn);
545 foreach my $volid (@$vollist) {
546 eval { PVE::Storage::vdisk_free($storecfg, $volid); };
555 __PACKAGE__->register_method({
556 name => 'destroy_vm',
561 description => "Destroy the vm
(also
delete all used
/owned volumes
).",
563 additionalProperties => 0,
565 node => get_standard_option('pve-node'),
566 vmid => get_standard_option('pve-vmid'),
567 skiplock => get_standard_option('skiplock'),
576 my $rpcenv = PVE::RPCEnvironment::get();
578 my $user = $rpcenv->get_user();
580 my $vmid = $param->{vmid};
582 my $skiplock = $param->{skiplock};
583 raise_param_exc({ skiplock => "Only root may
use this option
." })
584 if $skiplock && $user ne 'root@pam';
587 my $conf = PVE::QemuServer::load_config($vmid);
589 my $storecfg = PVE::Storage::config();
592 PVE::QemuServer::vm_destroy($storecfg, $vmid, $skiplock);
595 return $rpcenv->fork_worker('qmdestroy', $vmid, $user, $realcmd);
598 __PACKAGE__->register_method({
600 path => '{vmid}/unlink',
604 description => "Unlink
/delete disk images
.",
606 additionalProperties => 0,
608 node => get_standard_option('pve-node'),
609 vmid => get_standard_option('pve-vmid'),
611 type => 'string', format => 'pve-configid-list',
612 description => "A list of disk IDs you want to
delete.",
616 description => $opt_force_description,
621 returns => { type => 'null'},
625 $param->{delete} = extract_param($param, 'idlist');
627 __PACKAGE__->update_vm($param);
634 __PACKAGE__->register_method({
636 path => '{vmid}/vncproxy',
640 path => '/vms/{vmid}',
641 privs => [ 'VM.Console' ],
643 description => "Creates a TCP VNC proxy connections
.",
645 additionalProperties => 0,
647 node => get_standard_option('pve-node'),
648 vmid => get_standard_option('pve-vmid'),
652 additionalProperties => 0,
654 user => { type => 'string' },
655 ticket => { type => 'string' },
656 cert => { type => 'string' },
657 port => { type => 'integer' },
658 upid => { type => 'string' },
664 my $rpcenv = PVE::RPCEnvironment::get();
666 my $user = $rpcenv->get_user();
667 my $ticket = PVE::AccessControl::assemble_ticket($user);
669 my $vmid = $param->{vmid};
670 my $node = $param->{node};
672 $sslcert = PVE::Tools::file_get_contents("/etc/pve
/pve-root-ca
.pem
", 8192)
675 my $port = PVE::Tools::next_vnc_port();
679 if ($node ne PVE::INotify::nodename()) {
680 $remip = PVE::Cluster::remote_node_ip($node);
683 # NOTE: kvm VNC traffic is already TLS encrypted,
684 # so we select the fastest chipher here (or 'none'?)
685 my $remcmd = $remip ? ['/usr/bin/ssh', '-T', '-o', 'BatchMode=yes',
686 '-c', 'blowfish-cbc', $remip] : [];
693 syslog('info', "starting vnc proxy
$upid\n");
695 my $qmcmd = [@$remcmd, "/usr/sbin
/qm
", 'vncproxy', $vmid];
697 my $qmstr = join(' ', @$qmcmd);
699 # also redirect stderr (else we get RFB protocol errors)
700 my $cmd = ['/bin/nc', '-l', '-p', $port, '-w', $timeout, '-c', "$qmstr 2>/dev/null
"];
702 PVE::Tools::run_command($cmd);
707 my $upid = $rpcenv->fork_worker('vncproxy', $vmid, $user, $realcmd);
718 __PACKAGE__->register_method({
720 path => '{vmid}/status',
723 description => "Directory
index",
725 additionalProperties => 0,
727 node => get_standard_option('pve-node'),
728 vmid => get_standard_option('pve-vmid'),
736 subdir => { type => 'string' },
739 links => [ { rel => 'child', href => "{subdir
}" } ],
745 my $conf = PVE::QemuServer::load_config($param->{vmid});
748 { subdir => 'current' },
749 { subdir => 'start' },
750 { subdir => 'stop' },
756 __PACKAGE__->register_method({
758 path => '{vmid}/status/current',
761 protected => 1, # qemu pid files are only readable by root
762 description => "Get virtual machine status
.",
764 additionalProperties => 0,
766 node => get_standard_option('pve-node'),
767 vmid => get_standard_option('pve-vmid'),
770 returns => { type => 'object' },
775 my $conf = PVE::QemuServer::load_config($param->{vmid});
777 my $vmstatus = PVE::QemuServer::vmstatus($param->{vmid});
779 return $vmstatus->{$param->{vmid}};
782 __PACKAGE__->register_method({
784 path => '{vmid}/status/start',
788 description => "Start virtual machine
.",
790 additionalProperties => 0,
792 node => get_standard_option('pve-node'),
793 vmid => get_standard_option('pve-vmid'),
794 skiplock => get_standard_option('skiplock'),
795 stateuri => get_standard_option('pve-qm-stateuri'),
804 my $rpcenv = PVE::RPCEnvironment::get();
806 my $user = $rpcenv->get_user();
808 my $node = extract_param($param, 'node');
810 my $vmid = extract_param($param, 'vmid');
812 my $stateuri = extract_param($param, 'stateuri');
813 raise_param_exc({ stateuri => "Only root may
use this option
." })
814 if $stateuri && $user ne 'root@pam';
816 my $skiplock = extract_param($param, 'skiplock');
817 raise_param_exc({ skiplock => "Only root may
use this option
." })
818 if $skiplock && $user ne 'root@pam';
820 my $storecfg = PVE::Storage::config();
825 syslog('info', "start VM
$vmid: $upid\n");
827 PVE::QemuServer::vm_start($storecfg, $vmid, $stateuri, $skiplock);
832 return $rpcenv->fork_worker('qmstart', $vmid, $user, $realcmd);
835 __PACKAGE__->register_method({
837 path => '{vmid}/status/stop',
841 description => "Stop virtual machine
.",
843 additionalProperties => 0,
845 node => get_standard_option('pve-node'),
846 vmid => get_standard_option('pve-vmid'),
847 skiplock => get_standard_option('skiplock'),
849 description => "Wait maximal timeout seconds
.",
862 my $rpcenv = PVE::RPCEnvironment::get();
864 my $user = $rpcenv->get_user();
866 my $node = extract_param($param, 'node');
868 my $vmid = extract_param($param, 'vmid');
870 my $skiplock = extract_param($param, 'skiplock');
871 raise_param_exc({ skiplock => "Only root may
use this option
." })
872 if $skiplock && $user ne 'root@pam';
877 syslog('info', "stop VM
$vmid: $upid\n");
879 PVE::QemuServer::vm_stop($vmid, $skiplock);
881 my $pid = PVE::QemuServer::check_running ($vmid);
883 if ($pid && $param->{timeout}) {
884 print "waiting
until VM
$vmid stopps
(PID
$pid)\n";
887 while (($count < $param->{timeout}) &&
888 PVE::QemuServer::check_running($vmid)) {
893 die "wait failed
- got timeout
\n" if PVE::QemuServer::check_running($vmid);
899 return $rpcenv->fork_worker('qmstop', $vmid, $user, $realcmd);
902 __PACKAGE__->register_method({
904 path => '{vmid}/status/reset',
908 description => "Reset virtual machine
.",
910 additionalProperties => 0,
912 node => get_standard_option('pve-node'),
913 vmid => get_standard_option('pve-vmid'),
914 skiplock => get_standard_option('skiplock'),
923 my $rpcenv = PVE::RPCEnvironment::get();
925 my $user = $rpcenv->get_user();
927 my $node = extract_param($param, 'node');
929 my $vmid = extract_param($param, 'vmid');
931 my $skiplock = extract_param($param, 'skiplock');
932 raise_param_exc({ skiplock => "Only root may
use this option
." })
933 if $skiplock && $user ne 'root@pam';
938 syslog('info', "reset VM
$vmid: $upid\n");
940 PVE::QemuServer::vm_reset($vmid, $skiplock);
945 return $rpcenv->fork_worker('qmreset', $vmid, $user, $realcmd);
948 __PACKAGE__->register_method({
949 name => 'vm_shutdown',
950 path => '{vmid}/status/shutdown',
954 description => "Shutdown virtual machine
.",
956 additionalProperties => 0,
958 node => get_standard_option('pve-node'),
959 vmid => get_standard_option('pve-vmid'),
960 skiplock => get_standard_option('skiplock'),
962 description => "Wait maximal timeout seconds
.",
975 my $rpcenv = PVE::RPCEnvironment::get();
977 my $user = $rpcenv->get_user();
979 my $node = extract_param($param, 'node');
981 my $vmid = extract_param($param, 'vmid');
983 my $skiplock = extract_param($param, 'skiplock');
984 raise_param_exc({ skiplock => "Only root may
use this option
." })
985 if $skiplock && $user ne 'root@pam';
990 syslog('info', "shutdown VM
$vmid: $upid\n");
992 PVE::QemuServer::vm_shutdown($vmid, $skiplock);
994 my $pid = PVE::QemuServer::check_running ($vmid);
996 if ($pid && $param->{timeout}) {
997 print "waiting
until VM
$vmid stopps
(PID
$pid)\n";
1000 while (($count < $param->{timeout}) &&
1001 PVE::QemuServer::check_running($vmid)) {
1006 die "wait failed
- got timeout
\n" if PVE::QemuServer::check_running($vmid);
1012 return $rpcenv->fork_worker('qmshutdown', $vmid, $user, $realcmd);
1015 __PACKAGE__->register_method({
1016 name => 'vm_suspend',
1017 path => '{vmid}/status/suspend',
1021 description => "Suspend virtual machine
.",
1023 additionalProperties => 0,
1025 node => get_standard_option('pve-node'),
1026 vmid => get_standard_option('pve-vmid'),
1027 skiplock => get_standard_option('skiplock'),
1036 my $rpcenv = PVE::RPCEnvironment::get();
1038 my $user = $rpcenv->get_user();
1040 my $node = extract_param($param, 'node');
1042 my $vmid = extract_param($param, 'vmid');
1044 my $skiplock = extract_param($param, 'skiplock');
1045 raise_param_exc({ skiplock => "Only root may
use this option
." })
1046 if $skiplock && $user ne 'root@pam';
1051 syslog('info', "suspend VM
$vmid: $upid\n");
1053 PVE::QemuServer::vm_suspend($vmid, $skiplock);
1058 return $rpcenv->fork_worker('qmsuspend', $vmid, $user, $realcmd);
1061 __PACKAGE__->register_method({
1062 name => 'vm_resume',
1063 path => '{vmid}/status/resume',
1067 description => "Resume virtual machine
.",
1069 additionalProperties => 0,
1071 node => get_standard_option('pve-node'),
1072 vmid => get_standard_option('pve-vmid'),
1073 skiplock => get_standard_option('skiplock'),
1082 my $rpcenv = PVE::RPCEnvironment::get();
1084 my $user = $rpcenv->get_user();
1086 my $node = extract_param($param, 'node');
1088 my $vmid = extract_param($param, 'vmid');
1090 my $skiplock = extract_param($param, 'skiplock');
1091 raise_param_exc({ skiplock => "Only root may
use this option
." })
1092 if $skiplock && $user ne 'root@pam';
1097 syslog('info', "resume VM
$vmid: $upid\n");
1099 PVE::QemuServer::vm_resume($vmid, $skiplock);
1104 return $rpcenv->fork_worker('qmresume', $vmid, $user, $realcmd);
1107 __PACKAGE__->register_method({
1108 name => 'vm_sendkey',
1109 path => '{vmid}/sendkey',
1113 description => "Send key event to virtual machine
.",
1115 additionalProperties => 0,
1117 node => get_standard_option('pve-node'),
1118 vmid => get_standard_option('pve-vmid'),
1119 skiplock => get_standard_option('skiplock'),
1121 description => "The key
(qemu monitor encoding
).",
1126 returns => { type => 'null'},
1130 my $rpcenv = PVE::RPCEnvironment::get();
1132 my $user = $rpcenv->get_user();
1134 my $node = extract_param($param, 'node');
1136 my $vmid = extract_param($param, 'vmid');
1138 my $skiplock = extract_param($param, 'skiplock');
1139 raise_param_exc({ skiplock => "Only root may
use this option
." })
1140 if $skiplock && $user ne 'root@pam';
1142 PVE::QemuServer::vm_sendkey($vmid, $skiplock, $param->{key});
1147 __PACKAGE__->register_method({
1148 name => 'migrate_vm',
1149 path => '{vmid}/migrate',
1153 description => "Migrate virtual machine
. Creates a new migration task
.",
1155 additionalProperties => 0,
1157 node => get_standard_option('pve-node'),
1158 vmid => get_standard_option('pve-vmid'),
1159 target => get_standard_option('pve-node', { description => "Target node
." }),
1162 description => "Use online
/live migration
.",
1167 description => "Allow to migrate VMs which
use local devices
. Only root may
use this option
.",
1174 description => "the task ID
.",
1179 my $rpcenv = PVE::RPCEnvironment::get();
1181 my $user = $rpcenv->get_user();
1183 my $target = extract_param($param, 'target');
1185 my $localnode = PVE::INotify::nodename();
1186 raise_param_exc({ target => "target
is local node
."}) if $target eq $localnode;
1188 PVE::Cluster::check_cfs_quorum();
1190 PVE::Cluster::check_node_exists($target);
1192 my $targetip = PVE::Cluster::remote_node_ip($target);
1194 my $vmid = extract_param($param, 'vmid');
1196 raise_param_exc({ force => "Only root may
use this option
." }) if $user ne 'root@pam';
1199 PVE::QemuServer::load_config($vmid);
1201 # try to detect errors early
1202 if (PVE::QemuServer::check_running($vmid)) {
1203 die "cant migrate running VM without
--online
\n"
1204 if !$param->{online};
1210 PVE::QemuMigrate::migrate($target, $targetip, $vmid, $param->{online}, $param->{force});
1213 my $upid = $rpcenv->fork_worker('qmigrate', $vmid, $user, $realcmd);