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.",
92 requires
=> 'archive',
97 description
=> "Assign a unique random ethernet address.",
98 requires
=> 'archive',
108 my $rpcenv = PVE
::RPCEnvironment
::get
();
110 my $user = $rpcenv->get_user();
112 my $node = extract_param
($param, 'node');
114 my $vmid = extract_param
($param, 'vmid');
116 my $archive = extract_param
($param, 'archive');
118 my $storage = extract_param
($param, 'storage');
120 my $force = extract_param
($param, 'force');
122 my $unique = extract_param
($param, 'unique');
124 my $filename = PVE
::QemuServer
::config_file
($vmid);
126 my $storecfg = PVE
::Storage
::config
();
128 PVE
::Cluster
::check_cfs_quorum
();
131 &$resolve_cdrom_alias($param);
133 foreach my $opt (keys %$param) {
134 if (PVE
::QemuServer
::valid_drivename
($opt)) {
135 my $drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
136 raise_param_exc
({ $opt => "unable to parse drive options" }) if !$drive;
138 PVE
::QemuServer
::cleanup_drive_path
($opt, $storecfg, $drive);
139 $param->{$opt} = PVE
::QemuServer
::print_drive
($vmid, $drive);
143 PVE
::QemuServer
::add_random_macs
($param);
145 my $keystr = join(' ', keys %$param);
146 raise_param_exc
({ archive
=> "option conflicts with other options ($keystr)"}) if $keystr;
149 # fixme: archive eq '-' (read from stdin)
151 my $restorefn = sub {
154 die "unable to restore vm $vmid: config file already exists\n"
157 die "unable to restore vm $vmid: vm is running\n"
158 if PVE
::QemuServer
::check_running
($vmid);
160 # destroy existing data - keep empty config
161 PVE
::QemuServer
::destroy_vm
($storecfg, $vmid, 1);
165 PVE
::QemuServer
::restore_archive
($archive, $vmid, {
167 unique
=> $unique });
170 return $rpcenv->fork_worker('qmrestore', $vmid, $user, $realcmd);
175 # second test (after locking test is accurate)
176 die "unable to create vm $vmid: config file already exists\n"
184 $vollist = PVE
::QemuServer
::create_disks
($storecfg, $vmid, $param, $storage);
186 # try to be smart about bootdisk
187 my @disks = PVE
::QemuServer
::disknames
();
189 foreach my $ds (reverse @disks) {
190 next if !$param->{$ds};
191 my $disk = PVE
::QemuServer
::parse_drive
($ds, $param->{$ds});
192 next if PVE
::QemuServer
::drive_is_cdrom
($disk);
196 if (!$param->{bootdisk
} && $firstdisk) {
197 $param->{bootdisk
} = $firstdisk;
200 PVE
::QemuServer
::create_conf_nolock
($vmid, $param);
205 foreach my $volid (@$vollist) {
206 eval { PVE
::Storage
::vdisk_free
($storecfg, $volid); };
209 die "create failed - $err";
213 return $rpcenv->fork_worker('qmcreate', $vmid, $user, $realcmd);
216 return PVE
::QemuServer
::lock_config
($vmid, $archive ?
$restorefn : $createfn);
219 __PACKAGE__-
>register_method({
224 description
=> "Directory index",
226 additionalProperties
=> 0,
228 node
=> get_standard_option
('pve-node'),
229 vmid
=> get_standard_option
('pve-vmid'),
237 subdir
=> { type
=> 'string' },
240 links
=> [ { rel
=> 'child', href
=> "{subdir}" } ],
246 { subdir
=> 'config' },
247 { subdir
=> 'status' },
248 { subdir
=> 'unlink' },
249 { subdir
=> 'vncproxy' },
250 { subdir
=> 'migrate' },
252 { subdir
=> 'rrddata' },
258 __PACKAGE__-
>register_method({
260 path
=> '{vmid}/rrd',
262 protected
=> 1, # fixme: can we avoid that?
264 path
=> '/vms/{vmid}',
265 privs
=> [ 'VM.Audit' ],
267 description
=> "Read VM RRD statistics (returns PNG)",
269 additionalProperties
=> 0,
271 node
=> get_standard_option
('pve-node'),
272 vmid
=> get_standard_option
('pve-vmid'),
274 description
=> "Specify the time frame you are interested in.",
276 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
279 description
=> "The list of datasources you want to display.",
280 type
=> 'string', format
=> 'pve-configid-list',
283 description
=> "The RRD consolidation function",
285 enum
=> [ 'AVERAGE', 'MAX' ],
293 filename
=> { type
=> 'string' },
299 return PVE
::Cluster
::create_rrd_graph
(
300 "pve2-vm/$param->{vmid}", $param->{timeframe
},
301 $param->{ds
}, $param->{cf
});
305 __PACKAGE__-
>register_method({
307 path
=> '{vmid}/rrddata',
309 protected
=> 1, # fixme: can we avoid that?
311 path
=> '/vms/{vmid}',
312 privs
=> [ 'VM.Audit' ],
314 description
=> "Read VM RRD statistics",
316 additionalProperties
=> 0,
318 node
=> get_standard_option
('pve-node'),
319 vmid
=> get_standard_option
('pve-vmid'),
321 description
=> "Specify the time frame you are interested in.",
323 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
326 description
=> "The RRD consolidation function",
328 enum
=> [ 'AVERAGE', 'MAX' ],
343 return PVE
::Cluster
::create_rrd_data
(
344 "pve2-vm/$param->{vmid}", $param->{timeframe
}, $param->{cf
});
348 __PACKAGE__-
>register_method({
350 path
=> '{vmid}/config',
353 description
=> "Get virtual machine configuration.",
355 additionalProperties
=> 0,
357 node
=> get_standard_option
('pve-node'),
358 vmid
=> get_standard_option
('pve-vmid'),
366 description
=> 'SHA1 digest of configuration file. This can be used to prevent concurrent modifications.',
373 my $conf = PVE
::QemuServer
::load_config
($param->{vmid
});
378 __PACKAGE__-
>register_method({
380 path
=> '{vmid}/config',
384 description
=> "Set virtual machine options.",
386 additionalProperties
=> 0,
387 properties
=> PVE
::QemuServer
::json_config_properties
(
389 node
=> get_standard_option
('pve-node'),
390 vmid
=> get_standard_option
('pve-vmid'),
391 skiplock
=> get_standard_option
('skiplock'),
393 type
=> 'string', format
=> 'pve-configid-list',
394 description
=> "A list of settings you want to delete.",
399 description
=> $opt_force_description,
401 requires
=> 'delete',
405 description
=> 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
411 returns
=> { type
=> 'null'},
415 my $rpcenv = PVE
::RPCEnvironment
::get
();
417 my $user = $rpcenv->get_user();
419 my $node = extract_param
($param, 'node');
421 my $vmid = extract_param
($param, 'vmid');
423 my $digest = extract_param
($param, 'digest');
425 my @paramarr = (); # used for log message
426 foreach my $key (keys %$param) {
427 push @paramarr, "-$key", $param->{$key};
430 my $skiplock = extract_param
($param, 'skiplock');
431 raise_param_exc
({ skiplock
=> "Only root may use this option." })
432 if $skiplock && $user ne 'root@pam';
434 my $delete = extract_param
($param, 'delete');
435 my $force = extract_param
($param, 'force');
437 die "no options specified\n" if !$delete && !scalar(keys %$param);
439 my $storecfg = PVE
::Storage
::config
();
441 &$resolve_cdrom_alias($param);
446 foreach my $opt (keys %$param) {
447 if (PVE
::QemuServer
::valid_drivename
($opt)) {
448 my $drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
449 raise_param_exc
({ $opt => "unable to parse drive options" }) if !$drive;
450 if ($drive->{file
} eq 'eject') {
452 delete $param->{$opt};
456 PVE
::QemuServer
::cleanup_drive_path
($opt, $storecfg, $drive);
457 $param->{$opt} = PVE
::QemuServer
::print_drive
($vmid, $drive);
459 if (PVE
::QemuServer
::drive_is_cdrom
($drive)) {
460 $cdchange->{$opt} = PVE
::QemuServer
::get_iso_path
($storecfg, $vmid, $drive->{file
});
465 foreach my $opt (PVE
::Tools
::split_list
($delete)) {
466 $opt = 'ide2' if $opt eq 'cdrom';
467 die "you can't use '-$opt' and '-delete $opt' at the same time\n"
468 if defined($param->{$opt});
471 PVE
::QemuServer
::add_random_macs
($param);
477 my $conf = PVE
::QemuServer
::load_config
($vmid);
479 die "checksum missmatch (file change by other user?)\n"
480 if $digest && $digest ne $conf->{digest
};
482 PVE
::QemuServer
::check_lock
($conf) if !$skiplock;
484 PVE
::Cluster
::log_msg
('info', $user, "update VM $vmid: " . join (' ', @paramarr));
486 foreach my $opt (keys %$eject) {
488 my $drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
489 $cdchange->{$opt} = undef if PVE
::QemuServer
::drive_is_cdrom
($drive);
491 raise_param_exc
({ $opt => "eject failed - drive does not exist." });
495 foreach my $opt (keys %$param) {
496 next if !PVE
::QemuServer
::valid_drivename
($opt);
497 next if !$conf->{$opt};
498 my $old_drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
499 next if PVE
::QemuServer
::drive_is_cdrom
($old_drive);
500 my $new_drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
501 if ($new_drive->{file
} ne $old_drive->{file
}) {
503 eval { ($path, $owner) = PVE
::Storage
::path
($storecfg, $old_drive->{file
}); };
504 if ($owner && ($owner == $vmid)) {
505 PVE
::QemuServer
::add_unused_volume
($conf, $param, $old_drive->{file
});
512 foreach my $opt (PVE
::Tools
::split_list
($delete)) {
513 $opt = 'ide2' if $opt eq 'cdrom';
514 if (!PVE
::QemuServer
::option_exists
($opt)) {
515 raise_param_exc
({ delete => "unknown option '$opt'" });
517 next if !defined($conf->{$opt});
518 if (PVE
::QemuServer
::valid_drivename
($opt)) {
519 PVE
::QemuServer
::vm_devicedel
($vmid, $conf, $opt);
520 my $drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
521 if (PVE
::QemuServer
::drive_is_cdrom
($drive)) {
522 $cdchange->{$opt} = undef;
524 my $volid = $drive->{file
};
526 if ($volid !~ m
|^/|) {
528 eval { ($path, $owner) = PVE
::Storage
::path
($storecfg, $volid); };
529 if ($owner && ($owner == $vmid)) {
531 push @$vollist, $volid;
533 PVE
::QemuServer
::add_unused_volume
($conf, $param, $volid);
538 } elsif ($opt =~ m/^unused/) {
539 push @$vollist, $conf->{$opt};
545 PVE
::QemuServer
::create_disks
($storecfg, $vmid, $param, $conf);
547 PVE
::QemuServer
::change_config_nolock
($vmid, $param, $unset, 1);
549 return if !PVE
::QemuServer
::check_running
($vmid);
551 foreach my $opt (keys %$cdchange) {
552 my $qdn = PVE
::QemuServer
::qemu_drive_name
($opt, 'cdrom');
553 my $path = $cdchange->{$opt};
554 PVE
::QemuServer
::vm_monitor_command
($vmid, "eject $qdn", 0);
555 PVE
::QemuServer
::vm_monitor_command
($vmid, "change $qdn \"$path\"", 0) if $path;
559 PVE::QemuServer::lock_config($vmid, $updatefn);
561 foreach my $volid (@$vollist) {
562 eval { PVE::Storage::vdisk_free($storecfg, $volid); };
571 __PACKAGE__->register_method({
572 name => 'destroy_vm',
577 description => "Destroy the vm
(also
delete all used
/owned volumes
).",
579 additionalProperties => 0,
581 node => get_standard_option('pve-node'),
582 vmid => get_standard_option('pve-vmid'),
583 skiplock => get_standard_option('skiplock'),
592 my $rpcenv = PVE::RPCEnvironment::get();
594 my $user = $rpcenv->get_user();
596 my $vmid = $param->{vmid};
598 my $skiplock = $param->{skiplock};
599 raise_param_exc({ skiplock => "Only root may
use this option
." })
600 if $skiplock && $user ne 'root@pam';
603 my $conf = PVE::QemuServer::load_config($vmid);
605 my $storecfg = PVE::Storage::config();
608 PVE::QemuServer::vm_destroy($storecfg, $vmid, $skiplock);
611 return $rpcenv->fork_worker('qmdestroy', $vmid, $user, $realcmd);
614 __PACKAGE__->register_method({
616 path => '{vmid}/unlink',
620 description => "Unlink
/delete disk images
.",
622 additionalProperties => 0,
624 node => get_standard_option('pve-node'),
625 vmid => get_standard_option('pve-vmid'),
627 type => 'string', format => 'pve-configid-list',
628 description => "A list of disk IDs you want to
delete.",
632 description => $opt_force_description,
637 returns => { type => 'null'},
641 $param->{delete} = extract_param($param, 'idlist');
643 __PACKAGE__->update_vm($param);
650 __PACKAGE__->register_method({
652 path => '{vmid}/vncproxy',
656 path => '/vms/{vmid}',
657 privs => [ 'VM.Console' ],
659 description => "Creates a TCP VNC proxy connections
.",
661 additionalProperties => 0,
663 node => get_standard_option('pve-node'),
664 vmid => get_standard_option('pve-vmid'),
668 additionalProperties => 0,
670 user => { type => 'string' },
671 ticket => { type => 'string' },
672 cert => { type => 'string' },
673 port => { type => 'integer' },
674 upid => { type => 'string' },
680 my $rpcenv = PVE::RPCEnvironment::get();
682 my $user = $rpcenv->get_user();
683 my $ticket = PVE::AccessControl::assemble_ticket($user);
685 my $vmid = $param->{vmid};
686 my $node = $param->{node};
688 $sslcert = PVE::Tools::file_get_contents("/etc/pve
/pve-root-ca
.pem
", 8192)
691 my $port = PVE::Tools::next_vnc_port();
695 if ($node ne PVE::INotify::nodename()) {
696 $remip = PVE::Cluster::remote_node_ip($node);
699 # NOTE: kvm VNC traffic is already TLS encrypted,
700 # so we select the fastest chipher here (or 'none'?)
701 my $remcmd = $remip ? ['/usr/bin/ssh', '-T', '-o', 'BatchMode=yes',
702 '-c', 'blowfish-cbc', $remip] : [];
709 syslog('info', "starting vnc proxy
$upid\n");
711 my $qmcmd = [@$remcmd, "/usr/sbin
/qm
", 'vncproxy', $vmid];
713 my $qmstr = join(' ', @$qmcmd);
715 # also redirect stderr (else we get RFB protocol errors)
716 my $cmd = ['/bin/nc', '-l', '-p', $port, '-w', $timeout, '-c', "$qmstr 2>/dev/null
"];
718 PVE::Tools::run_command($cmd);
723 my $upid = $rpcenv->fork_worker('vncproxy', $vmid, $user, $realcmd);
734 __PACKAGE__->register_method({
736 path => '{vmid}/status',
739 description => "Directory
index",
741 additionalProperties => 0,
743 node => get_standard_option('pve-node'),
744 vmid => get_standard_option('pve-vmid'),
752 subdir => { type => 'string' },
755 links => [ { rel => 'child', href => "{subdir
}" } ],
761 my $conf = PVE::QemuServer::load_config($param->{vmid});
764 { subdir => 'current' },
765 { subdir => 'start' },
766 { subdir => 'stop' },
772 __PACKAGE__->register_method({
774 path => '{vmid}/status/current',
777 protected => 1, # qemu pid files are only readable by root
778 description => "Get virtual machine status
.",
780 additionalProperties => 0,
782 node => get_standard_option('pve-node'),
783 vmid => get_standard_option('pve-vmid'),
786 returns => { type => 'object' },
791 my $conf = PVE::QemuServer::load_config($param->{vmid});
793 my $vmstatus = PVE::QemuServer::vmstatus($param->{vmid});
795 return $vmstatus->{$param->{vmid}};
798 __PACKAGE__->register_method({
800 path => '{vmid}/status/start',
804 description => "Start virtual machine
.",
806 additionalProperties => 0,
808 node => get_standard_option('pve-node'),
809 vmid => get_standard_option('pve-vmid'),
810 skiplock => get_standard_option('skiplock'),
811 stateuri => get_standard_option('pve-qm-stateuri'),
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 $stateuri = extract_param($param, 'stateuri');
829 raise_param_exc({ stateuri => "Only root may
use this option
." })
830 if $stateuri && $user ne 'root@pam';
832 my $skiplock = extract_param($param, 'skiplock');
833 raise_param_exc({ skiplock => "Only root may
use this option
." })
834 if $skiplock && $user ne 'root@pam';
836 my $storecfg = PVE::Storage::config();
841 syslog('info', "start VM
$vmid: $upid\n");
843 PVE::QemuServer::vm_start($storecfg, $vmid, $stateuri, $skiplock);
848 return $rpcenv->fork_worker('qmstart', $vmid, $user, $realcmd);
851 __PACKAGE__->register_method({
853 path => '{vmid}/status/stop',
857 description => "Stop virtual machine
.",
859 additionalProperties => 0,
861 node => get_standard_option('pve-node'),
862 vmid => get_standard_option('pve-vmid'),
863 skiplock => get_standard_option('skiplock'),
865 description => "Wait maximal timeout seconds
.",
878 my $rpcenv = PVE::RPCEnvironment::get();
880 my $user = $rpcenv->get_user();
882 my $node = extract_param($param, 'node');
884 my $vmid = extract_param($param, 'vmid');
886 my $skiplock = extract_param($param, 'skiplock');
887 raise_param_exc({ skiplock => "Only root may
use this option
." })
888 if $skiplock && $user ne 'root@pam';
893 syslog('info', "stop VM
$vmid: $upid\n");
895 PVE::QemuServer::vm_stop($vmid, $skiplock);
897 my $pid = PVE::QemuServer::check_running ($vmid);
899 if ($pid && $param->{timeout}) {
900 print "waiting
until VM
$vmid stopps
(PID
$pid)\n";
903 while (($count < $param->{timeout}) &&
904 PVE::QemuServer::check_running($vmid)) {
909 die "wait failed
- got timeout
\n" if PVE::QemuServer::check_running($vmid);
915 return $rpcenv->fork_worker('qmstop', $vmid, $user, $realcmd);
918 __PACKAGE__->register_method({
920 path => '{vmid}/status/reset',
924 description => "Reset virtual machine
.",
926 additionalProperties => 0,
928 node => get_standard_option('pve-node'),
929 vmid => get_standard_option('pve-vmid'),
930 skiplock => get_standard_option('skiplock'),
939 my $rpcenv = PVE::RPCEnvironment::get();
941 my $user = $rpcenv->get_user();
943 my $node = extract_param($param, 'node');
945 my $vmid = extract_param($param, 'vmid');
947 my $skiplock = extract_param($param, 'skiplock');
948 raise_param_exc({ skiplock => "Only root may
use this option
." })
949 if $skiplock && $user ne 'root@pam';
954 syslog('info', "reset VM
$vmid: $upid\n");
956 PVE::QemuServer::vm_reset($vmid, $skiplock);
961 return $rpcenv->fork_worker('qmreset', $vmid, $user, $realcmd);
964 __PACKAGE__->register_method({
965 name => 'vm_shutdown',
966 path => '{vmid}/status/shutdown',
970 description => "Shutdown virtual machine
.",
972 additionalProperties => 0,
974 node => get_standard_option('pve-node'),
975 vmid => get_standard_option('pve-vmid'),
976 skiplock => get_standard_option('skiplock'),
978 description => "Wait maximal timeout seconds
.",
991 my $rpcenv = PVE::RPCEnvironment::get();
993 my $user = $rpcenv->get_user();
995 my $node = extract_param($param, 'node');
997 my $vmid = extract_param($param, 'vmid');
999 my $skiplock = extract_param($param, 'skiplock');
1000 raise_param_exc({ skiplock => "Only root may
use this option
." })
1001 if $skiplock && $user ne 'root@pam';
1006 syslog('info', "shutdown VM
$vmid: $upid\n");
1008 PVE::QemuServer::vm_shutdown($vmid, $skiplock);
1010 my $pid = PVE::QemuServer::check_running ($vmid);
1012 if ($pid && $param->{timeout}) {
1013 print "waiting
until VM
$vmid stopps
(PID
$pid)\n";
1016 while (($count < $param->{timeout}) &&
1017 PVE::QemuServer::check_running($vmid)) {
1022 die "wait failed
- got timeout
\n" if PVE::QemuServer::check_running($vmid);
1028 return $rpcenv->fork_worker('qmshutdown', $vmid, $user, $realcmd);
1031 __PACKAGE__->register_method({
1032 name => 'vm_suspend',
1033 path => '{vmid}/status/suspend',
1037 description => "Suspend virtual machine
.",
1039 additionalProperties => 0,
1041 node => get_standard_option('pve-node'),
1042 vmid => get_standard_option('pve-vmid'),
1043 skiplock => get_standard_option('skiplock'),
1052 my $rpcenv = PVE::RPCEnvironment::get();
1054 my $user = $rpcenv->get_user();
1056 my $node = extract_param($param, 'node');
1058 my $vmid = extract_param($param, 'vmid');
1060 my $skiplock = extract_param($param, 'skiplock');
1061 raise_param_exc({ skiplock => "Only root may
use this option
." })
1062 if $skiplock && $user ne 'root@pam';
1067 syslog('info', "suspend VM
$vmid: $upid\n");
1069 PVE::QemuServer::vm_suspend($vmid, $skiplock);
1074 return $rpcenv->fork_worker('qmsuspend', $vmid, $user, $realcmd);
1077 __PACKAGE__->register_method({
1078 name => 'vm_resume',
1079 path => '{vmid}/status/resume',
1083 description => "Resume virtual machine
.",
1085 additionalProperties => 0,
1087 node => get_standard_option('pve-node'),
1088 vmid => get_standard_option('pve-vmid'),
1089 skiplock => get_standard_option('skiplock'),
1098 my $rpcenv = PVE::RPCEnvironment::get();
1100 my $user = $rpcenv->get_user();
1102 my $node = extract_param($param, 'node');
1104 my $vmid = extract_param($param, 'vmid');
1106 my $skiplock = extract_param($param, 'skiplock');
1107 raise_param_exc({ skiplock => "Only root may
use this option
." })
1108 if $skiplock && $user ne 'root@pam';
1113 syslog('info', "resume VM
$vmid: $upid\n");
1115 PVE::QemuServer::vm_resume($vmid, $skiplock);
1120 return $rpcenv->fork_worker('qmresume', $vmid, $user, $realcmd);
1123 __PACKAGE__->register_method({
1124 name => 'vm_sendkey',
1125 path => '{vmid}/sendkey',
1129 description => "Send key event to virtual machine
.",
1131 additionalProperties => 0,
1133 node => get_standard_option('pve-node'),
1134 vmid => get_standard_option('pve-vmid'),
1135 skiplock => get_standard_option('skiplock'),
1137 description => "The key
(qemu monitor encoding
).",
1142 returns => { type => 'null'},
1146 my $rpcenv = PVE::RPCEnvironment::get();
1148 my $user = $rpcenv->get_user();
1150 my $node = extract_param($param, 'node');
1152 my $vmid = extract_param($param, 'vmid');
1154 my $skiplock = extract_param($param, 'skiplock');
1155 raise_param_exc({ skiplock => "Only root may
use this option
." })
1156 if $skiplock && $user ne 'root@pam';
1158 PVE::QemuServer::vm_sendkey($vmid, $skiplock, $param->{key});
1163 __PACKAGE__->register_method({
1164 name => 'migrate_vm',
1165 path => '{vmid}/migrate',
1169 description => "Migrate virtual machine
. Creates a new migration task
.",
1171 additionalProperties => 0,
1173 node => get_standard_option('pve-node'),
1174 vmid => get_standard_option('pve-vmid'),
1175 target => get_standard_option('pve-node', { description => "Target node
." }),
1178 description => "Use online
/live migration
.",
1183 description => "Allow to migrate VMs which
use local devices
. Only root may
use this option
.",
1190 description => "the task ID
.",
1195 my $rpcenv = PVE::RPCEnvironment::get();
1197 my $user = $rpcenv->get_user();
1199 my $target = extract_param($param, 'target');
1201 my $localnode = PVE::INotify::nodename();
1202 raise_param_exc({ target => "target
is local node
."}) if $target eq $localnode;
1204 PVE::Cluster::check_cfs_quorum();
1206 PVE::Cluster::check_node_exists($target);
1208 my $targetip = PVE::Cluster::remote_node_ip($target);
1210 my $vmid = extract_param($param, 'vmid');
1212 raise_param_exc({ force => "Only root may
use this option
." }) if $user ne 'root@pam';
1215 PVE::QemuServer::load_config($vmid);
1217 # try to detect errors early
1218 if (PVE::QemuServer::check_running($vmid)) {
1219 die "cant migrate running VM without
--online
\n"
1220 if !$param->{online};
1226 PVE::QemuMigrate::migrate($target, $targetip, $vmid, $param->{online}, $param->{force});
1229 my $upid = $rpcenv->fork_worker('qmigrate', $vmid, $user, $realcmd);