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 new 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'),
86 my $rpcenv = PVE
::RPCEnvironment
::get
();
88 my $user = $rpcenv->get_user();
90 my $node = extract_param
($param, 'node');
94 my $vmid = extract_param
($param, 'vmid');
96 my $filename = PVE
::QemuServer
::config_file
($vmid);
97 # first test (befor locking)
98 die "unable to create vm $vmid: config file already exists\n"
101 my $storecfg = PVE
::Storage
::config
();
103 &$resolve_cdrom_alias($param);
105 foreach my $opt (keys %$param) {
106 if (PVE
::QemuServer
::valid_drivename
($opt)) {
107 my $drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
108 raise_param_exc
({ $opt => "unable to parse drive options" }) if !$drive;
110 PVE
::QemuServer
::cleanup_drive_path
($opt, $storecfg, $drive);
111 $param->{$opt} = PVE
::QemuServer
::print_drive
($vmid, $drive);
115 PVE
::QemuServer
::add_random_macs
($param);
119 # second test (after locking test is accurate)
120 die "unable to create vm $vmid: config file already exists\n"
128 $vollist = PVE
::QemuServer
::create_disks
($storecfg, $vmid, $param);
130 # try to be smart about bootdisk
131 my @disks = PVE
::QemuServer
::disknames
();
133 foreach my $ds (reverse @disks) {
134 next if !$param->{$ds};
135 my $disk = PVE
::QemuServer
::parse_drive
($ds, $param->{$ds});
136 next if PVE
::QemuServer
::drive_is_cdrom
($disk);
140 if (!$param->{bootdisk
} && $firstdisk) {
141 $param->{bootdisk
} = $firstdisk;
144 PVE
::QemuServer
::create_conf_nolock
($vmid, $param);
149 foreach my $volid (@$vollist) {
150 eval { PVE
::Storage
::vdisk_free
($storecfg, $volid); };
153 die "create failed - $err";
157 return $rpcenv->fork_worker('qmcreate', $vmid, $user, $realcmd);
160 return PVE
::QemuServer
::lock_config
($vmid, $createfn);
163 __PACKAGE__-
>register_method({
168 description
=> "Directory index",
170 additionalProperties
=> 0,
172 node
=> get_standard_option
('pve-node'),
173 vmid
=> get_standard_option
('pve-vmid'),
181 subdir
=> { type
=> 'string' },
184 links
=> [ { rel
=> 'child', href
=> "{subdir}" } ],
190 { subdir
=> 'config' },
191 { subdir
=> 'status' },
192 { subdir
=> 'unlink' },
193 { subdir
=> 'vncproxy' },
194 { subdir
=> 'migrate' },
196 { subdir
=> 'rrddata' },
202 __PACKAGE__-
>register_method({
204 path
=> '{vmid}/rrd',
206 protected
=> 1, # fixme: can we avoid that?
208 path
=> '/vms/{vmid}',
209 privs
=> [ 'VM.Audit' ],
211 description
=> "Read VM RRD statistics (returns PNG)",
213 additionalProperties
=> 0,
215 node
=> get_standard_option
('pve-node'),
216 vmid
=> get_standard_option
('pve-vmid'),
218 description
=> "Specify the time frame you are interested in.",
220 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
223 description
=> "The list of datasources you want to display.",
224 type
=> 'string', format
=> 'pve-configid-list',
227 description
=> "The RRD consolidation function",
229 enum
=> [ 'AVERAGE', 'MAX' ],
237 filename
=> { type
=> 'string' },
243 return PVE
::Cluster
::create_rrd_graph
(
244 "pve2-vm/$param->{vmid}", $param->{timeframe
},
245 $param->{ds
}, $param->{cf
});
249 __PACKAGE__-
>register_method({
251 path
=> '{vmid}/rrddata',
253 protected
=> 1, # fixme: can we avoid that?
255 path
=> '/vms/{vmid}',
256 privs
=> [ 'VM.Audit' ],
258 description
=> "Read VM RRD statistics",
260 additionalProperties
=> 0,
262 node
=> get_standard_option
('pve-node'),
263 vmid
=> get_standard_option
('pve-vmid'),
265 description
=> "Specify the time frame you are interested in.",
267 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
270 description
=> "The RRD consolidation function",
272 enum
=> [ 'AVERAGE', 'MAX' ],
287 return PVE
::Cluster
::create_rrd_data
(
288 "pve2-vm/$param->{vmid}", $param->{timeframe
}, $param->{cf
});
292 __PACKAGE__-
>register_method({
294 path
=> '{vmid}/config',
297 description
=> "Get virtual machine configuration.",
299 additionalProperties
=> 0,
301 node
=> get_standard_option
('pve-node'),
302 vmid
=> get_standard_option
('pve-vmid'),
310 description
=> 'SHA1 digest of configuration file. This can be used to prevent concurrent modifications.',
317 my $conf = PVE
::QemuServer
::load_config
($param->{vmid
});
322 __PACKAGE__-
>register_method({
324 path
=> '{vmid}/config',
328 description
=> "Set virtual machine options.",
330 additionalProperties
=> 0,
331 properties
=> PVE
::QemuServer
::json_config_properties
(
333 node
=> get_standard_option
('pve-node'),
334 vmid
=> get_standard_option
('pve-vmid'),
335 skiplock
=> get_standard_option
('skiplock'),
337 type
=> 'string', format
=> 'pve-configid-list',
338 description
=> "A list of settings you want to delete.",
343 description
=> $opt_force_description,
345 requires
=> 'delete',
349 description
=> 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
355 returns
=> { type
=> 'null'},
359 my $rpcenv = PVE
::RPCEnvironment
::get
();
361 my $user = $rpcenv->get_user();
363 my $node = extract_param
($param, 'node');
365 my $vmid = extract_param
($param, 'vmid');
367 my $digest = extract_param
($param, 'digest');
369 my @paramarr = (); # used for log message
370 foreach my $key (keys %$param) {
371 push @paramarr, "-$key", $param->{$key};
374 my $skiplock = extract_param
($param, 'skiplock');
375 raise_param_exc
({ skiplock
=> "Only root may use this option." })
376 if $skiplock && $user ne 'root@pam';
378 my $delete = extract_param
($param, 'delete');
379 my $force = extract_param
($param, 'force');
381 die "no options specified\n" if !$delete && !scalar(keys %$param);
383 my $storecfg = PVE
::Storage
::config
();
385 &$resolve_cdrom_alias($param);
390 foreach my $opt (keys %$param) {
391 if (PVE
::QemuServer
::valid_drivename
($opt)) {
392 my $drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
393 raise_param_exc
({ $opt => "unable to parse drive options" }) if !$drive;
394 if ($drive->{file
} eq 'eject') {
396 delete $param->{$opt};
400 PVE
::QemuServer
::cleanup_drive_path
($opt, $storecfg, $drive);
401 $param->{$opt} = PVE
::QemuServer
::print_drive
($vmid, $drive);
403 if (PVE
::QemuServer
::drive_is_cdrom
($drive)) {
404 $cdchange->{$opt} = PVE
::QemuServer
::get_iso_path
($storecfg, $vmid, $drive->{file
});
409 foreach my $opt (PVE
::Tools
::split_list
($delete)) {
410 $opt = 'ide2' if $opt eq 'cdrom';
411 die "you can't use '-$opt' and '-delete $opt' at the same time\n"
412 if defined($param->{$opt});
415 PVE
::QemuServer
::add_random_macs
($param);
421 my $conf = PVE
::QemuServer
::load_config
($vmid);
423 die "checksum missmatch (file change by other user?)\n"
424 if $digest && $digest ne $conf->{digest
};
426 PVE
::QemuServer
::check_lock
($conf) if !$skiplock;
428 PVE
::Cluster
::log_msg
('info', $user, "update VM $vmid: " . join (' ', @paramarr));
430 foreach my $opt (keys %$eject) {
432 my $drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
433 $cdchange->{$opt} = undef if PVE
::QemuServer
::drive_is_cdrom
($drive);
435 raise_param_exc
({ $opt => "eject failed - drive does not exist." });
439 foreach my $opt (keys %$param) {
440 next if !PVE
::QemuServer
::valid_drivename
($opt);
441 next if !$conf->{$opt};
442 my $old_drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
443 next if PVE
::QemuServer
::drive_is_cdrom
($old_drive);
444 my $new_drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
445 if ($new_drive->{file
} ne $old_drive->{file
}) {
447 eval { ($path, $owner) = PVE
::Storage
::path
($storecfg, $old_drive->{file
}); };
448 if ($owner && ($owner == $vmid)) {
449 PVE
::QemuServer
::add_unused_volume
($conf, $param, $old_drive->{file
});
456 foreach my $opt (PVE
::Tools
::split_list
($delete)) {
457 $opt = 'ide2' if $opt eq 'cdrom';
458 if (!PVE
::QemuServer
::option_exists
($opt)) {
459 raise_param_exc
({ delete => "unknown option '$opt'" });
461 next if !defined($conf->{$opt});
462 if (PVE
::QemuServer
::valid_drivename
($opt)) {
463 PVE
::QemuServer
::vm_devicedel
($vmid,$opt);
464 my $drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
465 if (PVE
::QemuServer
::drive_is_cdrom
($drive)) {
466 $cdchange->{$opt} = undef;
468 my $volid = $drive->{file
};
470 if ($volid !~ m
|^/|) {
472 eval { ($path, $owner) = PVE
::Storage
::path
($storecfg, $volid); };
473 if ($owner && ($owner == $vmid)) {
475 push @$vollist, $volid;
477 PVE
::QemuServer
::add_unused_volume
($conf, $param, $volid);
482 } elsif ($opt =~ m/^unused/) {
483 push @$vollist, $conf->{$opt};
489 PVE
::QemuServer
::create_disks
($storecfg, $vmid, $param);
491 PVE
::QemuServer
::change_config_nolock
($vmid, $param, $unset, 1);
493 return if !PVE
::QemuServer
::check_running
($vmid);
495 foreach my $opt (keys %$cdchange) {
496 my $qdn = PVE
::QemuServer
::qemu_drive_name
($opt, 'cdrom');
497 my $path = $cdchange->{$opt};
498 PVE
::QemuServer
::vm_monitor_command
($vmid, "eject $qdn", 0);
499 PVE
::QemuServer
::vm_monitor_command
($vmid, "change $qdn \"$path\"", 0) if $path;
503 PVE::QemuServer::lock_config($vmid, $updatefn);
505 foreach my $volid (@$vollist) {
506 eval { PVE::Storage::vdisk_free($storecfg, $volid); };
515 __PACKAGE__->register_method({
516 name => 'destroy_vm',
521 description => "Destroy the vm
(also
delete all used
/owned volumes
).",
523 additionalProperties => 0,
525 node => get_standard_option('pve-node'),
526 vmid => get_standard_option('pve-vmid'),
527 skiplock => get_standard_option('skiplock'),
536 my $rpcenv = PVE::RPCEnvironment::get();
538 my $user = $rpcenv->get_user();
540 my $vmid = $param->{vmid};
542 my $skiplock = $param->{skiplock};
543 raise_param_exc({ skiplock => "Only root may
use this option
." })
544 if $skiplock && $user ne 'root@pam';
547 my $conf = PVE::QemuServer::load_config($vmid);
549 my $storecfg = PVE::Storage::config();
552 PVE::QemuServer::vm_destroy($storecfg, $vmid, $skiplock);
555 return $rpcenv->fork_worker('qmdestroy', $vmid, $user, $realcmd);
558 __PACKAGE__->register_method({
560 path => '{vmid}/unlink',
564 description => "Unlink
/delete disk images
.",
566 additionalProperties => 0,
568 node => get_standard_option('pve-node'),
569 vmid => get_standard_option('pve-vmid'),
571 type => 'string', format => 'pve-configid-list',
572 description => "A list of disk IDs you want to
delete.",
576 description => $opt_force_description,
581 returns => { type => 'null'},
585 $param->{delete} = extract_param($param, 'idlist');
587 __PACKAGE__->update_vm($param);
594 __PACKAGE__->register_method({
596 path => '{vmid}/vncproxy',
600 path => '/vms/{vmid}',
601 privs => [ 'VM.Console' ],
603 description => "Creates a TCP VNC proxy connections
.",
605 additionalProperties => 0,
607 node => get_standard_option('pve-node'),
608 vmid => get_standard_option('pve-vmid'),
612 additionalProperties => 0,
614 user => { type => 'string' },
615 ticket => { type => 'string' },
616 cert => { type => 'string' },
617 port => { type => 'integer' },
618 upid => { type => 'string' },
624 my $rpcenv = PVE::RPCEnvironment::get();
626 my $user = $rpcenv->get_user();
627 my $ticket = PVE::AccessControl::assemble_ticket($user);
629 my $vmid = $param->{vmid};
630 my $node = $param->{node};
632 $sslcert = PVE::Tools::file_get_contents("/etc/pve
/pve-root-ca
.pem
", 8192)
635 my $port = PVE::Tools::next_vnc_port();
639 if ($node ne PVE::INotify::nodename()) {
640 $remip = PVE::Cluster::remote_node_ip($node);
643 # NOTE: kvm VNC traffic is already TLS encrypted,
644 # so we select the fastest chipher here (or 'none'?)
645 my $remcmd = $remip ? ['/usr/bin/ssh', '-T', '-o', 'BatchMode=yes',
646 '-c', 'blowfish-cbc', $remip] : [];
653 syslog('info', "starting vnc proxy
$upid\n");
655 my $qmcmd = [@$remcmd, "/usr/sbin
/qm
", 'vncproxy', $vmid];
657 my $qmstr = join(' ', @$qmcmd);
659 # also redirect stderr (else we get RFB protocol errors)
660 my $cmd = ['/bin/nc', '-l', '-p', $port, '-w', $timeout, '-c', "$qmstr 2>/dev/null
"];
662 PVE::Tools::run_command($cmd);
667 my $upid = $rpcenv->fork_worker('vncproxy', $vmid, $user, $realcmd);
678 __PACKAGE__->register_method({
680 path => '{vmid}/status',
683 description => "Directory
index",
685 additionalProperties => 0,
687 node => get_standard_option('pve-node'),
688 vmid => get_standard_option('pve-vmid'),
696 subdir => { type => 'string' },
699 links => [ { rel => 'child', href => "{subdir
}" } ],
705 my $conf = PVE::QemuServer::load_config($param->{vmid});
708 { subdir => 'current' },
709 { subdir => 'start' },
710 { subdir => 'stop' },
716 __PACKAGE__->register_method({
718 path => '{vmid}/status/current',
721 protected => 1, # qemu pid files are only readable by root
722 description => "Get virtual machine status
.",
724 additionalProperties => 0,
726 node => get_standard_option('pve-node'),
727 vmid => get_standard_option('pve-vmid'),
730 returns => { type => 'object' },
735 my $conf = PVE::QemuServer::load_config($param->{vmid});
737 my $vmstatus = PVE::QemuServer::vmstatus($param->{vmid});
739 return $vmstatus->{$param->{vmid}};
742 __PACKAGE__->register_method({
744 path => '{vmid}/status/start',
748 description => "Start virtual machine
.",
750 additionalProperties => 0,
752 node => get_standard_option('pve-node'),
753 vmid => get_standard_option('pve-vmid'),
754 skiplock => get_standard_option('skiplock'),
755 stateuri => get_standard_option('pve-qm-stateuri'),
764 my $rpcenv = PVE::RPCEnvironment::get();
766 my $user = $rpcenv->get_user();
768 my $node = extract_param($param, 'node');
770 my $vmid = extract_param($param, 'vmid');
772 my $stateuri = extract_param($param, 'stateuri');
773 raise_param_exc({ stateuri => "Only root may
use this option
." })
774 if $stateuri && $user ne 'root@pam';
776 my $skiplock = extract_param($param, 'skiplock');
777 raise_param_exc({ skiplock => "Only root may
use this option
." })
778 if $skiplock && $user ne 'root@pam';
780 my $storecfg = PVE::Storage::config();
785 syslog('info', "start VM
$vmid: $upid\n");
787 PVE::QemuServer::vm_start($storecfg, $vmid, $stateuri, $skiplock);
792 return $rpcenv->fork_worker('qmstart', $vmid, $user, $realcmd);
795 __PACKAGE__->register_method({
797 path => '{vmid}/status/stop',
801 description => "Stop virtual machine
.",
803 additionalProperties => 0,
805 node => get_standard_option('pve-node'),
806 vmid => get_standard_option('pve-vmid'),
807 skiplock => get_standard_option('skiplock'),
809 description => "Wait maximal timeout seconds
.",
822 my $rpcenv = PVE::RPCEnvironment::get();
824 my $user = $rpcenv->get_user();
826 my $node = extract_param($param, 'node');
828 my $vmid = extract_param($param, 'vmid');
830 my $skiplock = extract_param($param, 'skiplock');
831 raise_param_exc({ skiplock => "Only root may
use this option
." })
832 if $skiplock && $user ne 'root@pam';
837 syslog('info', "stop VM
$vmid: $upid\n");
839 PVE::QemuServer::vm_stop($vmid, $skiplock);
841 my $pid = PVE::QemuServer::check_running ($vmid);
843 if ($pid && $param->{timeout}) {
844 print "waiting
until VM
$vmid stopps
(PID
$pid)\n";
847 while (($count < $param->{timeout}) &&
848 PVE::QemuServer::check_running($vmid)) {
853 die "wait failed
- got timeout
\n" if PVE::QemuServer::check_running($vmid);
859 return $rpcenv->fork_worker('qmstop', $vmid, $user, $realcmd);
862 __PACKAGE__->register_method({
864 path => '{vmid}/status/reset',
868 description => "Reset virtual machine
.",
870 additionalProperties => 0,
872 node => get_standard_option('pve-node'),
873 vmid => get_standard_option('pve-vmid'),
874 skiplock => get_standard_option('skiplock'),
883 my $rpcenv = PVE::RPCEnvironment::get();
885 my $user = $rpcenv->get_user();
887 my $node = extract_param($param, 'node');
889 my $vmid = extract_param($param, 'vmid');
891 my $skiplock = extract_param($param, 'skiplock');
892 raise_param_exc({ skiplock => "Only root may
use this option
." })
893 if $skiplock && $user ne 'root@pam';
898 syslog('info', "reset VM
$vmid: $upid\n");
900 PVE::QemuServer::vm_reset($vmid, $skiplock);
905 return $rpcenv->fork_worker('qmreset', $vmid, $user, $realcmd);
908 __PACKAGE__->register_method({
909 name => 'vm_shutdown',
910 path => '{vmid}/status/shutdown',
914 description => "Shutdown virtual machine
.",
916 additionalProperties => 0,
918 node => get_standard_option('pve-node'),
919 vmid => get_standard_option('pve-vmid'),
920 skiplock => get_standard_option('skiplock'),
922 description => "Wait maximal timeout seconds
.",
935 my $rpcenv = PVE::RPCEnvironment::get();
937 my $user = $rpcenv->get_user();
939 my $node = extract_param($param, 'node');
941 my $vmid = extract_param($param, 'vmid');
943 my $skiplock = extract_param($param, 'skiplock');
944 raise_param_exc({ skiplock => "Only root may
use this option
." })
945 if $skiplock && $user ne 'root@pam';
950 syslog('info', "shutdown VM
$vmid: $upid\n");
952 PVE::QemuServer::vm_shutdown($vmid, $skiplock);
954 my $pid = PVE::QemuServer::check_running ($vmid);
956 if ($pid && $param->{timeout}) {
957 print "waiting
until VM
$vmid stopps
(PID
$pid)\n";
960 while (($count < $param->{timeout}) &&
961 PVE::QemuServer::check_running($vmid)) {
966 die "wait failed
- got timeout
\n" if PVE::QemuServer::check_running($vmid);
972 return $rpcenv->fork_worker('qmshutdown', $vmid, $user, $realcmd);
975 __PACKAGE__->register_method({
976 name => 'vm_suspend',
977 path => '{vmid}/status/suspend',
981 description => "Suspend virtual machine
.",
983 additionalProperties => 0,
985 node => get_standard_option('pve-node'),
986 vmid => get_standard_option('pve-vmid'),
987 skiplock => get_standard_option('skiplock'),
996 my $rpcenv = PVE::RPCEnvironment::get();
998 my $user = $rpcenv->get_user();
1000 my $node = extract_param($param, 'node');
1002 my $vmid = extract_param($param, 'vmid');
1004 my $skiplock = extract_param($param, 'skiplock');
1005 raise_param_exc({ skiplock => "Only root may
use this option
." })
1006 if $skiplock && $user ne 'root@pam';
1011 syslog('info', "suspend VM
$vmid: $upid\n");
1013 PVE::QemuServer::vm_suspend($vmid, $skiplock);
1018 return $rpcenv->fork_worker('qmsuspend', $vmid, $user, $realcmd);
1021 __PACKAGE__->register_method({
1022 name => 'vm_resume',
1023 path => '{vmid}/status/resume',
1027 description => "Resume virtual machine
.",
1029 additionalProperties => 0,
1031 node => get_standard_option('pve-node'),
1032 vmid => get_standard_option('pve-vmid'),
1033 skiplock => get_standard_option('skiplock'),
1042 my $rpcenv = PVE::RPCEnvironment::get();
1044 my $user = $rpcenv->get_user();
1046 my $node = extract_param($param, 'node');
1048 my $vmid = extract_param($param, 'vmid');
1050 my $skiplock = extract_param($param, 'skiplock');
1051 raise_param_exc({ skiplock => "Only root may
use this option
." })
1052 if $skiplock && $user ne 'root@pam';
1057 syslog('info', "resume VM
$vmid: $upid\n");
1059 PVE::QemuServer::vm_resume($vmid, $skiplock);
1064 return $rpcenv->fork_worker('qmresume', $vmid, $user, $realcmd);
1067 __PACKAGE__->register_method({
1068 name => 'vm_sendkey',
1069 path => '{vmid}/sendkey',
1073 description => "Send key event to virtual machine
.",
1075 additionalProperties => 0,
1077 node => get_standard_option('pve-node'),
1078 vmid => get_standard_option('pve-vmid'),
1079 skiplock => get_standard_option('skiplock'),
1081 description => "The key
(qemu monitor encoding
).",
1086 returns => { type => 'null'},
1090 my $rpcenv = PVE::RPCEnvironment::get();
1092 my $user = $rpcenv->get_user();
1094 my $node = extract_param($param, 'node');
1096 my $vmid = extract_param($param, 'vmid');
1098 my $skiplock = extract_param($param, 'skiplock');
1099 raise_param_exc({ skiplock => "Only root may
use this option
." })
1100 if $skiplock && $user ne 'root@pam';
1102 PVE::QemuServer::vm_sendkey($vmid, $skiplock, $param->{key});
1107 __PACKAGE__->register_method({
1108 name => 'migrate_vm',
1109 path => '{vmid}/migrate',
1113 description => "Migrate virtual machine
. Creates a new migration task
.",
1115 additionalProperties => 0,
1117 node => get_standard_option('pve-node'),
1118 vmid => get_standard_option('pve-vmid'),
1119 target => get_standard_option('pve-node', { description => "Target node
." }),
1122 description => "Use online
/live migration
.",
1127 description => "Allow to migrate VMs which
use local devices
. Only root may
use this option
.",
1134 description => "the task ID
.",
1139 my $rpcenv = PVE::RPCEnvironment::get();
1141 my $user = $rpcenv->get_user();
1143 my $target = extract_param($param, 'target');
1145 my $localnode = PVE::INotify::nodename();
1146 raise_param_exc({ target => "target
is local node
."}) if $target eq $localnode;
1148 PVE::Cluster::check_cfs_quorum();
1150 PVE::Cluster::check_node_exists($target);
1152 my $targetip = PVE::Cluster::remote_node_ip($target);
1154 my $vmid = extract_param($param, 'vmid');
1156 raise_param_exc({ force => "Only root may
use this option
." }) if $user ne 'root@pam';
1159 PVE::QemuServer::load_config($vmid);
1161 # try to detect errors early
1162 if (PVE::QemuServer::check_running($vmid)) {
1163 die "cant migrate running VM without
--online
\n"
1164 if !$param->{online};
1170 PVE::QemuMigrate::migrate($target, $targetip, $vmid, $param->{online}, $param->{force});
1173 my $upid = $rpcenv->fork_worker('qmigrate', $vmid, $user, $realcmd);