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);
148 PVE
::QemuServer
::restore_archive
($archive, $vmid, { storage
=> $storage});
151 return $rpcenv->fork_worker('qmrestore', $vmid, $user, $realcmd);
156 # second test (after locking test is accurate)
157 die "unable to create vm $vmid: config file already exists\n"
165 $vollist = PVE
::QemuServer
::create_disks
($storecfg, $vmid, $param, $storage);
167 # try to be smart about bootdisk
168 my @disks = PVE
::QemuServer
::disknames
();
170 foreach my $ds (reverse @disks) {
171 next if !$param->{$ds};
172 my $disk = PVE
::QemuServer
::parse_drive
($ds, $param->{$ds});
173 next if PVE
::QemuServer
::drive_is_cdrom
($disk);
177 if (!$param->{bootdisk
} && $firstdisk) {
178 $param->{bootdisk
} = $firstdisk;
181 PVE
::QemuServer
::create_conf_nolock
($vmid, $param);
186 foreach my $volid (@$vollist) {
187 eval { PVE
::Storage
::vdisk_free
($storecfg, $volid); };
190 die "create failed - $err";
194 return $rpcenv->fork_worker('qmcreate', $vmid, $user, $realcmd);
197 return PVE
::QemuServer
::lock_config
($vmid, $archive ?
$restorefn : $createfn);
200 __PACKAGE__-
>register_method({
205 description
=> "Directory index",
207 additionalProperties
=> 0,
209 node
=> get_standard_option
('pve-node'),
210 vmid
=> get_standard_option
('pve-vmid'),
218 subdir
=> { type
=> 'string' },
221 links
=> [ { rel
=> 'child', href
=> "{subdir}" } ],
227 { subdir
=> 'config' },
228 { subdir
=> 'status' },
229 { subdir
=> 'unlink' },
230 { subdir
=> 'vncproxy' },
231 { subdir
=> 'migrate' },
233 { subdir
=> 'rrddata' },
239 __PACKAGE__-
>register_method({
241 path
=> '{vmid}/rrd',
243 protected
=> 1, # fixme: can we avoid that?
245 path
=> '/vms/{vmid}',
246 privs
=> [ 'VM.Audit' ],
248 description
=> "Read VM RRD statistics (returns PNG)",
250 additionalProperties
=> 0,
252 node
=> get_standard_option
('pve-node'),
253 vmid
=> get_standard_option
('pve-vmid'),
255 description
=> "Specify the time frame you are interested in.",
257 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
260 description
=> "The list of datasources you want to display.",
261 type
=> 'string', format
=> 'pve-configid-list',
264 description
=> "The RRD consolidation function",
266 enum
=> [ 'AVERAGE', 'MAX' ],
274 filename
=> { type
=> 'string' },
280 return PVE
::Cluster
::create_rrd_graph
(
281 "pve2-vm/$param->{vmid}", $param->{timeframe
},
282 $param->{ds
}, $param->{cf
});
286 __PACKAGE__-
>register_method({
288 path
=> '{vmid}/rrddata',
290 protected
=> 1, # fixme: can we avoid that?
292 path
=> '/vms/{vmid}',
293 privs
=> [ 'VM.Audit' ],
295 description
=> "Read VM RRD statistics",
297 additionalProperties
=> 0,
299 node
=> get_standard_option
('pve-node'),
300 vmid
=> get_standard_option
('pve-vmid'),
302 description
=> "Specify the time frame you are interested in.",
304 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
307 description
=> "The RRD consolidation function",
309 enum
=> [ 'AVERAGE', 'MAX' ],
324 return PVE
::Cluster
::create_rrd_data
(
325 "pve2-vm/$param->{vmid}", $param->{timeframe
}, $param->{cf
});
329 __PACKAGE__-
>register_method({
331 path
=> '{vmid}/config',
334 description
=> "Get virtual machine configuration.",
336 additionalProperties
=> 0,
338 node
=> get_standard_option
('pve-node'),
339 vmid
=> get_standard_option
('pve-vmid'),
347 description
=> 'SHA1 digest of configuration file. This can be used to prevent concurrent modifications.',
354 my $conf = PVE
::QemuServer
::load_config
($param->{vmid
});
359 __PACKAGE__-
>register_method({
361 path
=> '{vmid}/config',
365 description
=> "Set virtual machine options.",
367 additionalProperties
=> 0,
368 properties
=> PVE
::QemuServer
::json_config_properties
(
370 node
=> get_standard_option
('pve-node'),
371 vmid
=> get_standard_option
('pve-vmid'),
372 skiplock
=> get_standard_option
('skiplock'),
374 type
=> 'string', format
=> 'pve-configid-list',
375 description
=> "A list of settings you want to delete.",
380 description
=> $opt_force_description,
382 requires
=> 'delete',
386 description
=> 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
392 returns
=> { type
=> 'null'},
396 my $rpcenv = PVE
::RPCEnvironment
::get
();
398 my $user = $rpcenv->get_user();
400 my $node = extract_param
($param, 'node');
402 my $vmid = extract_param
($param, 'vmid');
404 my $digest = extract_param
($param, 'digest');
406 my @paramarr = (); # used for log message
407 foreach my $key (keys %$param) {
408 push @paramarr, "-$key", $param->{$key};
411 my $skiplock = extract_param
($param, 'skiplock');
412 raise_param_exc
({ skiplock
=> "Only root may use this option." })
413 if $skiplock && $user ne 'root@pam';
415 my $delete = extract_param
($param, 'delete');
416 my $force = extract_param
($param, 'force');
418 die "no options specified\n" if !$delete && !scalar(keys %$param);
420 my $storecfg = PVE
::Storage
::config
();
422 &$resolve_cdrom_alias($param);
427 foreach my $opt (keys %$param) {
428 if (PVE
::QemuServer
::valid_drivename
($opt)) {
429 my $drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
430 raise_param_exc
({ $opt => "unable to parse drive options" }) if !$drive;
431 if ($drive->{file
} eq 'eject') {
433 delete $param->{$opt};
437 PVE
::QemuServer
::cleanup_drive_path
($opt, $storecfg, $drive);
438 $param->{$opt} = PVE
::QemuServer
::print_drive
($vmid, $drive);
440 if (PVE
::QemuServer
::drive_is_cdrom
($drive)) {
441 $cdchange->{$opt} = PVE
::QemuServer
::get_iso_path
($storecfg, $vmid, $drive->{file
});
446 foreach my $opt (PVE
::Tools
::split_list
($delete)) {
447 $opt = 'ide2' if $opt eq 'cdrom';
448 die "you can't use '-$opt' and '-delete $opt' at the same time\n"
449 if defined($param->{$opt});
452 PVE
::QemuServer
::add_random_macs
($param);
458 my $conf = PVE
::QemuServer
::load_config
($vmid);
460 die "checksum missmatch (file change by other user?)\n"
461 if $digest && $digest ne $conf->{digest
};
463 PVE
::QemuServer
::check_lock
($conf) if !$skiplock;
465 PVE
::Cluster
::log_msg
('info', $user, "update VM $vmid: " . join (' ', @paramarr));
467 foreach my $opt (keys %$eject) {
469 my $drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
470 $cdchange->{$opt} = undef if PVE
::QemuServer
::drive_is_cdrom
($drive);
472 raise_param_exc
({ $opt => "eject failed - drive does not exist." });
476 foreach my $opt (keys %$param) {
477 next if !PVE
::QemuServer
::valid_drivename
($opt);
478 next if !$conf->{$opt};
479 my $old_drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
480 next if PVE
::QemuServer
::drive_is_cdrom
($old_drive);
481 my $new_drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
482 if ($new_drive->{file
} ne $old_drive->{file
}) {
484 eval { ($path, $owner) = PVE
::Storage
::path
($storecfg, $old_drive->{file
}); };
485 if ($owner && ($owner == $vmid)) {
486 PVE
::QemuServer
::add_unused_volume
($conf, $param, $old_drive->{file
});
493 foreach my $opt (PVE
::Tools
::split_list
($delete)) {
494 $opt = 'ide2' if $opt eq 'cdrom';
495 if (!PVE
::QemuServer
::option_exists
($opt)) {
496 raise_param_exc
({ delete => "unknown option '$opt'" });
498 next if !defined($conf->{$opt});
499 if (PVE
::QemuServer
::valid_drivename
($opt)) {
500 PVE
::QemuServer
::vm_devicedel
($vmid, $conf, $opt);
501 my $drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
502 if (PVE
::QemuServer
::drive_is_cdrom
($drive)) {
503 $cdchange->{$opt} = undef;
505 my $volid = $drive->{file
};
507 if ($volid !~ m
|^/|) {
509 eval { ($path, $owner) = PVE
::Storage
::path
($storecfg, $volid); };
510 if ($owner && ($owner == $vmid)) {
512 push @$vollist, $volid;
514 PVE
::QemuServer
::add_unused_volume
($conf, $param, $volid);
519 } elsif ($opt =~ m/^unused/) {
520 push @$vollist, $conf->{$opt};
526 PVE
::QemuServer
::create_disks
($storecfg, $vmid, $param, $conf);
528 PVE
::QemuServer
::change_config_nolock
($vmid, $param, $unset, 1);
530 return if !PVE
::QemuServer
::check_running
($vmid);
532 foreach my $opt (keys %$cdchange) {
533 my $qdn = PVE
::QemuServer
::qemu_drive_name
($opt, 'cdrom');
534 my $path = $cdchange->{$opt};
535 PVE
::QemuServer
::vm_monitor_command
($vmid, "eject $qdn", 0);
536 PVE
::QemuServer
::vm_monitor_command
($vmid, "change $qdn \"$path\"", 0) if $path;
540 PVE::QemuServer::lock_config($vmid, $updatefn);
542 foreach my $volid (@$vollist) {
543 eval { PVE::Storage::vdisk_free($storecfg, $volid); };
552 __PACKAGE__->register_method({
553 name => 'destroy_vm',
558 description => "Destroy the vm
(also
delete all used
/owned volumes
).",
560 additionalProperties => 0,
562 node => get_standard_option('pve-node'),
563 vmid => get_standard_option('pve-vmid'),
564 skiplock => get_standard_option('skiplock'),
573 my $rpcenv = PVE::RPCEnvironment::get();
575 my $user = $rpcenv->get_user();
577 my $vmid = $param->{vmid};
579 my $skiplock = $param->{skiplock};
580 raise_param_exc({ skiplock => "Only root may
use this option
." })
581 if $skiplock && $user ne 'root@pam';
584 my $conf = PVE::QemuServer::load_config($vmid);
586 my $storecfg = PVE::Storage::config();
589 PVE::QemuServer::vm_destroy($storecfg, $vmid, $skiplock);
592 return $rpcenv->fork_worker('qmdestroy', $vmid, $user, $realcmd);
595 __PACKAGE__->register_method({
597 path => '{vmid}/unlink',
601 description => "Unlink
/delete disk images
.",
603 additionalProperties => 0,
605 node => get_standard_option('pve-node'),
606 vmid => get_standard_option('pve-vmid'),
608 type => 'string', format => 'pve-configid-list',
609 description => "A list of disk IDs you want to
delete.",
613 description => $opt_force_description,
618 returns => { type => 'null'},
622 $param->{delete} = extract_param($param, 'idlist');
624 __PACKAGE__->update_vm($param);
631 __PACKAGE__->register_method({
633 path => '{vmid}/vncproxy',
637 path => '/vms/{vmid}',
638 privs => [ 'VM.Console' ],
640 description => "Creates a TCP VNC proxy connections
.",
642 additionalProperties => 0,
644 node => get_standard_option('pve-node'),
645 vmid => get_standard_option('pve-vmid'),
649 additionalProperties => 0,
651 user => { type => 'string' },
652 ticket => { type => 'string' },
653 cert => { type => 'string' },
654 port => { type => 'integer' },
655 upid => { type => 'string' },
661 my $rpcenv = PVE::RPCEnvironment::get();
663 my $user = $rpcenv->get_user();
664 my $ticket = PVE::AccessControl::assemble_ticket($user);
666 my $vmid = $param->{vmid};
667 my $node = $param->{node};
669 $sslcert = PVE::Tools::file_get_contents("/etc/pve
/pve-root-ca
.pem
", 8192)
672 my $port = PVE::Tools::next_vnc_port();
676 if ($node ne PVE::INotify::nodename()) {
677 $remip = PVE::Cluster::remote_node_ip($node);
680 # NOTE: kvm VNC traffic is already TLS encrypted,
681 # so we select the fastest chipher here (or 'none'?)
682 my $remcmd = $remip ? ['/usr/bin/ssh', '-T', '-o', 'BatchMode=yes',
683 '-c', 'blowfish-cbc', $remip] : [];
690 syslog('info', "starting vnc proxy
$upid\n");
692 my $qmcmd = [@$remcmd, "/usr/sbin
/qm
", 'vncproxy', $vmid];
694 my $qmstr = join(' ', @$qmcmd);
696 # also redirect stderr (else we get RFB protocol errors)
697 my $cmd = ['/bin/nc', '-l', '-p', $port, '-w', $timeout, '-c', "$qmstr 2>/dev/null
"];
699 PVE::Tools::run_command($cmd);
704 my $upid = $rpcenv->fork_worker('vncproxy', $vmid, $user, $realcmd);
715 __PACKAGE__->register_method({
717 path => '{vmid}/status',
720 description => "Directory
index",
722 additionalProperties => 0,
724 node => get_standard_option('pve-node'),
725 vmid => get_standard_option('pve-vmid'),
733 subdir => { type => 'string' },
736 links => [ { rel => 'child', href => "{subdir
}" } ],
742 my $conf = PVE::QemuServer::load_config($param->{vmid});
745 { subdir => 'current' },
746 { subdir => 'start' },
747 { subdir => 'stop' },
753 __PACKAGE__->register_method({
755 path => '{vmid}/status/current',
758 protected => 1, # qemu pid files are only readable by root
759 description => "Get virtual machine status
.",
761 additionalProperties => 0,
763 node => get_standard_option('pve-node'),
764 vmid => get_standard_option('pve-vmid'),
767 returns => { type => 'object' },
772 my $conf = PVE::QemuServer::load_config($param->{vmid});
774 my $vmstatus = PVE::QemuServer::vmstatus($param->{vmid});
776 return $vmstatus->{$param->{vmid}};
779 __PACKAGE__->register_method({
781 path => '{vmid}/status/start',
785 description => "Start virtual machine
.",
787 additionalProperties => 0,
789 node => get_standard_option('pve-node'),
790 vmid => get_standard_option('pve-vmid'),
791 skiplock => get_standard_option('skiplock'),
792 stateuri => get_standard_option('pve-qm-stateuri'),
801 my $rpcenv = PVE::RPCEnvironment::get();
803 my $user = $rpcenv->get_user();
805 my $node = extract_param($param, 'node');
807 my $vmid = extract_param($param, 'vmid');
809 my $stateuri = extract_param($param, 'stateuri');
810 raise_param_exc({ stateuri => "Only root may
use this option
." })
811 if $stateuri && $user ne 'root@pam';
813 my $skiplock = extract_param($param, 'skiplock');
814 raise_param_exc({ skiplock => "Only root may
use this option
." })
815 if $skiplock && $user ne 'root@pam';
817 my $storecfg = PVE::Storage::config();
822 syslog('info', "start VM
$vmid: $upid\n");
824 PVE::QemuServer::vm_start($storecfg, $vmid, $stateuri, $skiplock);
829 return $rpcenv->fork_worker('qmstart', $vmid, $user, $realcmd);
832 __PACKAGE__->register_method({
834 path => '{vmid}/status/stop',
838 description => "Stop virtual machine
.",
840 additionalProperties => 0,
842 node => get_standard_option('pve-node'),
843 vmid => get_standard_option('pve-vmid'),
844 skiplock => get_standard_option('skiplock'),
846 description => "Wait maximal timeout seconds
.",
859 my $rpcenv = PVE::RPCEnvironment::get();
861 my $user = $rpcenv->get_user();
863 my $node = extract_param($param, 'node');
865 my $vmid = extract_param($param, 'vmid');
867 my $skiplock = extract_param($param, 'skiplock');
868 raise_param_exc({ skiplock => "Only root may
use this option
." })
869 if $skiplock && $user ne 'root@pam';
874 syslog('info', "stop VM
$vmid: $upid\n");
876 PVE::QemuServer::vm_stop($vmid, $skiplock);
878 my $pid = PVE::QemuServer::check_running ($vmid);
880 if ($pid && $param->{timeout}) {
881 print "waiting
until VM
$vmid stopps
(PID
$pid)\n";
884 while (($count < $param->{timeout}) &&
885 PVE::QemuServer::check_running($vmid)) {
890 die "wait failed
- got timeout
\n" if PVE::QemuServer::check_running($vmid);
896 return $rpcenv->fork_worker('qmstop', $vmid, $user, $realcmd);
899 __PACKAGE__->register_method({
901 path => '{vmid}/status/reset',
905 description => "Reset virtual machine
.",
907 additionalProperties => 0,
909 node => get_standard_option('pve-node'),
910 vmid => get_standard_option('pve-vmid'),
911 skiplock => get_standard_option('skiplock'),
920 my $rpcenv = PVE::RPCEnvironment::get();
922 my $user = $rpcenv->get_user();
924 my $node = extract_param($param, 'node');
926 my $vmid = extract_param($param, 'vmid');
928 my $skiplock = extract_param($param, 'skiplock');
929 raise_param_exc({ skiplock => "Only root may
use this option
." })
930 if $skiplock && $user ne 'root@pam';
935 syslog('info', "reset VM
$vmid: $upid\n");
937 PVE::QemuServer::vm_reset($vmid, $skiplock);
942 return $rpcenv->fork_worker('qmreset', $vmid, $user, $realcmd);
945 __PACKAGE__->register_method({
946 name => 'vm_shutdown',
947 path => '{vmid}/status/shutdown',
951 description => "Shutdown virtual machine
.",
953 additionalProperties => 0,
955 node => get_standard_option('pve-node'),
956 vmid => get_standard_option('pve-vmid'),
957 skiplock => get_standard_option('skiplock'),
959 description => "Wait maximal timeout seconds
.",
972 my $rpcenv = PVE::RPCEnvironment::get();
974 my $user = $rpcenv->get_user();
976 my $node = extract_param($param, 'node');
978 my $vmid = extract_param($param, 'vmid');
980 my $skiplock = extract_param($param, 'skiplock');
981 raise_param_exc({ skiplock => "Only root may
use this option
." })
982 if $skiplock && $user ne 'root@pam';
987 syslog('info', "shutdown VM
$vmid: $upid\n");
989 PVE::QemuServer::vm_shutdown($vmid, $skiplock);
991 my $pid = PVE::QemuServer::check_running ($vmid);
993 if ($pid && $param->{timeout}) {
994 print "waiting
until VM
$vmid stopps
(PID
$pid)\n";
997 while (($count < $param->{timeout}) &&
998 PVE::QemuServer::check_running($vmid)) {
1003 die "wait failed
- got timeout
\n" if PVE::QemuServer::check_running($vmid);
1009 return $rpcenv->fork_worker('qmshutdown', $vmid, $user, $realcmd);
1012 __PACKAGE__->register_method({
1013 name => 'vm_suspend',
1014 path => '{vmid}/status/suspend',
1018 description => "Suspend virtual machine
.",
1020 additionalProperties => 0,
1022 node => get_standard_option('pve-node'),
1023 vmid => get_standard_option('pve-vmid'),
1024 skiplock => get_standard_option('skiplock'),
1033 my $rpcenv = PVE::RPCEnvironment::get();
1035 my $user = $rpcenv->get_user();
1037 my $node = extract_param($param, 'node');
1039 my $vmid = extract_param($param, 'vmid');
1041 my $skiplock = extract_param($param, 'skiplock');
1042 raise_param_exc({ skiplock => "Only root may
use this option
." })
1043 if $skiplock && $user ne 'root@pam';
1048 syslog('info', "suspend VM
$vmid: $upid\n");
1050 PVE::QemuServer::vm_suspend($vmid, $skiplock);
1055 return $rpcenv->fork_worker('qmsuspend', $vmid, $user, $realcmd);
1058 __PACKAGE__->register_method({
1059 name => 'vm_resume',
1060 path => '{vmid}/status/resume',
1064 description => "Resume virtual machine
.",
1066 additionalProperties => 0,
1068 node => get_standard_option('pve-node'),
1069 vmid => get_standard_option('pve-vmid'),
1070 skiplock => get_standard_option('skiplock'),
1079 my $rpcenv = PVE::RPCEnvironment::get();
1081 my $user = $rpcenv->get_user();
1083 my $node = extract_param($param, 'node');
1085 my $vmid = extract_param($param, 'vmid');
1087 my $skiplock = extract_param($param, 'skiplock');
1088 raise_param_exc({ skiplock => "Only root may
use this option
." })
1089 if $skiplock && $user ne 'root@pam';
1094 syslog('info', "resume VM
$vmid: $upid\n");
1096 PVE::QemuServer::vm_resume($vmid, $skiplock);
1101 return $rpcenv->fork_worker('qmresume', $vmid, $user, $realcmd);
1104 __PACKAGE__->register_method({
1105 name => 'vm_sendkey',
1106 path => '{vmid}/sendkey',
1110 description => "Send key event to virtual machine
.",
1112 additionalProperties => 0,
1114 node => get_standard_option('pve-node'),
1115 vmid => get_standard_option('pve-vmid'),
1116 skiplock => get_standard_option('skiplock'),
1118 description => "The key
(qemu monitor encoding
).",
1123 returns => { type => 'null'},
1127 my $rpcenv = PVE::RPCEnvironment::get();
1129 my $user = $rpcenv->get_user();
1131 my $node = extract_param($param, 'node');
1133 my $vmid = extract_param($param, 'vmid');
1135 my $skiplock = extract_param($param, 'skiplock');
1136 raise_param_exc({ skiplock => "Only root may
use this option
." })
1137 if $skiplock && $user ne 'root@pam';
1139 PVE::QemuServer::vm_sendkey($vmid, $skiplock, $param->{key});
1144 __PACKAGE__->register_method({
1145 name => 'migrate_vm',
1146 path => '{vmid}/migrate',
1150 description => "Migrate virtual machine
. Creates a new migration task
.",
1152 additionalProperties => 0,
1154 node => get_standard_option('pve-node'),
1155 vmid => get_standard_option('pve-vmid'),
1156 target => get_standard_option('pve-node', { description => "Target node
." }),
1159 description => "Use online
/live migration
.",
1164 description => "Allow to migrate VMs which
use local devices
. Only root may
use this option
.",
1171 description => "the task ID
.",
1176 my $rpcenv = PVE::RPCEnvironment::get();
1178 my $user = $rpcenv->get_user();
1180 my $target = extract_param($param, 'target');
1182 my $localnode = PVE::INotify::nodename();
1183 raise_param_exc({ target => "target
is local node
."}) if $target eq $localnode;
1185 PVE::Cluster::check_cfs_quorum();
1187 PVE::Cluster::check_node_exists($target);
1189 my $targetip = PVE::Cluster::remote_node_ip($target);
1191 my $vmid = extract_param($param, 'vmid');
1193 raise_param_exc({ force => "Only root may
use this option
." }) if $user ne 'root@pam';
1196 PVE::QemuServer::load_config($vmid);
1198 # try to detect errors early
1199 if (PVE::QemuServer::check_running($vmid)) {
1200 die "cant migrate running VM without
--online
\n"
1201 if !$param->{online};
1207 PVE::QemuMigrate::migrate($target, $targetip, $vmid, $param->{online}, $param->{force});
1210 my $upid = $rpcenv->fork_worker('qmigrate', $vmid, $user, $realcmd);