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');
92 my $vmid = extract_param
($param, 'vmid');
94 my $filename = PVE
::QemuServer
::config_file
($vmid);
95 # first test (befor locking)
96 die "unable to create vm $vmid: config file already exists\n"
99 my $storecfg = PVE
::Storage
::config
();
101 &$resolve_cdrom_alias($param);
103 foreach my $opt (keys %$param) {
104 if (PVE
::QemuServer
::valid_drivename
($opt)) {
105 my $drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
106 raise_param_exc
({ $opt => "unable to parse drive options" }) if !$drive;
108 PVE
::QemuServer
::cleanup_drive_path
($opt, $storecfg, $drive);
109 $param->{$opt} = PVE
::QemuServer
::print_drive
($vmid, $drive);
113 PVE
::QemuServer
::add_random_macs
($param);
117 # second test (after locking test is accurate)
118 die "unable to create vm $vmid: config file already exists\n"
126 $vollist = PVE
::QemuServer
::create_disks
($storecfg, $vmid, $param);
128 # try to be smart about bootdisk
129 my @disks = PVE
::QemuServer
::disknames
();
131 foreach my $ds (reverse @disks) {
132 next if !$param->{$ds};
133 my $disk = PVE
::QemuServer
::parse_drive
($ds, $param->{$ds});
134 next if PVE
::QemuServer
::drive_is_cdrom
($disk);
138 if (!$param->{bootdisk
} && $firstdisk) {
139 $param->{bootdisk
} = $firstdisk;
142 PVE
::QemuServer
::create_conf_nolock
($vmid, $param);
147 foreach my $volid (@$vollist) {
148 eval { PVE
::Storage
::vdisk_free
($storecfg, $volid); };
151 die "create failed - $err";
155 return $rpcenv->fork_worker('qmcreate', $vmid, $user, $realcmd);
158 return PVE
::QemuServer
::lock_config
($vmid, $createfn);
161 __PACKAGE__-
>register_method({
166 description
=> "Directory index",
168 additionalProperties
=> 0,
170 node
=> get_standard_option
('pve-node'),
171 vmid
=> get_standard_option
('pve-vmid'),
179 subdir
=> { type
=> 'string' },
182 links
=> [ { rel
=> 'child', href
=> "{subdir}" } ],
188 { subdir
=> 'config' },
189 { subdir
=> 'status' },
190 { subdir
=> 'unlink' },
191 { subdir
=> 'vncproxy' },
192 { subdir
=> 'migrate' },
194 { subdir
=> 'rrddata' },
200 __PACKAGE__-
>register_method({
202 path
=> '{vmid}/rrd',
204 protected
=> 1, # fixme: can we avoid that?
206 path
=> '/vms/{vmid}',
207 privs
=> [ 'VM.Audit' ],
209 description
=> "Read VM RRD statistics (returns PNG)",
211 additionalProperties
=> 0,
213 node
=> get_standard_option
('pve-node'),
214 vmid
=> get_standard_option
('pve-vmid'),
216 description
=> "Specify the time frame you are interested in.",
218 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
221 description
=> "The list of datasources you want to display.",
222 type
=> 'string', format
=> 'pve-configid-list',
225 description
=> "The RRD consolidation function",
227 enum
=> [ 'AVERAGE', 'MAX' ],
235 filename
=> { type
=> 'string' },
241 return PVE
::Cluster
::create_rrd_graph
(
242 "pve2-vm/$param->{vmid}", $param->{timeframe
},
243 $param->{ds
}, $param->{cf
});
247 __PACKAGE__-
>register_method({
249 path
=> '{vmid}/rrddata',
251 protected
=> 1, # fixme: can we avoid that?
253 path
=> '/vms/{vmid}',
254 privs
=> [ 'VM.Audit' ],
256 description
=> "Read VM RRD statistics",
258 additionalProperties
=> 0,
260 node
=> get_standard_option
('pve-node'),
261 vmid
=> get_standard_option
('pve-vmid'),
263 description
=> "Specify the time frame you are interested in.",
265 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
268 description
=> "The RRD consolidation function",
270 enum
=> [ 'AVERAGE', 'MAX' ],
285 return PVE
::Cluster
::create_rrd_data
(
286 "pve2-vm/$param->{vmid}", $param->{timeframe
}, $param->{cf
});
290 __PACKAGE__-
>register_method({
292 path
=> '{vmid}/config',
295 description
=> "Get virtual machine configuration.",
297 additionalProperties
=> 0,
299 node
=> get_standard_option
('pve-node'),
300 vmid
=> get_standard_option
('pve-vmid'),
308 description
=> 'SHA1 digest of configuration file. This can be used to prevent concurrent modifications.',
315 my $conf = PVE
::QemuServer
::load_config
($param->{vmid
});
320 __PACKAGE__-
>register_method({
322 path
=> '{vmid}/config',
326 description
=> "Set virtual machine options.",
328 additionalProperties
=> 0,
329 properties
=> PVE
::QemuServer
::json_config_properties
(
331 node
=> get_standard_option
('pve-node'),
332 vmid
=> get_standard_option
('pve-vmid'),
333 skiplock
=> get_standard_option
('skiplock'),
335 type
=> 'string', format
=> 'pve-configid-list',
336 description
=> "A list of settings you want to delete.",
341 description
=> $opt_force_description,
343 requires
=> 'delete',
347 description
=> 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
353 returns
=> { type
=> 'null'},
357 my $rpcenv = PVE
::RPCEnvironment
::get
();
359 my $user = $rpcenv->get_user();
361 my $node = extract_param
($param, 'node');
363 my $vmid = extract_param
($param, 'vmid');
365 my $digest = extract_param
($param, 'digest');
367 my @paramarr = (); # used for log message
368 foreach my $key (keys %$param) {
369 push @paramarr, "-$key", $param->{$key};
372 my $skiplock = extract_param
($param, 'skiplock');
373 raise_param_exc
({ skiplock
=> "Only root may use this option." })
374 if $skiplock && $user ne 'root@pam';
376 my $delete = extract_param
($param, 'delete');
377 my $force = extract_param
($param, 'force');
379 die "no options specified\n" if !$delete && !scalar(keys %$param);
381 my $storecfg = PVE
::Storage
::config
();
383 &$resolve_cdrom_alias($param);
388 foreach my $opt (keys %$param) {
389 if (PVE
::QemuServer
::valid_drivename
($opt)) {
390 my $drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
391 raise_param_exc
({ $opt => "unable to parse drive options" }) if !$drive;
392 if ($drive->{file
} eq 'eject') {
394 delete $param->{$opt};
398 PVE
::QemuServer
::cleanup_drive_path
($opt, $storecfg, $drive);
399 $param->{$opt} = PVE
::QemuServer
::print_drive
($vmid, $drive);
401 if (PVE
::QemuServer
::drive_is_cdrom
($drive)) {
402 $cdchange->{$opt} = PVE
::QemuServer
::get_iso_path
($storecfg, $vmid, $drive->{file
});
407 foreach my $opt (PVE
::Tools
::split_list
($delete)) {
408 $opt = 'ide2' if $opt eq 'cdrom';
409 die "you can't use '-$opt' and '-delete $opt' at the same time\n"
410 if defined($param->{$opt});
413 PVE
::QemuServer
::add_random_macs
($param);
419 my $conf = PVE
::QemuServer
::load_config
($vmid);
421 die "checksum missmatch (file change by other user?)\n"
422 if $digest && $digest ne $conf->{digest
};
424 PVE
::QemuServer
::check_lock
($conf) if !$skiplock;
426 PVE
::Cluster
::log_msg
('info', $user, "update VM $vmid: " . join (' ', @paramarr));
428 foreach my $opt (keys %$eject) {
430 my $drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
431 $cdchange->{$opt} = undef if PVE
::QemuServer
::drive_is_cdrom
($drive);
433 raise_param_exc
({ $opt => "eject failed - drive does not exist." });
437 foreach my $opt (keys %$param) {
438 next if !PVE
::QemuServer
::valid_drivename
($opt);
439 next if !$conf->{$opt};
440 my $old_drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
441 next if PVE
::QemuServer
::drive_is_cdrom
($old_drive);
442 my $new_drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
443 if ($new_drive->{file
} ne $old_drive->{file
}) {
445 eval { ($path, $owner) = PVE
::Storage
::path
($storecfg, $old_drive->{file
}); };
446 if ($owner && ($owner == $vmid)) {
447 PVE
::QemuServer
::add_unused_volume
($conf, $param, $old_drive->{file
});
454 foreach my $opt (PVE
::Tools
::split_list
($delete)) {
455 $opt = 'ide2' if $opt eq 'cdrom';
456 if (!PVE
::QemuServer
::option_exists
($opt)) {
457 raise_param_exc
({ delete => "unknown option '$opt'" });
459 next if !defined($conf->{$opt});
460 if (PVE
::QemuServer
::valid_drivename
($opt)) {
461 PVE
::QemuServer
::vm_devicedel
($vmid, $conf, $opt);
462 my $drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
463 if (PVE
::QemuServer
::drive_is_cdrom
($drive)) {
464 $cdchange->{$opt} = undef;
466 my $volid = $drive->{file
};
468 if ($volid !~ m
|^/|) {
470 eval { ($path, $owner) = PVE
::Storage
::path
($storecfg, $volid); };
471 if ($owner && ($owner == $vmid)) {
473 push @$vollist, $volid;
475 PVE
::QemuServer
::add_unused_volume
($conf, $param, $volid);
480 } elsif ($opt =~ m/^unused/) {
481 push @$vollist, $conf->{$opt};
487 PVE
::QemuServer
::create_disks
($storecfg, $vmid, $param, $conf);
489 PVE
::QemuServer
::change_config_nolock
($vmid, $param, $unset, 1);
491 return if !PVE
::QemuServer
::check_running
($vmid);
493 foreach my $opt (keys %$cdchange) {
494 my $qdn = PVE
::QemuServer
::qemu_drive_name
($opt, 'cdrom');
495 my $path = $cdchange->{$opt};
496 PVE
::QemuServer
::vm_monitor_command
($vmid, "eject $qdn", 0);
497 PVE
::QemuServer
::vm_monitor_command
($vmid, "change $qdn \"$path\"", 0) if $path;
501 PVE::QemuServer::lock_config($vmid, $updatefn);
503 foreach my $volid (@$vollist) {
504 eval { PVE::Storage::vdisk_free($storecfg, $volid); };
513 __PACKAGE__->register_method({
514 name => 'destroy_vm',
519 description => "Destroy the vm
(also
delete all used
/owned volumes
).",
521 additionalProperties => 0,
523 node => get_standard_option('pve-node'),
524 vmid => get_standard_option('pve-vmid'),
525 skiplock => get_standard_option('skiplock'),
534 my $rpcenv = PVE::RPCEnvironment::get();
536 my $user = $rpcenv->get_user();
538 my $vmid = $param->{vmid};
540 my $skiplock = $param->{skiplock};
541 raise_param_exc({ skiplock => "Only root may
use this option
." })
542 if $skiplock && $user ne 'root@pam';
545 my $conf = PVE::QemuServer::load_config($vmid);
547 my $storecfg = PVE::Storage::config();
550 PVE::QemuServer::vm_destroy($storecfg, $vmid, $skiplock);
553 return $rpcenv->fork_worker('qmdestroy', $vmid, $user, $realcmd);
556 __PACKAGE__->register_method({
558 path => '{vmid}/unlink',
562 description => "Unlink
/delete disk images
.",
564 additionalProperties => 0,
566 node => get_standard_option('pve-node'),
567 vmid => get_standard_option('pve-vmid'),
569 type => 'string', format => 'pve-configid-list',
570 description => "A list of disk IDs you want to
delete.",
574 description => $opt_force_description,
579 returns => { type => 'null'},
583 $param->{delete} = extract_param($param, 'idlist');
585 __PACKAGE__->update_vm($param);
592 __PACKAGE__->register_method({
594 path => '{vmid}/vncproxy',
598 path => '/vms/{vmid}',
599 privs => [ 'VM.Console' ],
601 description => "Creates a TCP VNC proxy connections
.",
603 additionalProperties => 0,
605 node => get_standard_option('pve-node'),
606 vmid => get_standard_option('pve-vmid'),
610 additionalProperties => 0,
612 user => { type => 'string' },
613 ticket => { type => 'string' },
614 cert => { type => 'string' },
615 port => { type => 'integer' },
616 upid => { type => 'string' },
622 my $rpcenv = PVE::RPCEnvironment::get();
624 my $user = $rpcenv->get_user();
625 my $ticket = PVE::AccessControl::assemble_ticket($user);
627 my $vmid = $param->{vmid};
628 my $node = $param->{node};
630 $sslcert = PVE::Tools::file_get_contents("/etc/pve
/pve-root-ca
.pem
", 8192)
633 my $port = PVE::Tools::next_vnc_port();
637 if ($node ne PVE::INotify::nodename()) {
638 $remip = PVE::Cluster::remote_node_ip($node);
641 # NOTE: kvm VNC traffic is already TLS encrypted,
642 # so we select the fastest chipher here (or 'none'?)
643 my $remcmd = $remip ? ['/usr/bin/ssh', '-T', '-o', 'BatchMode=yes',
644 '-c', 'blowfish-cbc', $remip] : [];
651 syslog('info', "starting vnc proxy
$upid\n");
653 my $qmcmd = [@$remcmd, "/usr/sbin
/qm
", 'vncproxy', $vmid];
655 my $qmstr = join(' ', @$qmcmd);
657 # also redirect stderr (else we get RFB protocol errors)
658 my $cmd = ['/bin/nc', '-l', '-p', $port, '-w', $timeout, '-c', "$qmstr 2>/dev/null
"];
660 PVE::Tools::run_command($cmd);
665 my $upid = $rpcenv->fork_worker('vncproxy', $vmid, $user, $realcmd);
676 __PACKAGE__->register_method({
678 path => '{vmid}/status',
681 description => "Directory
index",
683 additionalProperties => 0,
685 node => get_standard_option('pve-node'),
686 vmid => get_standard_option('pve-vmid'),
694 subdir => { type => 'string' },
697 links => [ { rel => 'child', href => "{subdir
}" } ],
703 my $conf = PVE::QemuServer::load_config($param->{vmid});
706 { subdir => 'current' },
707 { subdir => 'start' },
708 { subdir => 'stop' },
714 __PACKAGE__->register_method({
716 path => '{vmid}/status/current',
719 protected => 1, # qemu pid files are only readable by root
720 description => "Get virtual machine status
.",
722 additionalProperties => 0,
724 node => get_standard_option('pve-node'),
725 vmid => get_standard_option('pve-vmid'),
728 returns => { type => 'object' },
733 my $conf = PVE::QemuServer::load_config($param->{vmid});
735 my $vmstatus = PVE::QemuServer::vmstatus($param->{vmid});
737 return $vmstatus->{$param->{vmid}};
740 __PACKAGE__->register_method({
742 path => '{vmid}/status/start',
746 description => "Start virtual machine
.",
748 additionalProperties => 0,
750 node => get_standard_option('pve-node'),
751 vmid => get_standard_option('pve-vmid'),
752 skiplock => get_standard_option('skiplock'),
753 stateuri => get_standard_option('pve-qm-stateuri'),
762 my $rpcenv = PVE::RPCEnvironment::get();
764 my $user = $rpcenv->get_user();
766 my $node = extract_param($param, 'node');
768 my $vmid = extract_param($param, 'vmid');
770 my $stateuri = extract_param($param, 'stateuri');
771 raise_param_exc({ stateuri => "Only root may
use this option
." })
772 if $stateuri && $user ne 'root@pam';
774 my $skiplock = extract_param($param, 'skiplock');
775 raise_param_exc({ skiplock => "Only root may
use this option
." })
776 if $skiplock && $user ne 'root@pam';
778 my $storecfg = PVE::Storage::config();
783 syslog('info', "start VM
$vmid: $upid\n");
785 PVE::QemuServer::vm_start($storecfg, $vmid, $stateuri, $skiplock);
790 return $rpcenv->fork_worker('qmstart', $vmid, $user, $realcmd);
793 __PACKAGE__->register_method({
795 path => '{vmid}/status/stop',
799 description => "Stop virtual machine
.",
801 additionalProperties => 0,
803 node => get_standard_option('pve-node'),
804 vmid => get_standard_option('pve-vmid'),
805 skiplock => get_standard_option('skiplock'),
807 description => "Wait maximal timeout seconds
.",
820 my $rpcenv = PVE::RPCEnvironment::get();
822 my $user = $rpcenv->get_user();
824 my $node = extract_param($param, 'node');
826 my $vmid = extract_param($param, 'vmid');
828 my $skiplock = extract_param($param, 'skiplock');
829 raise_param_exc({ skiplock => "Only root may
use this option
." })
830 if $skiplock && $user ne 'root@pam';
835 syslog('info', "stop VM
$vmid: $upid\n");
837 PVE::QemuServer::vm_stop($vmid, $skiplock);
839 my $pid = PVE::QemuServer::check_running ($vmid);
841 if ($pid && $param->{timeout}) {
842 print "waiting
until VM
$vmid stopps
(PID
$pid)\n";
845 while (($count < $param->{timeout}) &&
846 PVE::QemuServer::check_running($vmid)) {
851 die "wait failed
- got timeout
\n" if PVE::QemuServer::check_running($vmid);
857 return $rpcenv->fork_worker('qmstop', $vmid, $user, $realcmd);
860 __PACKAGE__->register_method({
862 path => '{vmid}/status/reset',
866 description => "Reset virtual machine
.",
868 additionalProperties => 0,
870 node => get_standard_option('pve-node'),
871 vmid => get_standard_option('pve-vmid'),
872 skiplock => get_standard_option('skiplock'),
881 my $rpcenv = PVE::RPCEnvironment::get();
883 my $user = $rpcenv->get_user();
885 my $node = extract_param($param, 'node');
887 my $vmid = extract_param($param, 'vmid');
889 my $skiplock = extract_param($param, 'skiplock');
890 raise_param_exc({ skiplock => "Only root may
use this option
." })
891 if $skiplock && $user ne 'root@pam';
896 syslog('info', "reset VM
$vmid: $upid\n");
898 PVE::QemuServer::vm_reset($vmid, $skiplock);
903 return $rpcenv->fork_worker('qmreset', $vmid, $user, $realcmd);
906 __PACKAGE__->register_method({
907 name => 'vm_shutdown',
908 path => '{vmid}/status/shutdown',
912 description => "Shutdown virtual machine
.",
914 additionalProperties => 0,
916 node => get_standard_option('pve-node'),
917 vmid => get_standard_option('pve-vmid'),
918 skiplock => get_standard_option('skiplock'),
920 description => "Wait maximal timeout seconds
.",
933 my $rpcenv = PVE::RPCEnvironment::get();
935 my $user = $rpcenv->get_user();
937 my $node = extract_param($param, 'node');
939 my $vmid = extract_param($param, 'vmid');
941 my $skiplock = extract_param($param, 'skiplock');
942 raise_param_exc({ skiplock => "Only root may
use this option
." })
943 if $skiplock && $user ne 'root@pam';
948 syslog('info', "shutdown VM
$vmid: $upid\n");
950 PVE::QemuServer::vm_shutdown($vmid, $skiplock);
952 my $pid = PVE::QemuServer::check_running ($vmid);
954 if ($pid && $param->{timeout}) {
955 print "waiting
until VM
$vmid stopps
(PID
$pid)\n";
958 while (($count < $param->{timeout}) &&
959 PVE::QemuServer::check_running($vmid)) {
964 die "wait failed
- got timeout
\n" if PVE::QemuServer::check_running($vmid);
970 return $rpcenv->fork_worker('qmshutdown', $vmid, $user, $realcmd);
973 __PACKAGE__->register_method({
974 name => 'vm_suspend',
975 path => '{vmid}/status/suspend',
979 description => "Suspend virtual machine
.",
981 additionalProperties => 0,
983 node => get_standard_option('pve-node'),
984 vmid => get_standard_option('pve-vmid'),
985 skiplock => get_standard_option('skiplock'),
994 my $rpcenv = PVE::RPCEnvironment::get();
996 my $user = $rpcenv->get_user();
998 my $node = extract_param($param, 'node');
1000 my $vmid = extract_param($param, 'vmid');
1002 my $skiplock = extract_param($param, 'skiplock');
1003 raise_param_exc({ skiplock => "Only root may
use this option
." })
1004 if $skiplock && $user ne 'root@pam';
1009 syslog('info', "suspend VM
$vmid: $upid\n");
1011 PVE::QemuServer::vm_suspend($vmid, $skiplock);
1016 return $rpcenv->fork_worker('qmsuspend', $vmid, $user, $realcmd);
1019 __PACKAGE__->register_method({
1020 name => 'vm_resume',
1021 path => '{vmid}/status/resume',
1025 description => "Resume virtual machine
.",
1027 additionalProperties => 0,
1029 node => get_standard_option('pve-node'),
1030 vmid => get_standard_option('pve-vmid'),
1031 skiplock => get_standard_option('skiplock'),
1040 my $rpcenv = PVE::RPCEnvironment::get();
1042 my $user = $rpcenv->get_user();
1044 my $node = extract_param($param, 'node');
1046 my $vmid = extract_param($param, 'vmid');
1048 my $skiplock = extract_param($param, 'skiplock');
1049 raise_param_exc({ skiplock => "Only root may
use this option
." })
1050 if $skiplock && $user ne 'root@pam';
1055 syslog('info', "resume VM
$vmid: $upid\n");
1057 PVE::QemuServer::vm_resume($vmid, $skiplock);
1062 return $rpcenv->fork_worker('qmresume', $vmid, $user, $realcmd);
1065 __PACKAGE__->register_method({
1066 name => 'vm_sendkey',
1067 path => '{vmid}/sendkey',
1071 description => "Send key event to virtual machine
.",
1073 additionalProperties => 0,
1075 node => get_standard_option('pve-node'),
1076 vmid => get_standard_option('pve-vmid'),
1077 skiplock => get_standard_option('skiplock'),
1079 description => "The key
(qemu monitor encoding
).",
1084 returns => { type => 'null'},
1088 my $rpcenv = PVE::RPCEnvironment::get();
1090 my $user = $rpcenv->get_user();
1092 my $node = extract_param($param, 'node');
1094 my $vmid = extract_param($param, 'vmid');
1096 my $skiplock = extract_param($param, 'skiplock');
1097 raise_param_exc({ skiplock => "Only root may
use this option
." })
1098 if $skiplock && $user ne 'root@pam';
1100 PVE::QemuServer::vm_sendkey($vmid, $skiplock, $param->{key});
1105 __PACKAGE__->register_method({
1106 name => 'migrate_vm',
1107 path => '{vmid}/migrate',
1111 description => "Migrate virtual machine
. Creates a new migration task
.",
1113 additionalProperties => 0,
1115 node => get_standard_option('pve-node'),
1116 vmid => get_standard_option('pve-vmid'),
1117 target => get_standard_option('pve-node', { description => "Target node
." }),
1120 description => "Use online
/live migration
.",
1125 description => "Allow to migrate VMs which
use local devices
. Only root may
use this option
.",
1132 description => "the task ID
.",
1137 my $rpcenv = PVE::RPCEnvironment::get();
1139 my $user = $rpcenv->get_user();
1141 my $target = extract_param($param, 'target');
1143 my $localnode = PVE::INotify::nodename();
1144 raise_param_exc({ target => "target
is local node
."}) if $target eq $localnode;
1146 PVE::Cluster::check_cfs_quorum();
1148 PVE::Cluster::check_node_exists($target);
1150 my $targetip = PVE::Cluster::remote_node_ip($target);
1152 my $vmid = extract_param($param, 'vmid');
1154 raise_param_exc({ force => "Only root may
use this option
." }) if $user ne 'root@pam';
1157 PVE::QemuServer::load_config($vmid);
1159 # try to detect errors early
1160 if (PVE::QemuServer::check_running($vmid)) {
1161 die "cant migrate running VM without
--online
\n"
1162 if !$param->{online};
1168 PVE::QemuMigrate::migrate($target, $targetip, $vmid, $param->{online}, $param->{force});
1171 my $upid = $rpcenv->fork_worker('qmigrate', $vmid, $user, $realcmd);