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';
153 if (PVE
::Storage
::parse_volume_id
($archive, 1)) {
154 $archive = PVE
::Storage
::path
($storecfg, $archive);
156 raise_param_exc
({ archive
=> "Only root can pass arbitrary paths." })
157 if $user ne 'root@pam';
159 $archive = abs_path
($archive);
161 die "can't find file '$archive'\n" if ! -f
$archive;
165 my $restorefn = sub {
168 die "unable to restore vm $vmid: config file already exists\n"
171 die "unable to restore vm $vmid: vm is running\n"
172 if PVE
::QemuServer
::check_running
($vmid);
174 # destroy existing data - keep empty config
175 PVE
::QemuServer
::destroy_vm
($storecfg, $vmid, 1);
179 PVE
::QemuServer
::restore_archive
($archive, $vmid, {
181 unique
=> $unique });
184 return $rpcenv->fork_worker('qmrestore', $vmid, $user, $realcmd);
189 # second test (after locking test is accurate)
190 die "unable to create vm $vmid: config file already exists\n"
198 $vollist = PVE
::QemuServer
::create_disks
($storecfg, $vmid, $param, $storage);
200 # try to be smart about bootdisk
201 my @disks = PVE
::QemuServer
::disknames
();
203 foreach my $ds (reverse @disks) {
204 next if !$param->{$ds};
205 my $disk = PVE
::QemuServer
::parse_drive
($ds, $param->{$ds});
206 next if PVE
::QemuServer
::drive_is_cdrom
($disk);
210 if (!$param->{bootdisk
} && $firstdisk) {
211 $param->{bootdisk
} = $firstdisk;
214 PVE
::QemuServer
::create_conf_nolock
($vmid, $param);
219 foreach my $volid (@$vollist) {
220 eval { PVE
::Storage
::vdisk_free
($storecfg, $volid); };
223 die "create failed - $err";
227 return $rpcenv->fork_worker('qmcreate', $vmid, $user, $realcmd);
230 return PVE
::QemuServer
::lock_config
($vmid, $archive ?
$restorefn : $createfn);
233 __PACKAGE__-
>register_method({
238 description
=> "Directory index",
240 additionalProperties
=> 0,
242 node
=> get_standard_option
('pve-node'),
243 vmid
=> get_standard_option
('pve-vmid'),
251 subdir
=> { type
=> 'string' },
254 links
=> [ { rel
=> 'child', href
=> "{subdir}" } ],
260 { subdir
=> 'config' },
261 { subdir
=> 'status' },
262 { subdir
=> 'unlink' },
263 { subdir
=> 'vncproxy' },
264 { subdir
=> 'migrate' },
266 { subdir
=> 'rrddata' },
267 { subdir
=> 'monitor' },
273 __PACKAGE__-
>register_method({
275 path
=> '{vmid}/rrd',
277 protected
=> 1, # fixme: can we avoid that?
279 path
=> '/vms/{vmid}',
280 privs
=> [ 'VM.Audit' ],
282 description
=> "Read VM RRD statistics (returns PNG)",
284 additionalProperties
=> 0,
286 node
=> get_standard_option
('pve-node'),
287 vmid
=> get_standard_option
('pve-vmid'),
289 description
=> "Specify the time frame you are interested in.",
291 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
294 description
=> "The list of datasources you want to display.",
295 type
=> 'string', format
=> 'pve-configid-list',
298 description
=> "The RRD consolidation function",
300 enum
=> [ 'AVERAGE', 'MAX' ],
308 filename
=> { type
=> 'string' },
314 return PVE
::Cluster
::create_rrd_graph
(
315 "pve2-vm/$param->{vmid}", $param->{timeframe
},
316 $param->{ds
}, $param->{cf
});
320 __PACKAGE__-
>register_method({
322 path
=> '{vmid}/rrddata',
324 protected
=> 1, # fixme: can we avoid that?
326 path
=> '/vms/{vmid}',
327 privs
=> [ 'VM.Audit' ],
329 description
=> "Read VM RRD statistics",
331 additionalProperties
=> 0,
333 node
=> get_standard_option
('pve-node'),
334 vmid
=> get_standard_option
('pve-vmid'),
336 description
=> "Specify the time frame you are interested in.",
338 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
341 description
=> "The RRD consolidation function",
343 enum
=> [ 'AVERAGE', 'MAX' ],
358 return PVE
::Cluster
::create_rrd_data
(
359 "pve2-vm/$param->{vmid}", $param->{timeframe
}, $param->{cf
});
363 __PACKAGE__-
>register_method({
365 path
=> '{vmid}/config',
368 description
=> "Get virtual machine configuration.",
370 additionalProperties
=> 0,
372 node
=> get_standard_option
('pve-node'),
373 vmid
=> get_standard_option
('pve-vmid'),
381 description
=> 'SHA1 digest of configuration file. This can be used to prevent concurrent modifications.',
388 my $conf = PVE
::QemuServer
::load_config
($param->{vmid
});
393 __PACKAGE__-
>register_method({
395 path
=> '{vmid}/config',
399 description
=> "Set virtual machine options.",
401 additionalProperties
=> 0,
402 properties
=> PVE
::QemuServer
::json_config_properties
(
404 node
=> get_standard_option
('pve-node'),
405 vmid
=> get_standard_option
('pve-vmid'),
406 skiplock
=> get_standard_option
('skiplock'),
408 type
=> 'string', format
=> 'pve-configid-list',
409 description
=> "A list of settings you want to delete.",
414 description
=> $opt_force_description,
416 requires
=> 'delete',
420 description
=> 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
426 returns
=> { type
=> 'null'},
430 my $rpcenv = PVE
::RPCEnvironment
::get
();
432 my $user = $rpcenv->get_user();
434 my $node = extract_param
($param, 'node');
436 my $vmid = extract_param
($param, 'vmid');
438 my $digest = extract_param
($param, 'digest');
440 my @paramarr = (); # used for log message
441 foreach my $key (keys %$param) {
442 push @paramarr, "-$key", $param->{$key};
445 my $skiplock = extract_param
($param, 'skiplock');
446 raise_param_exc
({ skiplock
=> "Only root may use this option." })
447 if $skiplock && $user ne 'root@pam';
449 my $delete = extract_param
($param, 'delete');
450 my $force = extract_param
($param, 'force');
452 die "no options specified\n" if !$delete && !scalar(keys %$param);
454 my $storecfg = PVE
::Storage
::config
();
456 &$resolve_cdrom_alias($param);
461 foreach my $opt (keys %$param) {
462 if (PVE
::QemuServer
::valid_drivename
($opt)) {
463 my $drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
464 raise_param_exc
({ $opt => "unable to parse drive options" }) if !$drive;
465 if ($drive->{file
} eq 'eject') {
467 delete $param->{$opt};
471 PVE
::QemuServer
::cleanup_drive_path
($opt, $storecfg, $drive);
472 $param->{$opt} = PVE
::QemuServer
::print_drive
($vmid, $drive);
474 if (PVE
::QemuServer
::drive_is_cdrom
($drive)) {
475 $cdchange->{$opt} = PVE
::QemuServer
::get_iso_path
($storecfg, $vmid, $drive->{file
});
480 foreach my $opt (PVE
::Tools
::split_list
($delete)) {
481 $opt = 'ide2' if $opt eq 'cdrom';
482 die "you can't use '-$opt' and '-delete $opt' at the same time\n"
483 if defined($param->{$opt});
486 PVE
::QemuServer
::add_random_macs
($param);
492 my $conf = PVE
::QemuServer
::load_config
($vmid);
494 die "checksum missmatch (file change by other user?)\n"
495 if $digest && $digest ne $conf->{digest
};
497 PVE
::QemuServer
::check_lock
($conf) if !$skiplock;
499 PVE
::Cluster
::log_msg
('info', $user, "update VM $vmid: " . join (' ', @paramarr));
501 foreach my $opt (keys %$eject) {
503 my $drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
504 $cdchange->{$opt} = undef if PVE
::QemuServer
::drive_is_cdrom
($drive);
506 raise_param_exc
({ $opt => "eject failed - drive does not exist." });
510 foreach my $opt (keys %$param) {
511 next if !PVE
::QemuServer
::valid_drivename
($opt);
512 next if !$conf->{$opt};
513 my $old_drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
514 next if PVE
::QemuServer
::drive_is_cdrom
($old_drive);
515 my $new_drive = PVE
::QemuServer
::parse_drive
($opt, $param->{$opt});
516 if ($new_drive->{file
} ne $old_drive->{file
}) {
518 eval { ($path, $owner) = PVE
::Storage
::path
($storecfg, $old_drive->{file
}); };
519 if ($owner && ($owner == $vmid)) {
520 PVE
::QemuServer
::add_unused_volume
($conf, $param, $old_drive->{file
});
527 foreach my $opt (PVE
::Tools
::split_list
($delete)) {
528 $opt = 'ide2' if $opt eq 'cdrom';
529 if (!PVE
::QemuServer
::option_exists
($opt)) {
530 raise_param_exc
({ delete => "unknown option '$opt'" });
532 next if !defined($conf->{$opt});
533 if (PVE
::QemuServer
::valid_drivename
($opt)) {
534 PVE
::QemuServer
::vm_devicedel
($vmid, $conf, $opt);
535 my $drive = PVE
::QemuServer
::parse_drive
($opt, $conf->{$opt});
536 if (PVE
::QemuServer
::drive_is_cdrom
($drive)) {
537 $cdchange->{$opt} = undef;
539 my $volid = $drive->{file
};
541 if ($volid !~ m
|^/|) {
543 eval { ($path, $owner) = PVE
::Storage
::path
($storecfg, $volid); };
544 if ($owner && ($owner == $vmid)) {
546 push @$vollist, $volid;
548 PVE
::QemuServer
::add_unused_volume
($conf, $param, $volid);
553 } elsif ($opt =~ m/^unused/) {
554 push @$vollist, $conf->{$opt};
560 PVE
::QemuServer
::create_disks
($storecfg, $vmid, $param, $conf);
562 PVE
::QemuServer
::change_config_nolock
($vmid, $param, $unset, 1);
564 return if !PVE
::QemuServer
::check_running
($vmid);
566 foreach my $opt (keys %$cdchange) {
567 my $qdn = PVE
::QemuServer
::qemu_drive_name
($opt, 'cdrom');
568 my $path = $cdchange->{$opt};
569 PVE
::QemuServer
::vm_monitor_command
($vmid, "eject $qdn", 0);
570 PVE
::QemuServer
::vm_monitor_command
($vmid, "change $qdn \"$path\"", 0) if $path;
574 PVE::QemuServer::lock_config($vmid, $updatefn);
576 foreach my $volid (@$vollist) {
577 eval { PVE::Storage::vdisk_free($storecfg, $volid); };
586 __PACKAGE__->register_method({
587 name => 'destroy_vm',
592 description => "Destroy the vm
(also
delete all used
/owned volumes
).",
594 additionalProperties => 0,
596 node => get_standard_option('pve-node'),
597 vmid => get_standard_option('pve-vmid'),
598 skiplock => get_standard_option('skiplock'),
607 my $rpcenv = PVE::RPCEnvironment::get();
609 my $user = $rpcenv->get_user();
611 my $vmid = $param->{vmid};
613 my $skiplock = $param->{skiplock};
614 raise_param_exc({ skiplock => "Only root may
use this option
." })
615 if $skiplock && $user ne 'root@pam';
618 my $conf = PVE::QemuServer::load_config($vmid);
620 my $storecfg = PVE::Storage::config();
623 PVE::QemuServer::vm_destroy($storecfg, $vmid, $skiplock);
626 return $rpcenv->fork_worker('qmdestroy', $vmid, $user, $realcmd);
629 __PACKAGE__->register_method({
631 path => '{vmid}/unlink',
635 description => "Unlink
/delete disk images
.",
637 additionalProperties => 0,
639 node => get_standard_option('pve-node'),
640 vmid => get_standard_option('pve-vmid'),
642 type => 'string', format => 'pve-configid-list',
643 description => "A list of disk IDs you want to
delete.",
647 description => $opt_force_description,
652 returns => { type => 'null'},
656 $param->{delete} = extract_param($param, 'idlist');
658 __PACKAGE__->update_vm($param);
665 __PACKAGE__->register_method({
667 path => '{vmid}/vncproxy',
671 path => '/vms/{vmid}',
672 privs => [ 'VM.Console' ],
674 description => "Creates a TCP VNC proxy connections
.",
676 additionalProperties => 0,
678 node => get_standard_option('pve-node'),
679 vmid => get_standard_option('pve-vmid'),
683 additionalProperties => 0,
685 user => { type => 'string' },
686 ticket => { type => 'string' },
687 cert => { type => 'string' },
688 port => { type => 'integer' },
689 upid => { type => 'string' },
695 my $rpcenv = PVE::RPCEnvironment::get();
697 my $user = $rpcenv->get_user();
698 my $ticket = PVE::AccessControl::assemble_ticket($user);
700 my $vmid = $param->{vmid};
701 my $node = $param->{node};
703 $sslcert = PVE::Tools::file_get_contents("/etc/pve
/pve-root-ca
.pem
", 8192)
706 my $port = PVE::Tools::next_vnc_port();
710 if ($node ne 'localhost' && $node ne PVE::INotify::nodename()) {
711 $remip = PVE::Cluster::remote_node_ip($node);
714 # NOTE: kvm VNC traffic is already TLS encrypted,
715 # so we select the fastest chipher here (or 'none'?)
716 my $remcmd = $remip ? ['/usr/bin/ssh', '-T', '-o', 'BatchMode=yes',
717 '-c', 'blowfish-cbc', $remip] : [];
724 syslog('info', "starting vnc proxy
$upid\n");
726 my $qmcmd = [@$remcmd, "/usr/sbin
/qm
", 'vncproxy', $vmid];
728 my $qmstr = join(' ', @$qmcmd);
730 # also redirect stderr (else we get RFB protocol errors)
731 my $cmd = ['/bin/nc', '-l', '-p', $port, '-w', $timeout, '-c', "$qmstr 2>/dev/null
"];
733 PVE::Tools::run_command($cmd);
738 my $upid = $rpcenv->fork_worker('vncproxy', $vmid, $user, $realcmd);
749 __PACKAGE__->register_method({
751 path => '{vmid}/status',
754 description => "Directory
index",
756 additionalProperties => 0,
758 node => get_standard_option('pve-node'),
759 vmid => get_standard_option('pve-vmid'),
767 subdir => { type => 'string' },
770 links => [ { rel => 'child', href => "{subdir
}" } ],
776 my $conf = PVE::QemuServer::load_config($param->{vmid});
779 { subdir => 'current' },
780 { subdir => 'start' },
781 { subdir => 'stop' },
787 __PACKAGE__->register_method({
789 path => '{vmid}/status/current',
792 protected => 1, # qemu pid files are only readable by root
793 description => "Get virtual machine status
.",
795 additionalProperties => 0,
797 node => get_standard_option('pve-node'),
798 vmid => get_standard_option('pve-vmid'),
801 returns => { type => 'object' },
806 my $conf = PVE::QemuServer::load_config($param->{vmid});
808 my $vmstatus = PVE::QemuServer::vmstatus($param->{vmid});
810 return $vmstatus->{$param->{vmid}};
813 __PACKAGE__->register_method({
815 path => '{vmid}/status/start',
819 description => "Start virtual machine
.",
821 additionalProperties => 0,
823 node => get_standard_option('pve-node'),
824 vmid => get_standard_option('pve-vmid'),
825 skiplock => get_standard_option('skiplock'),
826 stateuri => get_standard_option('pve-qm-stateuri'),
835 my $rpcenv = PVE::RPCEnvironment::get();
837 my $user = $rpcenv->get_user();
839 my $node = extract_param($param, 'node');
841 my $vmid = extract_param($param, 'vmid');
843 my $stateuri = extract_param($param, 'stateuri');
844 raise_param_exc({ stateuri => "Only root may
use this option
." })
845 if $stateuri && $user ne 'root@pam';
847 my $skiplock = extract_param($param, 'skiplock');
848 raise_param_exc({ skiplock => "Only root may
use this option
." })
849 if $skiplock && $user ne 'root@pam';
851 my $storecfg = PVE::Storage::config();
856 syslog('info', "start VM
$vmid: $upid\n");
858 PVE::QemuServer::vm_start($storecfg, $vmid, $stateuri, $skiplock);
863 return $rpcenv->fork_worker('qmstart', $vmid, $user, $realcmd);
866 __PACKAGE__->register_method({
868 path => '{vmid}/status/stop',
872 description => "Stop virtual machine
.",
874 additionalProperties => 0,
876 node => get_standard_option('pve-node'),
877 vmid => get_standard_option('pve-vmid'),
878 skiplock => get_standard_option('skiplock'),
880 description => "Wait maximal timeout seconds
.",
893 my $rpcenv = PVE::RPCEnvironment::get();
895 my $user = $rpcenv->get_user();
897 my $node = extract_param($param, 'node');
899 my $vmid = extract_param($param, 'vmid');
901 my $skiplock = extract_param($param, 'skiplock');
902 raise_param_exc({ skiplock => "Only root may
use this option
." })
903 if $skiplock && $user ne 'root@pam';
908 syslog('info', "stop VM
$vmid: $upid\n");
910 PVE::QemuServer::vm_stop($vmid, $skiplock);
912 my $pid = PVE::QemuServer::check_running ($vmid);
914 if ($pid && $param->{timeout}) {
915 print "waiting
until VM
$vmid stopps
(PID
$pid)\n";
918 while (($count < $param->{timeout}) &&
919 PVE::QemuServer::check_running($vmid)) {
924 die "wait failed
- got timeout
\n" if PVE::QemuServer::check_running($vmid);
930 return $rpcenv->fork_worker('qmstop', $vmid, $user, $realcmd);
933 __PACKAGE__->register_method({
935 path => '{vmid}/status/reset',
939 description => "Reset virtual machine
.",
941 additionalProperties => 0,
943 node => get_standard_option('pve-node'),
944 vmid => get_standard_option('pve-vmid'),
945 skiplock => get_standard_option('skiplock'),
954 my $rpcenv = PVE::RPCEnvironment::get();
956 my $user = $rpcenv->get_user();
958 my $node = extract_param($param, 'node');
960 my $vmid = extract_param($param, 'vmid');
962 my $skiplock = extract_param($param, 'skiplock');
963 raise_param_exc({ skiplock => "Only root may
use this option
." })
964 if $skiplock && $user ne 'root@pam';
969 syslog('info', "reset VM
$vmid: $upid\n");
971 PVE::QemuServer::vm_reset($vmid, $skiplock);
976 return $rpcenv->fork_worker('qmreset', $vmid, $user, $realcmd);
979 __PACKAGE__->register_method({
980 name => 'vm_shutdown',
981 path => '{vmid}/status/shutdown',
985 description => "Shutdown virtual machine
.",
987 additionalProperties => 0,
989 node => get_standard_option('pve-node'),
990 vmid => get_standard_option('pve-vmid'),
991 skiplock => get_standard_option('skiplock'),
993 description => "Wait maximal timeout seconds
.",
1006 my $rpcenv = PVE::RPCEnvironment::get();
1008 my $user = $rpcenv->get_user();
1010 my $node = extract_param($param, 'node');
1012 my $vmid = extract_param($param, 'vmid');
1014 my $skiplock = extract_param($param, 'skiplock');
1015 raise_param_exc({ skiplock => "Only root may
use this option
." })
1016 if $skiplock && $user ne 'root@pam';
1021 syslog('info', "shutdown VM
$vmid: $upid\n");
1023 PVE::QemuServer::vm_shutdown($vmid, $skiplock);
1025 my $pid = PVE::QemuServer::check_running ($vmid);
1027 if ($pid && $param->{timeout}) {
1028 print "waiting
until VM
$vmid stopps
(PID
$pid)\n";
1031 while (($count < $param->{timeout}) &&
1032 PVE::QemuServer::check_running($vmid)) {
1037 die "wait failed
- got timeout
\n" if PVE::QemuServer::check_running($vmid);
1043 return $rpcenv->fork_worker('qmshutdown', $vmid, $user, $realcmd);
1046 __PACKAGE__->register_method({
1047 name => 'vm_suspend',
1048 path => '{vmid}/status/suspend',
1052 description => "Suspend virtual machine
.",
1054 additionalProperties => 0,
1056 node => get_standard_option('pve-node'),
1057 vmid => get_standard_option('pve-vmid'),
1058 skiplock => get_standard_option('skiplock'),
1067 my $rpcenv = PVE::RPCEnvironment::get();
1069 my $user = $rpcenv->get_user();
1071 my $node = extract_param($param, 'node');
1073 my $vmid = extract_param($param, 'vmid');
1075 my $skiplock = extract_param($param, 'skiplock');
1076 raise_param_exc({ skiplock => "Only root may
use this option
." })
1077 if $skiplock && $user ne 'root@pam';
1082 syslog('info', "suspend VM
$vmid: $upid\n");
1084 PVE::QemuServer::vm_suspend($vmid, $skiplock);
1089 return $rpcenv->fork_worker('qmsuspend', $vmid, $user, $realcmd);
1092 __PACKAGE__->register_method({
1093 name => 'vm_resume',
1094 path => '{vmid}/status/resume',
1098 description => "Resume virtual machine
.",
1100 additionalProperties => 0,
1102 node => get_standard_option('pve-node'),
1103 vmid => get_standard_option('pve-vmid'),
1104 skiplock => get_standard_option('skiplock'),
1113 my $rpcenv = PVE::RPCEnvironment::get();
1115 my $user = $rpcenv->get_user();
1117 my $node = extract_param($param, 'node');
1119 my $vmid = extract_param($param, 'vmid');
1121 my $skiplock = extract_param($param, 'skiplock');
1122 raise_param_exc({ skiplock => "Only root may
use this option
." })
1123 if $skiplock && $user ne 'root@pam';
1128 syslog('info', "resume VM
$vmid: $upid\n");
1130 PVE::QemuServer::vm_resume($vmid, $skiplock);
1135 return $rpcenv->fork_worker('qmresume', $vmid, $user, $realcmd);
1138 __PACKAGE__->register_method({
1139 name => 'vm_sendkey',
1140 path => '{vmid}/sendkey',
1144 description => "Send key event to virtual machine
.",
1146 additionalProperties => 0,
1148 node => get_standard_option('pve-node'),
1149 vmid => get_standard_option('pve-vmid'),
1150 skiplock => get_standard_option('skiplock'),
1152 description => "The key
(qemu monitor encoding
).",
1157 returns => { type => 'null'},
1161 my $rpcenv = PVE::RPCEnvironment::get();
1163 my $user = $rpcenv->get_user();
1165 my $node = extract_param($param, 'node');
1167 my $vmid = extract_param($param, 'vmid');
1169 my $skiplock = extract_param($param, 'skiplock');
1170 raise_param_exc({ skiplock => "Only root may
use this option
." })
1171 if $skiplock && $user ne 'root@pam';
1173 PVE::QemuServer::vm_sendkey($vmid, $skiplock, $param->{key});
1178 __PACKAGE__->register_method({
1179 name => 'migrate_vm',
1180 path => '{vmid}/migrate',
1184 description => "Migrate virtual machine
. Creates a new migration task
.",
1186 additionalProperties => 0,
1188 node => get_standard_option('pve-node'),
1189 vmid => get_standard_option('pve-vmid'),
1190 target => get_standard_option('pve-node', { description => "Target node
." }),
1193 description => "Use online
/live migration
.",
1198 description => "Allow to migrate VMs which
use local devices
. Only root may
use this option
.",
1205 description => "the task ID
.",
1210 my $rpcenv = PVE::RPCEnvironment::get();
1212 my $user = $rpcenv->get_user();
1214 my $target = extract_param($param, 'target');
1216 my $localnode = PVE::INotify::nodename();
1217 raise_param_exc({ target => "target
is local node
."}) if $target eq $localnode;
1219 PVE::Cluster::check_cfs_quorum();
1221 PVE::Cluster::check_node_exists($target);
1223 my $targetip = PVE::Cluster::remote_node_ip($target);
1225 my $vmid = extract_param($param, 'vmid');
1227 raise_param_exc({ force => "Only root may
use this option
." }) if $user ne 'root@pam';
1230 PVE::QemuServer::load_config($vmid);
1232 # try to detect errors early
1233 if (PVE::QemuServer::check_running($vmid)) {
1234 die "cant migrate running VM without
--online
\n"
1235 if !$param->{online};
1241 PVE::QemuMigrate::migrate($target, $targetip, $vmid, $param->{online}, $param->{force});
1244 my $upid = $rpcenv->fork_worker('qmigrate', $vmid, $user, $realcmd);
1249 __PACKAGE__->register_method({
1251 path => '{vmid}/monitor',
1255 description => "Execute Qemu monitor commands
.",
1257 additionalProperties => 0,
1259 node => get_standard_option('pve-node'),
1260 vmid => get_standard_option('pve-vmid'),
1263 description => "The monitor command
.",
1267 returns => { type => 'string'},
1271 my $vmid = $param->{vmid};
1273 my $conf = PVE::QemuServer::load_config ($vmid); # check if VM exists
1277 $res = PVE::QemuServer::vm_monitor_command($vmid, $param->{command});
1279 $res = "ERROR
: $@" if $@;