1 package PVE
::API2
::Qemu
;
9 use PVE
::Tools
qw(extract_param);
10 use PVE
::Exception
qw(raise raise_param_exc);
12 use PVE
::JSONSchema
qw(get_standard_option);
16 use PVE
::RPCEnvironment
;
17 use PVE
::AccessControl
;
20 use Data
::Dumper
; # fixme: remove
22 use base
qw(PVE::RESTHandler);
24 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.";
26 my $resolve_cdrom_alias = sub {
29 if (my $value = $param->{cdrom
}) {
30 $value .= ",media=cdrom" if $value !~ m/media=/;
31 $param->{ide2
} = $value;
32 delete $param->{cdrom
};
36 __PACKAGE__-
>register_method({
40 description
=> "Virtual machine index (per node).",
42 protected
=> 1, # qemu pid files are only readable by root
44 additionalProperties
=> 0,
46 node
=> get_standard_option
('pve-node'),
55 links
=> [ { rel
=> 'child', href
=> "{vmid}" } ],
60 my $vmstatus = PVE
::QemuServer
::vmstatus
();
62 return PVE
::RESTHandler
::hash_to_array
($vmstatus, 'vmid');
66 __PACKAGE__-
>register_method({
70 description
=> "Create or restore a virtual machine.",
74 additionalProperties
=> 0,
75 properties
=> PVE
::QemuServer
::json_config_properties
(
77 node
=> get_standard_option
('pve-node'),
78 vmid
=> get_standard_option
('pve-vmid'),
80 description
=> "The backup file.",
85 storage
=> get_standard_option
('pve-storage-id', {
86 description
=> "Default storage.",
92 description
=> "Allow to overwrite existing VM.",
93 requires
=> 'archive',
98 description
=> "Assign a unique random ethernet address.",
99 requires
=> 'archive',
109 my $rpcenv = PVE
::RPCEnvironment
::get
();
111 my $user = $rpcenv->get_user();
113 my $node = extract_param
($param, 'node');
115 my $vmid = extract_param
($param, 'vmid');
117 my $archive = extract_param
($param, 'archive');
119 my $storage = extract_param
($param, 'storage');
121 my $force = extract_param
($param, 'force');
123 my $unique = extract_param
($param, 'unique');
125 my $filename = PVE
::QemuServer
::config_file
($vmid);
127 my $storecfg = PVE
::Storage
::config
();
129 PVE
::Cluster
::check_cfs_quorum
();
132 &$resolve_cdrom_alias($param);
134 foreach my $opt (keys %$param) {
135 if (PVE
::QemuServer
::valid_drivename
($opt)) {
136 my $drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
137 raise_param_exc
({ $opt => "unable to parse drive options" }) if !$drive;
139 PVE
::QemuServer
::cleanup_drive_path
($opt, $storecfg, $drive);
140 $param->{$opt} = PVE
::QemuServer
::print_drive
($vmid, $drive);
144 PVE
::QemuServer
::add_random_macs
($param);
146 my $keystr = join(' ', keys %$param);
147 raise_param_exc
({ archive
=> "option conflicts with other options ($keystr)"}) if $keystr;
149 if ($archive eq '-') {
150 die "pipe requires cli environment\n"
151 && $rpcenv->{type
} ne 'cli';
154 if (PVE
::Storage
::parse_volume_id
($archive, 1)) {
155 $path = PVE
::Storage
::path
($storecfg, $archive);
157 raise_param_exc
({ archive
=> "Only root can pass arbitrary paths." })
158 if $user ne 'root@pam';
160 $path = abs_path
($archive);
162 die "can't find archive file '$archive'\n" if !($path && -f
$path);
167 my $restorefn = sub {
170 die "unable to restore vm $vmid: config file already exists\n"
173 die "unable to restore vm $vmid: vm is running\n"
174 if PVE
::QemuServer
::check_running
($vmid);
176 # destroy existing data - keep empty config
177 PVE
::QemuServer
::destroy_vm
($storecfg, $vmid, 1);
181 PVE
::QemuServer
::restore_archive
($archive, $vmid, {
183 unique
=> $unique });
186 return $rpcenv->fork_worker('qmrestore', $vmid, $user, $realcmd);
191 # second test (after locking test is accurate)
192 die "unable to create vm $vmid: config file already exists\n"
200 $vollist = PVE
::QemuServer
::create_disks
($storecfg, $vmid, $param, $storage);
202 # try to be smart about bootdisk
203 my @disks = PVE
::QemuServer
::disknames
();
205 foreach my $ds (reverse @disks) {
206 next if !$param->{$ds};
207 my $disk = PVE
::QemuServer
::parse_drive
($ds, $param->{$ds});
208 next if PVE
::QemuServer
::drive_is_cdrom
($disk);
212 if (!$param->{bootdisk
} && $firstdisk) {
213 $param->{bootdisk
} = $firstdisk;
216 PVE
::QemuServer
::create_conf_nolock
($vmid, $param);
221 foreach my $volid (@$vollist) {
222 eval { PVE
::Storage
::vdisk_free
($storecfg, $volid); };
225 die "create failed - $err";
229 return $rpcenv->fork_worker('qmcreate', $vmid, $user, $realcmd);
232 return PVE
::QemuServer
::lock_config
($vmid, $archive ?
$restorefn : $createfn);
235 __PACKAGE__-
>register_method({
240 description
=> "Directory index",
242 additionalProperties
=> 0,
244 node
=> get_standard_option
('pve-node'),
245 vmid
=> get_standard_option
('pve-vmid'),
253 subdir
=> { type
=> 'string' },
256 links
=> [ { rel
=> 'child', href
=> "{subdir}" } ],
262 { subdir
=> 'config' },
263 { subdir
=> 'status' },
264 { subdir
=> 'unlink' },
265 { subdir
=> 'vncproxy' },
266 { subdir
=> 'migrate' },
268 { subdir
=> 'rrddata' },
269 { subdir
=> 'monitor' },
275 __PACKAGE__-
>register_method({
277 path
=> '{vmid}/rrd',
279 protected
=> 1, # fixme: can we avoid that?
281 path
=> '/vms/{vmid}',
282 privs
=> [ 'VM.Audit' ],
284 description
=> "Read VM RRD statistics (returns PNG)",
286 additionalProperties
=> 0,
288 node
=> get_standard_option
('pve-node'),
289 vmid
=> get_standard_option
('pve-vmid'),
291 description
=> "Specify the time frame you are interested in.",
293 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
296 description
=> "The list of datasources you want to display.",
297 type
=> 'string', format
=> 'pve-configid-list',
300 description
=> "The RRD consolidation function",
302 enum
=> [ 'AVERAGE', 'MAX' ],
310 filename
=> { type
=> 'string' },
316 return PVE
::Cluster
::create_rrd_graph
(
317 "pve2-vm/$param->{vmid}", $param->{timeframe
},
318 $param->{ds
}, $param->{cf
});
322 __PACKAGE__-
>register_method({
324 path
=> '{vmid}/rrddata',
326 protected
=> 1, # fixme: can we avoid that?
328 path
=> '/vms/{vmid}',
329 privs
=> [ 'VM.Audit' ],
331 description
=> "Read VM RRD statistics",
333 additionalProperties
=> 0,
335 node
=> get_standard_option
('pve-node'),
336 vmid
=> get_standard_option
('pve-vmid'),
338 description
=> "Specify the time frame you are interested in.",
340 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
343 description
=> "The RRD consolidation function",
345 enum
=> [ 'AVERAGE', 'MAX' ],
360 return PVE
::Cluster
::create_rrd_data
(
361 "pve2-vm/$param->{vmid}", $param->{timeframe
}, $param->{cf
});
365 __PACKAGE__-
>register_method({
367 path
=> '{vmid}/config',
370 description
=> "Get virtual machine configuration.",
372 additionalProperties
=> 0,
374 node
=> get_standard_option
('pve-node'),
375 vmid
=> get_standard_option
('pve-vmid'),
383 description
=> 'SHA1 digest of configuration file. This can be used to prevent concurrent modifications.',
390 my $conf = PVE
::QemuServer
::load_config
($param->{vmid
});
395 __PACKAGE__-
>register_method({
397 path
=> '{vmid}/config',
401 description
=> "Set virtual machine options.",
403 additionalProperties
=> 0,
404 properties
=> PVE
::QemuServer
::json_config_properties
(
406 node
=> get_standard_option
('pve-node'),
407 vmid
=> get_standard_option
('pve-vmid'),
408 skiplock
=> get_standard_option
('skiplock'),
410 type
=> 'string', format
=> 'pve-configid-list',
411 description
=> "A list of settings you want to delete.",
416 description
=> $opt_force_description,
418 requires
=> 'delete',
422 description
=> 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
428 returns
=> { type
=> 'null'},
432 my $rpcenv = PVE
::RPCEnvironment
::get
();
434 my $user = $rpcenv->get_user();
436 my $node = extract_param
($param, 'node');
438 my $vmid = extract_param
($param, 'vmid');
440 my $digest = extract_param
($param, 'digest');
442 my @paramarr = (); # used for log message
443 foreach my $key (keys %$param) {
444 push @paramarr, "-$key", $param->{$key};
447 my $skiplock = extract_param
($param, 'skiplock');
448 raise_param_exc
({ skiplock
=> "Only root may use this option." })
449 if $skiplock && $user ne 'root@pam';
451 my $delete = extract_param
($param, 'delete');
452 my $force = extract_param
($param, 'force');
454 die "no options specified\n" if !$delete && !scalar(keys %$param);
456 my $storecfg = PVE
::Storage
::config
();
458 &$resolve_cdrom_alias($param);
463 foreach my $opt (keys %$param) {
464 if (PVE
::QemuServer
::valid_drivename
($opt)) {
465 my $drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
466 raise_param_exc
({ $opt => "unable to parse drive options" }) if !$drive;
467 if ($drive->{file
} eq 'eject') {
469 delete $param->{$opt};
473 PVE
::QemuServer
::cleanup_drive_path
($opt, $storecfg, $drive);
474 $param->{$opt} = PVE
::QemuServer
::print_drive
($vmid, $drive);
476 if (PVE
::QemuServer
::drive_is_cdrom
($drive)) {
477 $cdchange->{$opt} = PVE
::QemuServer
::get_iso_path
($storecfg, $vmid, $drive->{file
});
482 foreach my $opt (PVE
::Tools
::split_list
($delete)) {
483 $opt = 'ide2' if $opt eq 'cdrom';
484 die "you can't use '-$opt' and '-delete $opt' at the same time\n"
485 if defined($param->{$opt});
488 PVE
::QemuServer
::add_random_macs
($param);
494 my $conf = PVE
::QemuServer
::load_config
($vmid);
496 die "checksum missmatch (file change by other user?)\n"
497 if $digest && $digest ne $conf->{digest
};
499 PVE
::QemuServer
::check_lock
($conf) if !$skiplock;
501 PVE
::Cluster
::log_msg
('info', $user, "update VM $vmid: " . join (' ', @paramarr));
503 foreach my $opt (keys %$eject) {
505 my $drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
506 $cdchange->{$opt} = undef if PVE
::QemuServer
::drive_is_cdrom
($drive);
508 raise_param_exc
({ $opt => "eject failed - drive does not exist." });
512 foreach my $opt (keys %$param) {
513 next if !PVE
::QemuServer
::valid_drivename
($opt);
514 next if !$conf->{$opt};
515 my $old_drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
516 next if PVE
::QemuServer
::drive_is_cdrom
($old_drive);
517 my $new_drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
518 if ($new_drive->{file
} ne $old_drive->{file
}) {
520 eval { ($path, $owner) = PVE
::Storage
::path
($storecfg, $old_drive->{file
}); };
521 if ($owner && ($owner == $vmid)) {
522 PVE
::QemuServer
::add_unused_volume
($conf, $param, $old_drive->{file
});
529 foreach my $opt (PVE
::Tools
::split_list
($delete)) {
530 $opt = 'ide2' if $opt eq 'cdrom';
531 if (!PVE
::QemuServer
::option_exists
($opt)) {
532 raise_param_exc
({ delete => "unknown option '$opt'" });
534 next if !defined($conf->{$opt});
535 if (PVE
::QemuServer
::valid_drivename
($opt)) {
536 PVE
::QemuServer
::vm_devicedel
($vmid, $conf, $opt);
537 my $drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
538 if (PVE
::QemuServer
::drive_is_cdrom
($drive)) {
539 $cdchange->{$opt} = undef;
541 my $volid = $drive->{file
};
543 if ($volid !~ m
|^/|) {
545 eval { ($path, $owner) = PVE
::Storage
::path
($storecfg, $volid); };
546 if ($owner && ($owner == $vmid)) {
548 push @$vollist, $volid;
550 PVE
::QemuServer
::add_unused_volume
($conf, $param, $volid);
555 } elsif ($opt =~ m/^unused/) {
556 push @$vollist, $conf->{$opt};
562 PVE
::QemuServer
::create_disks
($storecfg, $vmid, $param, $conf);
564 PVE
::QemuServer
::change_config_nolock
($vmid, $param, $unset, 1);
566 return if !PVE
::QemuServer
::check_running
($vmid);
568 foreach my $opt (keys %$cdchange) {
569 my $qdn = PVE
::QemuServer
::qemu_drive_name
($opt, 'cdrom');
570 my $path = $cdchange->{$opt};
571 PVE
::QemuServer
::vm_monitor_command
($vmid, "eject $qdn", 0);
572 PVE
::QemuServer
::vm_monitor_command
($vmid, "change $qdn \"$path\"", 0) if $path;
576 PVE::QemuServer::lock_config($vmid, $updatefn);
578 foreach my $volid (@$vollist) {
579 eval { PVE::Storage::vdisk_free($storecfg, $volid); };
588 __PACKAGE__->register_method({
589 name => 'destroy_vm',
594 description => "Destroy the vm
(also
delete all used
/owned volumes
).",
596 additionalProperties => 0,
598 node => get_standard_option('pve-node'),
599 vmid => get_standard_option('pve-vmid'),
600 skiplock => get_standard_option('skiplock'),
609 my $rpcenv = PVE::RPCEnvironment::get();
611 my $user = $rpcenv->get_user();
613 my $vmid = $param->{vmid};
615 my $skiplock = $param->{skiplock};
616 raise_param_exc({ skiplock => "Only root may
use this option
." })
617 if $skiplock && $user ne 'root@pam';
620 my $conf = PVE::QemuServer::load_config($vmid);
622 my $storecfg = PVE::Storage::config();
627 syslog('info', "destroy VM
$vmid: $upid\n");
629 PVE::QemuServer::vm_destroy($storecfg, $vmid, $skiplock);
632 return $rpcenv->fork_worker('qmdestroy', $vmid, $user, $realcmd);
635 __PACKAGE__->register_method({
637 path => '{vmid}/unlink',
641 description => "Unlink
/delete disk images
.",
643 additionalProperties => 0,
645 node => get_standard_option('pve-node'),
646 vmid => get_standard_option('pve-vmid'),
648 type => 'string', format => 'pve-configid-list',
649 description => "A list of disk IDs you want to
delete.",
653 description => $opt_force_description,
658 returns => { type => 'null'},
662 $param->{delete} = extract_param($param, 'idlist');
664 __PACKAGE__->update_vm($param);
671 __PACKAGE__->register_method({
673 path => '{vmid}/vncproxy',
677 path => '/vms/{vmid}',
678 privs => [ 'VM.Console' ],
680 description => "Creates a TCP VNC proxy connections
.",
682 additionalProperties => 0,
684 node => get_standard_option('pve-node'),
685 vmid => get_standard_option('pve-vmid'),
689 additionalProperties => 0,
691 user => { type => 'string' },
692 ticket => { type => 'string' },
693 cert => { type => 'string' },
694 port => { type => 'integer' },
695 upid => { type => 'string' },
701 my $rpcenv = PVE::RPCEnvironment::get();
703 my $user = $rpcenv->get_user();
704 my $ticket = PVE::AccessControl::assemble_ticket($user);
706 my $vmid = $param->{vmid};
707 my $node = $param->{node};
709 $sslcert = PVE::Tools::file_get_contents("/etc/pve
/pve-root-ca
.pem
", 8192)
712 my $port = PVE::Tools::next_vnc_port();
716 if ($node ne 'localhost' && $node ne PVE::INotify::nodename()) {
717 $remip = PVE::Cluster::remote_node_ip($node);
720 # NOTE: kvm VNC traffic is already TLS encrypted,
721 # so we select the fastest chipher here (or 'none'?)
722 my $remcmd = $remip ? ['/usr/bin/ssh', '-T', '-o', 'BatchMode=yes',
723 '-c', 'blowfish-cbc', $remip] : [];
730 syslog('info', "starting vnc proxy
$upid\n");
732 my $qmcmd = [@$remcmd, "/usr/sbin
/qm
", 'vncproxy', $vmid];
734 my $qmstr = join(' ', @$qmcmd);
736 # also redirect stderr (else we get RFB protocol errors)
737 my $cmd = ['/bin/nc', '-l', '-p', $port, '-w', $timeout, '-c', "$qmstr 2>/dev/null
"];
739 PVE::Tools::run_command($cmd);
744 my $upid = $rpcenv->fork_worker('vncproxy', $vmid, $user, $realcmd);
755 __PACKAGE__->register_method({
757 path => '{vmid}/status',
760 description => "Directory
index",
762 additionalProperties => 0,
764 node => get_standard_option('pve-node'),
765 vmid => get_standard_option('pve-vmid'),
773 subdir => { type => 'string' },
776 links => [ { rel => 'child', href => "{subdir
}" } ],
782 my $conf = PVE::QemuServer::load_config($param->{vmid});
785 { subdir => 'current' },
786 { subdir => 'start' },
787 { subdir => 'stop' },
793 __PACKAGE__->register_method({
795 path => '{vmid}/status/current',
798 protected => 1, # qemu pid files are only readable by root
799 description => "Get virtual machine status
.",
801 additionalProperties => 0,
803 node => get_standard_option('pve-node'),
804 vmid => get_standard_option('pve-vmid'),
807 returns => { type => 'object' },
812 my $conf = PVE::QemuServer::load_config($param->{vmid});
814 my $vmstatus = PVE::QemuServer::vmstatus($param->{vmid});
816 return $vmstatus->{$param->{vmid}};
819 __PACKAGE__->register_method({
821 path => '{vmid}/status/start',
825 description => "Start virtual machine
.",
827 additionalProperties => 0,
829 node => get_standard_option('pve-node'),
830 vmid => get_standard_option('pve-vmid'),
831 skiplock => get_standard_option('skiplock'),
832 stateuri => get_standard_option('pve-qm-stateuri'),
841 my $rpcenv = PVE::RPCEnvironment::get();
843 my $user = $rpcenv->get_user();
845 my $node = extract_param($param, 'node');
847 my $vmid = extract_param($param, 'vmid');
849 my $stateuri = extract_param($param, 'stateuri');
850 raise_param_exc({ stateuri => "Only root may
use this option
." })
851 if $stateuri && $user ne 'root@pam';
853 my $skiplock = extract_param($param, 'skiplock');
854 raise_param_exc({ skiplock => "Only root may
use this option
." })
855 if $skiplock && $user ne 'root@pam';
857 die "VM
$vmid already running
\n" if PVE::QemuServer::check_running($vmid);
859 my $storecfg = PVE::Storage::config();
864 syslog('info', "start VM
$vmid: $upid\n");
866 PVE::QemuServer::vm_start($storecfg, $vmid, $stateuri, $skiplock);
871 return $rpcenv->fork_worker('qmstart', $vmid, $user, $realcmd);
874 __PACKAGE__->register_method({
876 path => '{vmid}/status/stop',
880 description => "Stop virtual machine
.",
882 additionalProperties => 0,
884 node => get_standard_option('pve-node'),
885 vmid => get_standard_option('pve-vmid'),
886 skiplock => get_standard_option('skiplock'),
888 description => "Wait maximal timeout seconds
.",
901 my $rpcenv = PVE::RPCEnvironment::get();
903 my $user = $rpcenv->get_user();
905 my $node = extract_param($param, 'node');
907 my $vmid = extract_param($param, 'vmid');
909 my $skiplock = extract_param($param, 'skiplock');
910 raise_param_exc({ skiplock => "Only root may
use this option
." })
911 if $skiplock && $user ne 'root@pam';
913 die "VM
$vmid not running
\n" if !PVE::QemuServer::check_running($vmid);
915 my $storecfg = PVE::Storage::config();
920 syslog('info', "stop VM
$vmid: $upid\n");
922 PVE::QemuServer::vm_stop($storecfg, $vmid, $skiplock, 0, $param->{timeout});
927 return $rpcenv->fork_worker('qmstop', $vmid, $user, $realcmd);
930 __PACKAGE__->register_method({
932 path => '{vmid}/status/reset',
936 description => "Reset virtual machine
.",
938 additionalProperties => 0,
940 node => get_standard_option('pve-node'),
941 vmid => get_standard_option('pve-vmid'),
942 skiplock => get_standard_option('skiplock'),
951 my $rpcenv = PVE::RPCEnvironment::get();
953 my $user = $rpcenv->get_user();
955 my $node = extract_param($param, 'node');
957 my $vmid = extract_param($param, 'vmid');
959 my $skiplock = extract_param($param, 'skiplock');
960 raise_param_exc({ skiplock => "Only root may
use this option
." })
961 if $skiplock && $user ne 'root@pam';
963 die "VM
$vmid not running
\n" if !PVE::QemuServer::check_running($vmid);
968 PVE::QemuServer::vm_reset($vmid, $skiplock);
973 return $rpcenv->fork_worker('qmreset', $vmid, $user, $realcmd);
976 __PACKAGE__->register_method({
977 name => 'vm_shutdown',
978 path => '{vmid}/status/shutdown',
982 description => "Shutdown virtual machine
.",
984 additionalProperties => 0,
986 node => get_standard_option('pve-node'),
987 vmid => get_standard_option('pve-vmid'),
988 skiplock => get_standard_option('skiplock'),
990 description => "Wait maximal timeout seconds
.",
1003 my $rpcenv = PVE::RPCEnvironment::get();
1005 my $user = $rpcenv->get_user();
1007 my $node = extract_param($param, 'node');
1009 my $vmid = extract_param($param, 'vmid');
1011 my $skiplock = extract_param($param, 'skiplock');
1012 raise_param_exc({ skiplock => "Only root may
use this option
." })
1013 if $skiplock && $user ne 'root@pam';
1015 die "VM
$vmid not running
\n" if !PVE::QemuServer::check_running($vmid);
1020 syslog('info', "shutdown VM
$vmid: $upid\n");
1022 PVE::QemuServer::vm_shutdown($vmid, $skiplock, $param->{timeout});
1027 return $rpcenv->fork_worker('qmshutdown', $vmid, $user, $realcmd);
1030 __PACKAGE__->register_method({
1031 name => 'vm_suspend',
1032 path => '{vmid}/status/suspend',
1036 description => "Suspend virtual machine
.",
1038 additionalProperties => 0,
1040 node => get_standard_option('pve-node'),
1041 vmid => get_standard_option('pve-vmid'),
1042 skiplock => get_standard_option('skiplock'),
1051 my $rpcenv = PVE::RPCEnvironment::get();
1053 my $user = $rpcenv->get_user();
1055 my $node = extract_param($param, 'node');
1057 my $vmid = extract_param($param, 'vmid');
1059 my $skiplock = extract_param($param, 'skiplock');
1060 raise_param_exc({ skiplock => "Only root may
use this option
." })
1061 if $skiplock && $user ne 'root@pam';
1063 die "VM
$vmid not running
\n" if !PVE::QemuServer::check_running($vmid);
1068 syslog('info', "suspend VM
$vmid: $upid\n");
1070 PVE::QemuServer::vm_suspend($vmid, $skiplock);
1075 return $rpcenv->fork_worker('qmsuspend', $vmid, $user, $realcmd);
1078 __PACKAGE__->register_method({
1079 name => 'vm_resume',
1080 path => '{vmid}/status/resume',
1084 description => "Resume virtual machine
.",
1086 additionalProperties => 0,
1088 node => get_standard_option('pve-node'),
1089 vmid => get_standard_option('pve-vmid'),
1090 skiplock => get_standard_option('skiplock'),
1099 my $rpcenv = PVE::RPCEnvironment::get();
1101 my $user = $rpcenv->get_user();
1103 my $node = extract_param($param, 'node');
1105 my $vmid = extract_param($param, 'vmid');
1107 my $skiplock = extract_param($param, 'skiplock');
1108 raise_param_exc({ skiplock => "Only root may
use this option
." })
1109 if $skiplock && $user ne 'root@pam';
1111 die "VM
$vmid already running
\n" if PVE::QemuServer::check_running($vmid);
1116 syslog('info', "resume VM
$vmid: $upid\n");
1118 PVE::QemuServer::vm_resume($vmid, $skiplock);
1123 return $rpcenv->fork_worker('qmresume', $vmid, $user, $realcmd);
1126 __PACKAGE__->register_method({
1127 name => 'vm_sendkey',
1128 path => '{vmid}/sendkey',
1132 description => "Send key event to virtual machine
.",
1134 additionalProperties => 0,
1136 node => get_standard_option('pve-node'),
1137 vmid => get_standard_option('pve-vmid'),
1138 skiplock => get_standard_option('skiplock'),
1140 description => "The key
(qemu monitor encoding
).",
1145 returns => { type => 'null'},
1149 my $rpcenv = PVE::RPCEnvironment::get();
1151 my $user = $rpcenv->get_user();
1153 my $node = extract_param($param, 'node');
1155 my $vmid = extract_param($param, 'vmid');
1157 my $skiplock = extract_param($param, 'skiplock');
1158 raise_param_exc({ skiplock => "Only root may
use this option
." })
1159 if $skiplock && $user ne 'root@pam';
1161 PVE::QemuServer::vm_sendkey($vmid, $skiplock, $param->{key});
1166 __PACKAGE__->register_method({
1167 name => 'migrate_vm',
1168 path => '{vmid}/migrate',
1172 description => "Migrate virtual machine
. Creates a new migration task
.",
1174 additionalProperties => 0,
1176 node => get_standard_option('pve-node'),
1177 vmid => get_standard_option('pve-vmid'),
1178 target => get_standard_option('pve-node', { description => "Target node
." }),
1181 description => "Use online
/live migration
.",
1186 description => "Allow to migrate VMs which
use local devices
. Only root may
use this option
.",
1193 description => "the task ID
.",
1198 my $rpcenv = PVE::RPCEnvironment::get();
1200 my $user = $rpcenv->get_user();
1202 my $target = extract_param($param, 'target');
1204 my $localnode = PVE::INotify::nodename();
1205 raise_param_exc({ target => "target
is local node
."}) if $target eq $localnode;
1207 PVE::Cluster::check_cfs_quorum();
1209 PVE::Cluster::check_node_exists($target);
1211 my $targetip = PVE::Cluster::remote_node_ip($target);
1213 my $vmid = extract_param($param, 'vmid');
1215 raise_param_exc({ force => "Only root may
use this option
." })
1216 if $param->{force} && $user ne 'root@pam';
1219 PVE::QemuServer::load_config($vmid);
1221 # try to detect errors early
1222 if (PVE::QemuServer::check_running($vmid)) {
1223 die "cant migrate running VM without
--online
\n"
1224 if !$param->{online};
1230 PVE::QemuMigrate::migrate($target, $targetip, $vmid, $param->{online}, $param->{force});
1233 my $upid = $rpcenv->fork_worker('qmigrate', $vmid, $user, $realcmd);
1238 __PACKAGE__->register_method({
1240 path => '{vmid}/monitor',
1244 description => "Execute Qemu monitor commands
.",
1246 additionalProperties => 0,
1248 node => get_standard_option('pve-node'),
1249 vmid => get_standard_option('pve-vmid'),
1252 description => "The monitor command
.",
1256 returns => { type => 'string'},
1260 my $vmid = $param->{vmid};
1262 my $conf = PVE::QemuServer::load_config ($vmid); # check if VM exists
1266 $res = PVE::QemuServer::vm_monitor_command($vmid, $param->{command});
1268 $res = "ERROR
: $@" if $@;