]>
Commit | Line | Data |
---|---|---|
1e3baf05 DM |
1 | package PVE::API2::Qemu; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use PVE::Cluster; | |
7 | use PVE::SafeSyslog; | |
8 | use PVE::Tools qw(extract_param); | |
9 | use PVE::Exception qw(raise raise_param_exc); | |
10 | use PVE::Storage; | |
11 | use PVE::JSONSchema qw(get_standard_option); | |
12 | use PVE::RESTHandler; | |
13 | use PVE::QemuServer; | |
3ea94c60 | 14 | use PVE::QemuMigrate; |
1e3baf05 DM |
15 | use PVE::RPCEnvironment; |
16 | use PVE::AccessControl; | |
17 | use PVE::INotify; | |
18 | ||
19 | use Data::Dumper; # fixme: remove | |
20 | ||
21 | use base qw(PVE::RESTHandler); | |
22 | ||
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."; | |
24 | ||
25 | my $resolve_cdrom_alias = sub { | |
26 | my $param = shift; | |
27 | ||
28 | if (my $value = $param->{cdrom}) { | |
29 | $value .= ",media=cdrom" if $value !~ m/media=/; | |
30 | $param->{ide2} = $value; | |
31 | delete $param->{cdrom}; | |
32 | } | |
33 | }; | |
34 | ||
35 | __PACKAGE__->register_method({ | |
36 | name => 'vmlist', | |
37 | path => '', | |
38 | method => 'GET', | |
39 | description => "Virtual machine index (per node).", | |
40 | proxyto => 'node', | |
41 | protected => 1, # qemu pid files are only readable by root | |
42 | parameters => { | |
43 | additionalProperties => 0, | |
44 | properties => { | |
45 | node => get_standard_option('pve-node'), | |
46 | }, | |
47 | }, | |
48 | returns => { | |
49 | type => 'array', | |
50 | items => { | |
51 | type => "object", | |
52 | properties => {}, | |
53 | }, | |
54 | links => [ { rel => 'child', href => "{vmid}" } ], | |
55 | }, | |
56 | code => sub { | |
57 | my ($param) = @_; | |
58 | ||
59 | my $vmstatus = PVE::QemuServer::vmstatus(); | |
60 | ||
61 | return PVE::RESTHandler::hash_to_array($vmstatus, 'vmid'); | |
62 | ||
63 | }}); | |
64 | ||
65 | __PACKAGE__->register_method({ | |
66 | name => 'create_vm', | |
67 | path => '', | |
68 | method => 'POST', | |
3e16d5fc | 69 | description => "Create or restore a virtual machine.", |
1e3baf05 DM |
70 | protected => 1, |
71 | proxyto => 'node', | |
72 | parameters => { | |
73 | additionalProperties => 0, | |
74 | properties => PVE::QemuServer::json_config_properties( | |
75 | { | |
76 | node => get_standard_option('pve-node'), | |
77 | vmid => get_standard_option('pve-vmid'), | |
3e16d5fc DM |
78 | archive => { |
79 | description => "The backup file.", | |
80 | type => 'string', | |
81 | optional => 1, | |
82 | maxLength => 255, | |
83 | }, | |
84 | storage => get_standard_option('pve-storage-id', { | |
85 | description => "Default storage.", | |
86 | optional => 1, | |
87 | }), | |
88 | force => { | |
89 | optional => 1, | |
90 | type => 'boolean', | |
91 | description => "Allow to overwrite existing VM.", | |
92 | }, | |
1e3baf05 DM |
93 | }), |
94 | }, | |
5fdbe4f0 DM |
95 | returns => { |
96 | type => 'string', | |
97 | }, | |
1e3baf05 DM |
98 | code => sub { |
99 | my ($param) = @_; | |
100 | ||
5fdbe4f0 DM |
101 | my $rpcenv = PVE::RPCEnvironment::get(); |
102 | ||
103 | my $user = $rpcenv->get_user(); | |
104 | ||
1e3baf05 DM |
105 | my $node = extract_param($param, 'node'); |
106 | ||
1e3baf05 DM |
107 | my $vmid = extract_param($param, 'vmid'); |
108 | ||
3e16d5fc DM |
109 | my $archive = extract_param($param, 'archive'); |
110 | ||
111 | my $storage = extract_param($param, 'storage'); | |
112 | ||
1e3baf05 | 113 | my $filename = PVE::QemuServer::config_file($vmid); |
1e3baf05 DM |
114 | |
115 | my $storecfg = PVE::Storage::config(); | |
116 | ||
3e16d5fc | 117 | PVE::Cluster::check_cfs_quorum(); |
1e3baf05 | 118 | |
3e16d5fc DM |
119 | if (!$archive) { |
120 | &$resolve_cdrom_alias($param); | |
1e3baf05 | 121 | |
3e16d5fc DM |
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; | |
126 | ||
127 | PVE::QemuServer::cleanup_drive_path($opt, $storecfg, $drive); | |
128 | $param->{$opt} = PVE::QemuServer::print_drive($vmid, $drive); | |
129 | } | |
1e3baf05 | 130 | } |
3e16d5fc DM |
131 | |
132 | PVE::QemuServer::add_random_macs($param); | |
1e3baf05 DM |
133 | } |
134 | ||
3e16d5fc DM |
135 | # fixme: archive eq '-' (read from stdin) |
136 | ||
137 | my $restorefn = sub { | |
138 | ||
139 | if (-f $filename) { | |
140 | die "unable to restore vm $vmid: config file already exists\n" | |
141 | if !$param->{force}; | |
142 | ||
143 | die "unable to restore vm $vmid: vm is running\n" | |
144 | if PVE::QemuServer::check_running($vmid); | |
a6af7b3e DM |
145 | |
146 | # destroy existing data - keep empty config | |
147 | PVE::QemuServer::destroy_vm($storecfg, $vmid, 1); | |
3e16d5fc DM |
148 | } |
149 | ||
150 | my $realcmd = sub { | |
151 | PVE::QemuServer::restore_archive($archive, $vmid, { storage => $storage}); | |
152 | }; | |
153 | ||
154 | return $rpcenv->fork_worker('qmrestore', $vmid, $user, $realcmd); | |
155 | }; | |
1e3baf05 | 156 | |
1e3baf05 DM |
157 | my $createfn = sub { |
158 | ||
159 | # second test (after locking test is accurate) | |
160 | die "unable to create vm $vmid: config file already exists\n" | |
161 | if -f $filename; | |
162 | ||
5fdbe4f0 | 163 | my $realcmd = sub { |
1e3baf05 | 164 | |
5fdbe4f0 | 165 | my $vollist = []; |
1e3baf05 | 166 | |
5fdbe4f0 | 167 | eval { |
3e16d5fc | 168 | $vollist = PVE::QemuServer::create_disks($storecfg, $vmid, $param, $storage); |
1e3baf05 | 169 | |
5fdbe4f0 DM |
170 | # try to be smart about bootdisk |
171 | my @disks = PVE::QemuServer::disknames(); | |
172 | my $firstdisk; | |
173 | foreach my $ds (reverse @disks) { | |
174 | next if !$param->{$ds}; | |
175 | my $disk = PVE::QemuServer::parse_drive($ds, $param->{$ds}); | |
176 | next if PVE::QemuServer::drive_is_cdrom($disk); | |
177 | $firstdisk = $ds; | |
178 | } | |
1e3baf05 | 179 | |
5fdbe4f0 DM |
180 | if (!$param->{bootdisk} && $firstdisk) { |
181 | $param->{bootdisk} = $firstdisk; | |
182 | } | |
1e3baf05 | 183 | |
5fdbe4f0 DM |
184 | PVE::QemuServer::create_conf_nolock($vmid, $param); |
185 | }; | |
186 | my $err = $@; | |
1e3baf05 | 187 | |
5fdbe4f0 DM |
188 | if ($err) { |
189 | foreach my $volid (@$vollist) { | |
190 | eval { PVE::Storage::vdisk_free($storecfg, $volid); }; | |
191 | warn $@ if $@; | |
192 | } | |
193 | die "create failed - $err"; | |
194 | } | |
195 | }; | |
196 | ||
197 | return $rpcenv->fork_worker('qmcreate', $vmid, $user, $realcmd); | |
198 | }; | |
199 | ||
3e16d5fc | 200 | return PVE::QemuServer::lock_config($vmid, $archive ? $restorefn : $createfn); |
1e3baf05 DM |
201 | }}); |
202 | ||
203 | __PACKAGE__->register_method({ | |
204 | name => 'vmdiridx', | |
205 | path => '{vmid}', | |
206 | method => 'GET', | |
207 | proxyto => 'node', | |
208 | description => "Directory index", | |
209 | parameters => { | |
210 | additionalProperties => 0, | |
211 | properties => { | |
212 | node => get_standard_option('pve-node'), | |
213 | vmid => get_standard_option('pve-vmid'), | |
214 | }, | |
215 | }, | |
216 | returns => { | |
217 | type => 'array', | |
218 | items => { | |
219 | type => "object", | |
220 | properties => { | |
221 | subdir => { type => 'string' }, | |
222 | }, | |
223 | }, | |
224 | links => [ { rel => 'child', href => "{subdir}" } ], | |
225 | }, | |
226 | code => sub { | |
227 | my ($param) = @_; | |
228 | ||
229 | my $res = [ | |
230 | { subdir => 'config' }, | |
231 | { subdir => 'status' }, | |
232 | { subdir => 'unlink' }, | |
233 | { subdir => 'vncproxy' }, | |
3ea94c60 | 234 | { subdir => 'migrate' }, |
1e3baf05 DM |
235 | { subdir => 'rrd' }, |
236 | { subdir => 'rrddata' }, | |
237 | ]; | |
238 | ||
239 | return $res; | |
240 | }}); | |
241 | ||
242 | __PACKAGE__->register_method({ | |
243 | name => 'rrd', | |
244 | path => '{vmid}/rrd', | |
245 | method => 'GET', | |
246 | protected => 1, # fixme: can we avoid that? | |
247 | permissions => { | |
248 | path => '/vms/{vmid}', | |
249 | privs => [ 'VM.Audit' ], | |
250 | }, | |
251 | description => "Read VM RRD statistics (returns PNG)", | |
252 | parameters => { | |
253 | additionalProperties => 0, | |
254 | properties => { | |
255 | node => get_standard_option('pve-node'), | |
256 | vmid => get_standard_option('pve-vmid'), | |
257 | timeframe => { | |
258 | description => "Specify the time frame you are interested in.", | |
259 | type => 'string', | |
260 | enum => [ 'hour', 'day', 'week', 'month', 'year' ], | |
261 | }, | |
262 | ds => { | |
263 | description => "The list of datasources you want to display.", | |
264 | type => 'string', format => 'pve-configid-list', | |
265 | }, | |
266 | cf => { | |
267 | description => "The RRD consolidation function", | |
268 | type => 'string', | |
269 | enum => [ 'AVERAGE', 'MAX' ], | |
270 | optional => 1, | |
271 | }, | |
272 | }, | |
273 | }, | |
274 | returns => { | |
275 | type => "object", | |
276 | properties => { | |
277 | filename => { type => 'string' }, | |
278 | }, | |
279 | }, | |
280 | code => sub { | |
281 | my ($param) = @_; | |
282 | ||
283 | return PVE::Cluster::create_rrd_graph( | |
284 | "pve2-vm/$param->{vmid}", $param->{timeframe}, | |
285 | $param->{ds}, $param->{cf}); | |
286 | ||
287 | }}); | |
288 | ||
289 | __PACKAGE__->register_method({ | |
290 | name => 'rrddata', | |
291 | path => '{vmid}/rrddata', | |
292 | method => 'GET', | |
293 | protected => 1, # fixme: can we avoid that? | |
294 | permissions => { | |
295 | path => '/vms/{vmid}', | |
296 | privs => [ 'VM.Audit' ], | |
297 | }, | |
298 | description => "Read VM RRD statistics", | |
299 | parameters => { | |
300 | additionalProperties => 0, | |
301 | properties => { | |
302 | node => get_standard_option('pve-node'), | |
303 | vmid => get_standard_option('pve-vmid'), | |
304 | timeframe => { | |
305 | description => "Specify the time frame you are interested in.", | |
306 | type => 'string', | |
307 | enum => [ 'hour', 'day', 'week', 'month', 'year' ], | |
308 | }, | |
309 | cf => { | |
310 | description => "The RRD consolidation function", | |
311 | type => 'string', | |
312 | enum => [ 'AVERAGE', 'MAX' ], | |
313 | optional => 1, | |
314 | }, | |
315 | }, | |
316 | }, | |
317 | returns => { | |
318 | type => "array", | |
319 | items => { | |
320 | type => "object", | |
321 | properties => {}, | |
322 | }, | |
323 | }, | |
324 | code => sub { | |
325 | my ($param) = @_; | |
326 | ||
327 | return PVE::Cluster::create_rrd_data( | |
328 | "pve2-vm/$param->{vmid}", $param->{timeframe}, $param->{cf}); | |
329 | }}); | |
330 | ||
331 | ||
332 | __PACKAGE__->register_method({ | |
333 | name => 'vm_config', | |
334 | path => '{vmid}/config', | |
335 | method => 'GET', | |
336 | proxyto => 'node', | |
337 | description => "Get virtual machine configuration.", | |
338 | parameters => { | |
339 | additionalProperties => 0, | |
340 | properties => { | |
341 | node => get_standard_option('pve-node'), | |
342 | vmid => get_standard_option('pve-vmid'), | |
343 | }, | |
344 | }, | |
345 | returns => { | |
346 | type => "object", | |
554ac7e7 DM |
347 | properties => { |
348 | digest => { | |
349 | type => 'string', | |
350 | description => 'SHA1 digest of configuration file. This can be used to prevent concurrent modifications.', | |
351 | } | |
352 | }, | |
1e3baf05 DM |
353 | }, |
354 | code => sub { | |
355 | my ($param) = @_; | |
356 | ||
357 | my $conf = PVE::QemuServer::load_config($param->{vmid}); | |
358 | ||
359 | return $conf; | |
360 | }}); | |
361 | ||
362 | __PACKAGE__->register_method({ | |
363 | name => 'update_vm', | |
364 | path => '{vmid}/config', | |
365 | method => 'PUT', | |
366 | protected => 1, | |
367 | proxyto => 'node', | |
368 | description => "Set virtual machine options.", | |
369 | parameters => { | |
370 | additionalProperties => 0, | |
371 | properties => PVE::QemuServer::json_config_properties( | |
372 | { | |
373 | node => get_standard_option('pve-node'), | |
374 | vmid => get_standard_option('pve-vmid'), | |
3ea94c60 | 375 | skiplock => get_standard_option('skiplock'), |
1e3baf05 DM |
376 | delete => { |
377 | type => 'string', format => 'pve-configid-list', | |
378 | description => "A list of settings you want to delete.", | |
379 | optional => 1, | |
380 | }, | |
381 | force => { | |
382 | type => 'boolean', | |
383 | description => $opt_force_description, | |
384 | optional => 1, | |
385 | requires => 'delete', | |
386 | }, | |
554ac7e7 DM |
387 | digest => { |
388 | type => 'string', | |
389 | description => 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.', | |
390 | maxLength => 40, | |
391 | optional => 1, | |
392 | } | |
1e3baf05 DM |
393 | }), |
394 | }, | |
395 | returns => { type => 'null'}, | |
396 | code => sub { | |
397 | my ($param) = @_; | |
398 | ||
399 | my $rpcenv = PVE::RPCEnvironment::get(); | |
400 | ||
401 | my $user = $rpcenv->get_user(); | |
402 | ||
403 | my $node = extract_param($param, 'node'); | |
404 | ||
1e3baf05 DM |
405 | my $vmid = extract_param($param, 'vmid'); |
406 | ||
5fdbe4f0 DM |
407 | my $digest = extract_param($param, 'digest'); |
408 | ||
409 | my @paramarr = (); # used for log message | |
410 | foreach my $key (keys %$param) { | |
411 | push @paramarr, "-$key", $param->{$key}; | |
412 | } | |
413 | ||
1e3baf05 | 414 | my $skiplock = extract_param($param, 'skiplock'); |
3ea94c60 DM |
415 | raise_param_exc({ skiplock => "Only root may use this option." }) |
416 | if $skiplock && $user ne 'root@pam'; | |
1e3baf05 DM |
417 | |
418 | my $delete = extract_param($param, 'delete'); | |
419 | my $force = extract_param($param, 'force'); | |
420 | ||
421 | die "no options specified\n" if !$delete && !scalar(keys %$param); | |
422 | ||
423 | my $storecfg = PVE::Storage::config(); | |
424 | ||
425 | &$resolve_cdrom_alias($param); | |
426 | ||
427 | my $eject = {}; | |
428 | my $cdchange = {}; | |
429 | ||
430 | foreach my $opt (keys %$param) { | |
431 | if (PVE::QemuServer::valid_drivename($opt)) { | |
432 | my $drive = PVE::QemuServer::parse_drive($opt, $param->{$opt}); | |
433 | raise_param_exc({ $opt => "unable to parse drive options" }) if !$drive; | |
434 | if ($drive->{file} eq 'eject') { | |
435 | $eject->{$opt} = 1; | |
436 | delete $param->{$opt}; | |
437 | next; | |
438 | } | |
439 | ||
440 | PVE::QemuServer::cleanup_drive_path($opt, $storecfg, $drive); | |
441 | $param->{$opt} = PVE::QemuServer::print_drive($vmid, $drive); | |
442 | ||
443 | if (PVE::QemuServer::drive_is_cdrom($drive)) { | |
444 | $cdchange->{$opt} = PVE::QemuServer::get_iso_path($storecfg, $vmid, $drive->{file}); | |
445 | } | |
446 | } | |
447 | } | |
448 | ||
449 | foreach my $opt (PVE::Tools::split_list($delete)) { | |
450 | $opt = 'ide2' if $opt eq 'cdrom'; | |
451 | die "you can't use '-$opt' and '-delete $opt' at the same time\n" | |
452 | if defined($param->{$opt}); | |
453 | } | |
454 | ||
455 | PVE::QemuServer::add_random_macs($param); | |
456 | ||
457 | my $vollist = []; | |
458 | ||
459 | my $updatefn = sub { | |
460 | ||
461 | my $conf = PVE::QemuServer::load_config($vmid); | |
462 | ||
554ac7e7 DM |
463 | die "checksum missmatch (file change by other user?)\n" |
464 | if $digest && $digest ne $conf->{digest}; | |
465 | ||
1e3baf05 DM |
466 | PVE::QemuServer::check_lock($conf) if !$skiplock; |
467 | ||
5fdbe4f0 DM |
468 | PVE::Cluster::log_msg('info', $user, "update VM $vmid: " . join (' ', @paramarr)); |
469 | ||
1e3baf05 DM |
470 | foreach my $opt (keys %$eject) { |
471 | if ($conf->{$opt}) { | |
472 | my $drive = PVE::QemuServer::parse_drive($opt, $conf->{$opt}); | |
473 | $cdchange->{$opt} = undef if PVE::QemuServer::drive_is_cdrom($drive); | |
474 | } else { | |
475 | raise_param_exc({ $opt => "eject failed - drive does not exist." }); | |
476 | } | |
477 | } | |
478 | ||
479 | foreach my $opt (keys %$param) { | |
480 | next if !PVE::QemuServer::valid_drivename($opt); | |
481 | next if !$conf->{$opt}; | |
482 | my $old_drive = PVE::QemuServer::parse_drive($opt, $conf->{$opt}); | |
483 | next if PVE::QemuServer::drive_is_cdrom($old_drive); | |
484 | my $new_drive = PVE::QemuServer::parse_drive($opt, $param->{$opt}); | |
485 | if ($new_drive->{file} ne $old_drive->{file}) { | |
486 | my ($path, $owner); | |
487 | eval { ($path, $owner) = PVE::Storage::path($storecfg, $old_drive->{file}); }; | |
488 | if ($owner && ($owner == $vmid)) { | |
489 | PVE::QemuServer::add_unused_volume($conf, $param, $old_drive->{file}); | |
490 | } | |
491 | } | |
492 | } | |
493 | ||
494 | my $unset = {}; | |
495 | ||
496 | foreach my $opt (PVE::Tools::split_list($delete)) { | |
497 | $opt = 'ide2' if $opt eq 'cdrom'; | |
498 | if (!PVE::QemuServer::option_exists($opt)) { | |
499 | raise_param_exc({ delete => "unknown option '$opt'" }); | |
500 | } | |
501 | next if !defined($conf->{$opt}); | |
502 | if (PVE::QemuServer::valid_drivename($opt)) { | |
f19d1c47 | 503 | PVE::QemuServer::vm_devicedel($vmid, $conf, $opt); |
1e3baf05 DM |
504 | my $drive = PVE::QemuServer::parse_drive($opt, $conf->{$opt}); |
505 | if (PVE::QemuServer::drive_is_cdrom($drive)) { | |
506 | $cdchange->{$opt} = undef; | |
507 | } else { | |
508 | my $volid = $drive->{file}; | |
509 | ||
510 | if ($volid !~ m|^/|) { | |
511 | my ($path, $owner); | |
512 | eval { ($path, $owner) = PVE::Storage::path($storecfg, $volid); }; | |
513 | if ($owner && ($owner == $vmid)) { | |
514 | if ($force) { | |
515 | push @$vollist, $volid; | |
516 | } else { | |
517 | PVE::QemuServer::add_unused_volume($conf, $param, $volid); | |
518 | } | |
519 | } | |
520 | } | |
521 | } | |
522 | } elsif ($opt =~ m/^unused/) { | |
523 | push @$vollist, $conf->{$opt}; | |
524 | } | |
525 | ||
526 | $unset->{$opt} = 1; | |
527 | } | |
528 | ||
f19d1c47 | 529 | PVE::QemuServer::create_disks($storecfg, $vmid, $param, $conf); |
1e3baf05 DM |
530 | |
531 | PVE::QemuServer::change_config_nolock($vmid, $param, $unset, 1); | |
532 | ||
533 | return if !PVE::QemuServer::check_running($vmid); | |
534 | ||
535 | foreach my $opt (keys %$cdchange) { | |
536 | my $qdn = PVE::QemuServer::qemu_drive_name($opt, 'cdrom'); | |
537 | my $path = $cdchange->{$opt}; | |
538 | PVE::QemuServer::vm_monitor_command($vmid, "eject $qdn", 0); | |
539 | PVE::QemuServer::vm_monitor_command($vmid, "change $qdn \"$path\"", 0) if $path; | |
540 | } | |
541 | }; | |
542 | ||
543 | PVE::QemuServer::lock_config($vmid, $updatefn); | |
544 | ||
545 | foreach my $volid (@$vollist) { | |
546 | eval { PVE::Storage::vdisk_free($storecfg, $volid); }; | |
547 | # fixme: log ? | |
548 | warn $@ if $@; | |
549 | } | |
550 | ||
551 | return undef; | |
552 | }}); | |
553 | ||
554 | ||
555 | __PACKAGE__->register_method({ | |
556 | name => 'destroy_vm', | |
557 | path => '{vmid}', | |
558 | method => 'DELETE', | |
559 | protected => 1, | |
560 | proxyto => 'node', | |
561 | description => "Destroy the vm (also delete all used/owned volumes).", | |
562 | parameters => { | |
563 | additionalProperties => 0, | |
564 | properties => { | |
565 | node => get_standard_option('pve-node'), | |
566 | vmid => get_standard_option('pve-vmid'), | |
3ea94c60 | 567 | skiplock => get_standard_option('skiplock'), |
1e3baf05 DM |
568 | }, |
569 | }, | |
5fdbe4f0 DM |
570 | returns => { |
571 | type => 'string', | |
572 | }, | |
1e3baf05 DM |
573 | code => sub { |
574 | my ($param) = @_; | |
575 | ||
576 | my $rpcenv = PVE::RPCEnvironment::get(); | |
577 | ||
578 | my $user = $rpcenv->get_user(); | |
579 | ||
580 | my $vmid = $param->{vmid}; | |
581 | ||
582 | my $skiplock = $param->{skiplock}; | |
583 | raise_param_exc({ skiplock => "Only root may use this option." }) | |
3ea94c60 | 584 | if $skiplock && $user ne 'root@pam'; |
1e3baf05 | 585 | |
5fdbe4f0 DM |
586 | # test if VM exists |
587 | my $conf = PVE::QemuServer::load_config($vmid); | |
588 | ||
1e3baf05 DM |
589 | my $storecfg = PVE::Storage::config(); |
590 | ||
5fdbe4f0 DM |
591 | my $realcmd = sub { |
592 | PVE::QemuServer::vm_destroy($storecfg, $vmid, $skiplock); | |
593 | }; | |
1e3baf05 | 594 | |
5fdbe4f0 | 595 | return $rpcenv->fork_worker('qmdestroy', $vmid, $user, $realcmd); |
1e3baf05 DM |
596 | }}); |
597 | ||
598 | __PACKAGE__->register_method({ | |
599 | name => 'unlink', | |
600 | path => '{vmid}/unlink', | |
601 | method => 'PUT', | |
602 | protected => 1, | |
603 | proxyto => 'node', | |
604 | description => "Unlink/delete disk images.", | |
605 | parameters => { | |
606 | additionalProperties => 0, | |
607 | properties => { | |
608 | node => get_standard_option('pve-node'), | |
609 | vmid => get_standard_option('pve-vmid'), | |
610 | idlist => { | |
611 | type => 'string', format => 'pve-configid-list', | |
612 | description => "A list of disk IDs you want to delete.", | |
613 | }, | |
614 | force => { | |
615 | type => 'boolean', | |
616 | description => $opt_force_description, | |
617 | optional => 1, | |
618 | }, | |
619 | }, | |
620 | }, | |
621 | returns => { type => 'null'}, | |
622 | code => sub { | |
623 | my ($param) = @_; | |
624 | ||
625 | $param->{delete} = extract_param($param, 'idlist'); | |
626 | ||
627 | __PACKAGE__->update_vm($param); | |
628 | ||
629 | return undef; | |
630 | }}); | |
631 | ||
632 | my $sslcert; | |
633 | ||
634 | __PACKAGE__->register_method({ | |
635 | name => 'vncproxy', | |
636 | path => '{vmid}/vncproxy', | |
637 | method => 'POST', | |
638 | protected => 1, | |
639 | permissions => { | |
640 | path => '/vms/{vmid}', | |
641 | privs => [ 'VM.Console' ], | |
642 | }, | |
643 | description => "Creates a TCP VNC proxy connections.", | |
644 | parameters => { | |
645 | additionalProperties => 0, | |
646 | properties => { | |
647 | node => get_standard_option('pve-node'), | |
648 | vmid => get_standard_option('pve-vmid'), | |
649 | }, | |
650 | }, | |
651 | returns => { | |
652 | additionalProperties => 0, | |
653 | properties => { | |
654 | user => { type => 'string' }, | |
655 | ticket => { type => 'string' }, | |
656 | cert => { type => 'string' }, | |
657 | port => { type => 'integer' }, | |
658 | upid => { type => 'string' }, | |
659 | }, | |
660 | }, | |
661 | code => sub { | |
662 | my ($param) = @_; | |
663 | ||
664 | my $rpcenv = PVE::RPCEnvironment::get(); | |
665 | ||
666 | my $user = $rpcenv->get_user(); | |
667 | my $ticket = PVE::AccessControl::assemble_ticket($user); | |
668 | ||
669 | my $vmid = $param->{vmid}; | |
670 | my $node = $param->{node}; | |
671 | ||
672 | $sslcert = PVE::Tools::file_get_contents("/etc/pve/pve-root-ca.pem", 8192) | |
673 | if !$sslcert; | |
674 | ||
675 | my $port = PVE::Tools::next_vnc_port(); | |
676 | ||
677 | my $remip; | |
678 | ||
679 | if ($node ne PVE::INotify::nodename()) { | |
680 | $remip = PVE::Cluster::remote_node_ip($node); | |
681 | } | |
682 | ||
683 | # NOTE: kvm VNC traffic is already TLS encrypted, | |
684 | # so we select the fastest chipher here (or 'none'?) | |
685 | my $remcmd = $remip ? ['/usr/bin/ssh', '-T', '-o', 'BatchMode=yes', | |
686 | '-c', 'blowfish-cbc', $remip] : []; | |
687 | ||
688 | my $timeout = 10; | |
689 | ||
690 | my $realcmd = sub { | |
691 | my $upid = shift; | |
692 | ||
693 | syslog('info', "starting vnc proxy $upid\n"); | |
694 | ||
695 | my $qmcmd = [@$remcmd, "/usr/sbin/qm", 'vncproxy', $vmid]; | |
696 | ||
697 | my $qmstr = join(' ', @$qmcmd); | |
698 | ||
699 | # also redirect stderr (else we get RFB protocol errors) | |
be62c45c | 700 | my $cmd = ['/bin/nc', '-l', '-p', $port, '-w', $timeout, '-c', "$qmstr 2>/dev/null"]; |
1e3baf05 | 701 | |
be62c45c | 702 | PVE::Tools::run_command($cmd); |
1e3baf05 DM |
703 | |
704 | return; | |
705 | }; | |
706 | ||
707 | my $upid = $rpcenv->fork_worker('vncproxy', $vmid, $user, $realcmd); | |
708 | ||
709 | return { | |
710 | user => $user, | |
711 | ticket => $ticket, | |
712 | port => $port, | |
713 | upid => $upid, | |
714 | cert => $sslcert, | |
715 | }; | |
716 | }}); | |
717 | ||
5fdbe4f0 DM |
718 | __PACKAGE__->register_method({ |
719 | name => 'vmcmdidx', | |
720 | path => '{vmid}/status', | |
721 | method => 'GET', | |
722 | proxyto => 'node', | |
723 | description => "Directory index", | |
724 | parameters => { | |
725 | additionalProperties => 0, | |
726 | properties => { | |
727 | node => get_standard_option('pve-node'), | |
728 | vmid => get_standard_option('pve-vmid'), | |
729 | }, | |
730 | }, | |
731 | returns => { | |
732 | type => 'array', | |
733 | items => { | |
734 | type => "object", | |
735 | properties => { | |
736 | subdir => { type => 'string' }, | |
737 | }, | |
738 | }, | |
739 | links => [ { rel => 'child', href => "{subdir}" } ], | |
740 | }, | |
741 | code => sub { | |
742 | my ($param) = @_; | |
743 | ||
744 | # test if VM exists | |
745 | my $conf = PVE::QemuServer::load_config($param->{vmid}); | |
746 | ||
747 | my $res = [ | |
748 | { subdir => 'current' }, | |
749 | { subdir => 'start' }, | |
750 | { subdir => 'stop' }, | |
751 | ]; | |
752 | ||
753 | return $res; | |
754 | }}); | |
755 | ||
1e3baf05 DM |
756 | __PACKAGE__->register_method({ |
757 | name => 'vm_status', | |
5fdbe4f0 | 758 | path => '{vmid}/status/current', |
1e3baf05 DM |
759 | method => 'GET', |
760 | proxyto => 'node', | |
761 | protected => 1, # qemu pid files are only readable by root | |
762 | description => "Get virtual machine status.", | |
763 | parameters => { | |
764 | additionalProperties => 0, | |
765 | properties => { | |
766 | node => get_standard_option('pve-node'), | |
767 | vmid => get_standard_option('pve-vmid'), | |
768 | }, | |
769 | }, | |
770 | returns => { type => 'object' }, | |
771 | code => sub { | |
772 | my ($param) = @_; | |
773 | ||
774 | # test if VM exists | |
775 | my $conf = PVE::QemuServer::load_config($param->{vmid}); | |
776 | ||
777 | my $vmstatus = PVE::QemuServer::vmstatus($param->{vmid}); | |
778 | ||
779 | return $vmstatus->{$param->{vmid}}; | |
780 | }}); | |
781 | ||
782 | __PACKAGE__->register_method({ | |
5fdbe4f0 DM |
783 | name => 'vm_start', |
784 | path => '{vmid}/status/start', | |
785 | method => 'POST', | |
1e3baf05 DM |
786 | protected => 1, |
787 | proxyto => 'node', | |
5fdbe4f0 | 788 | description => "Start virtual machine.", |
1e3baf05 DM |
789 | parameters => { |
790 | additionalProperties => 0, | |
791 | properties => { | |
792 | node => get_standard_option('pve-node'), | |
793 | vmid => get_standard_option('pve-vmid'), | |
3ea94c60 DM |
794 | skiplock => get_standard_option('skiplock'), |
795 | stateuri => get_standard_option('pve-qm-stateuri'), | |
1e3baf05 DM |
796 | }, |
797 | }, | |
5fdbe4f0 DM |
798 | returns => { |
799 | type => 'string', | |
800 | }, | |
1e3baf05 DM |
801 | code => sub { |
802 | my ($param) = @_; | |
803 | ||
804 | my $rpcenv = PVE::RPCEnvironment::get(); | |
805 | ||
806 | my $user = $rpcenv->get_user(); | |
807 | ||
808 | my $node = extract_param($param, 'node'); | |
809 | ||
1e3baf05 DM |
810 | my $vmid = extract_param($param, 'vmid'); |
811 | ||
3ea94c60 DM |
812 | my $stateuri = extract_param($param, 'stateuri'); |
813 | raise_param_exc({ stateuri => "Only root may use this option." }) | |
814 | if $stateuri && $user ne 'root@pam'; | |
815 | ||
1e3baf05 DM |
816 | my $skiplock = extract_param($param, 'skiplock'); |
817 | raise_param_exc({ skiplock => "Only root may use this option." }) | |
3ea94c60 | 818 | if $skiplock && $user ne 'root@pam'; |
1e3baf05 | 819 | |
1e3baf05 | 820 | my $storecfg = PVE::Storage::config(); |
5fdbe4f0 DM |
821 | |
822 | my $realcmd = sub { | |
823 | my $upid = shift; | |
824 | ||
825 | syslog('info', "start VM $vmid: $upid\n"); | |
826 | ||
3ea94c60 | 827 | PVE::QemuServer::vm_start($storecfg, $vmid, $stateuri, $skiplock); |
5fdbe4f0 DM |
828 | |
829 | return; | |
830 | }; | |
831 | ||
832 | return $rpcenv->fork_worker('qmstart', $vmid, $user, $realcmd); | |
833 | }}); | |
834 | ||
835 | __PACKAGE__->register_method({ | |
836 | name => 'vm_stop', | |
837 | path => '{vmid}/status/stop', | |
838 | method => 'POST', | |
839 | protected => 1, | |
840 | proxyto => 'node', | |
841 | description => "Stop virtual machine.", | |
842 | parameters => { | |
843 | additionalProperties => 0, | |
844 | properties => { | |
845 | node => get_standard_option('pve-node'), | |
846 | vmid => get_standard_option('pve-vmid'), | |
847 | skiplock => get_standard_option('skiplock'), | |
c6bb9502 DM |
848 | timeout => { |
849 | description => "Wait maximal timeout seconds.", | |
850 | type => 'integer', | |
851 | minimum => 0, | |
852 | optional => 1, | |
853 | } | |
5fdbe4f0 DM |
854 | }, |
855 | }, | |
856 | returns => { | |
857 | type => 'string', | |
858 | }, | |
859 | code => sub { | |
860 | my ($param) = @_; | |
861 | ||
862 | my $rpcenv = PVE::RPCEnvironment::get(); | |
863 | ||
864 | my $user = $rpcenv->get_user(); | |
865 | ||
866 | my $node = extract_param($param, 'node'); | |
867 | ||
868 | my $vmid = extract_param($param, 'vmid'); | |
869 | ||
870 | my $skiplock = extract_param($param, 'skiplock'); | |
871 | raise_param_exc({ skiplock => "Only root may use this option." }) | |
872 | if $skiplock && $user ne 'root@pam'; | |
873 | ||
874 | my $realcmd = sub { | |
875 | my $upid = shift; | |
876 | ||
877 | syslog('info', "stop VM $vmid: $upid\n"); | |
878 | ||
1e3baf05 | 879 | PVE::QemuServer::vm_stop($vmid, $skiplock); |
5fdbe4f0 | 880 | |
c6bb9502 DM |
881 | my $pid = PVE::QemuServer::check_running ($vmid); |
882 | ||
883 | if ($pid && $param->{timeout}) { | |
884 | print "waiting until VM $vmid stopps (PID $pid)\n"; | |
885 | ||
886 | my $count = 0; | |
887 | while (($count < $param->{timeout}) && | |
888 | PVE::QemuServer::check_running($vmid)) { | |
889 | $count++; | |
890 | sleep 1; | |
891 | } | |
892 | ||
893 | die "wait failed - got timeout\n" if PVE::QemuServer::check_running($vmid); | |
894 | } | |
895 | ||
5fdbe4f0 DM |
896 | return; |
897 | }; | |
898 | ||
899 | return $rpcenv->fork_worker('qmstop', $vmid, $user, $realcmd); | |
900 | }}); | |
901 | ||
902 | __PACKAGE__->register_method({ | |
903 | name => 'vm_reset', | |
904 | path => '{vmid}/status/reset', | |
905 | method => 'POST', | |
906 | protected => 1, | |
907 | proxyto => 'node', | |
908 | description => "Reset virtual machine.", | |
909 | parameters => { | |
910 | additionalProperties => 0, | |
911 | properties => { | |
912 | node => get_standard_option('pve-node'), | |
913 | vmid => get_standard_option('pve-vmid'), | |
914 | skiplock => get_standard_option('skiplock'), | |
915 | }, | |
916 | }, | |
917 | returns => { | |
918 | type => 'string', | |
919 | }, | |
920 | code => sub { | |
921 | my ($param) = @_; | |
922 | ||
923 | my $rpcenv = PVE::RPCEnvironment::get(); | |
924 | ||
925 | my $user = $rpcenv->get_user(); | |
926 | ||
927 | my $node = extract_param($param, 'node'); | |
928 | ||
929 | my $vmid = extract_param($param, 'vmid'); | |
930 | ||
931 | my $skiplock = extract_param($param, 'skiplock'); | |
932 | raise_param_exc({ skiplock => "Only root may use this option." }) | |
933 | if $skiplock && $user ne 'root@pam'; | |
934 | ||
935 | my $realcmd = sub { | |
936 | my $upid = shift; | |
937 | ||
938 | syslog('info', "reset VM $vmid: $upid\n"); | |
939 | ||
1e3baf05 | 940 | PVE::QemuServer::vm_reset($vmid, $skiplock); |
5fdbe4f0 DM |
941 | |
942 | return; | |
943 | }; | |
944 | ||
945 | return $rpcenv->fork_worker('qmreset', $vmid, $user, $realcmd); | |
946 | }}); | |
947 | ||
948 | __PACKAGE__->register_method({ | |
949 | name => 'vm_shutdown', | |
950 | path => '{vmid}/status/shutdown', | |
951 | method => 'POST', | |
952 | protected => 1, | |
953 | proxyto => 'node', | |
954 | description => "Shutdown virtual machine.", | |
955 | parameters => { | |
956 | additionalProperties => 0, | |
957 | properties => { | |
958 | node => get_standard_option('pve-node'), | |
959 | vmid => get_standard_option('pve-vmid'), | |
960 | skiplock => get_standard_option('skiplock'), | |
c6bb9502 DM |
961 | timeout => { |
962 | description => "Wait maximal timeout seconds.", | |
963 | type => 'integer', | |
964 | minimum => 0, | |
965 | optional => 1, | |
966 | } | |
5fdbe4f0 DM |
967 | }, |
968 | }, | |
969 | returns => { | |
970 | type => 'string', | |
971 | }, | |
972 | code => sub { | |
973 | my ($param) = @_; | |
974 | ||
975 | my $rpcenv = PVE::RPCEnvironment::get(); | |
976 | ||
977 | my $user = $rpcenv->get_user(); | |
978 | ||
979 | my $node = extract_param($param, 'node'); | |
980 | ||
981 | my $vmid = extract_param($param, 'vmid'); | |
982 | ||
983 | my $skiplock = extract_param($param, 'skiplock'); | |
984 | raise_param_exc({ skiplock => "Only root may use this option." }) | |
985 | if $skiplock && $user ne 'root@pam'; | |
986 | ||
987 | my $realcmd = sub { | |
988 | my $upid = shift; | |
989 | ||
990 | syslog('info', "shutdown VM $vmid: $upid\n"); | |
991 | ||
1e3baf05 | 992 | PVE::QemuServer::vm_shutdown($vmid, $skiplock); |
5fdbe4f0 | 993 | |
c6bb9502 DM |
994 | my $pid = PVE::QemuServer::check_running ($vmid); |
995 | ||
996 | if ($pid && $param->{timeout}) { | |
997 | print "waiting until VM $vmid stopps (PID $pid)\n"; | |
998 | ||
999 | my $count = 0; | |
1000 | while (($count < $param->{timeout}) && | |
1001 | PVE::QemuServer::check_running($vmid)) { | |
1002 | $count++; | |
1003 | sleep 1; | |
1004 | } | |
1005 | ||
1006 | die "wait failed - got timeout\n" if PVE::QemuServer::check_running($vmid); | |
1007 | } | |
1008 | ||
5fdbe4f0 DM |
1009 | return; |
1010 | }; | |
1011 | ||
1012 | return $rpcenv->fork_worker('qmshutdown', $vmid, $user, $realcmd); | |
1013 | }}); | |
1014 | ||
1015 | __PACKAGE__->register_method({ | |
1016 | name => 'vm_suspend', | |
1017 | path => '{vmid}/status/suspend', | |
1018 | method => 'POST', | |
1019 | protected => 1, | |
1020 | proxyto => 'node', | |
1021 | description => "Suspend virtual machine.", | |
1022 | parameters => { | |
1023 | additionalProperties => 0, | |
1024 | properties => { | |
1025 | node => get_standard_option('pve-node'), | |
1026 | vmid => get_standard_option('pve-vmid'), | |
1027 | skiplock => get_standard_option('skiplock'), | |
1028 | }, | |
1029 | }, | |
1030 | returns => { | |
1031 | type => 'string', | |
1032 | }, | |
1033 | code => sub { | |
1034 | my ($param) = @_; | |
1035 | ||
1036 | my $rpcenv = PVE::RPCEnvironment::get(); | |
1037 | ||
1038 | my $user = $rpcenv->get_user(); | |
1039 | ||
1040 | my $node = extract_param($param, 'node'); | |
1041 | ||
1042 | my $vmid = extract_param($param, 'vmid'); | |
1043 | ||
1044 | my $skiplock = extract_param($param, 'skiplock'); | |
1045 | raise_param_exc({ skiplock => "Only root may use this option." }) | |
1046 | if $skiplock && $user ne 'root@pam'; | |
1047 | ||
1048 | my $realcmd = sub { | |
1049 | my $upid = shift; | |
1050 | ||
1051 | syslog('info', "suspend VM $vmid: $upid\n"); | |
1052 | ||
1e3baf05 | 1053 | PVE::QemuServer::vm_suspend($vmid, $skiplock); |
5fdbe4f0 DM |
1054 | |
1055 | return; | |
1056 | }; | |
1057 | ||
1058 | return $rpcenv->fork_worker('qmsuspend', $vmid, $user, $realcmd); | |
1059 | }}); | |
1060 | ||
1061 | __PACKAGE__->register_method({ | |
1062 | name => 'vm_resume', | |
1063 | path => '{vmid}/status/resume', | |
1064 | method => 'POST', | |
1065 | protected => 1, | |
1066 | proxyto => 'node', | |
1067 | description => "Resume virtual machine.", | |
1068 | parameters => { | |
1069 | additionalProperties => 0, | |
1070 | properties => { | |
1071 | node => get_standard_option('pve-node'), | |
1072 | vmid => get_standard_option('pve-vmid'), | |
1073 | skiplock => get_standard_option('skiplock'), | |
1074 | }, | |
1075 | }, | |
1076 | returns => { | |
1077 | type => 'string', | |
1078 | }, | |
1079 | code => sub { | |
1080 | my ($param) = @_; | |
1081 | ||
1082 | my $rpcenv = PVE::RPCEnvironment::get(); | |
1083 | ||
1084 | my $user = $rpcenv->get_user(); | |
1085 | ||
1086 | my $node = extract_param($param, 'node'); | |
1087 | ||
1088 | my $vmid = extract_param($param, 'vmid'); | |
1089 | ||
1090 | my $skiplock = extract_param($param, 'skiplock'); | |
1091 | raise_param_exc({ skiplock => "Only root may use this option." }) | |
1092 | if $skiplock && $user ne 'root@pam'; | |
1093 | ||
1094 | my $realcmd = sub { | |
1095 | my $upid = shift; | |
1096 | ||
1097 | syslog('info', "resume VM $vmid: $upid\n"); | |
1098 | ||
1e3baf05 | 1099 | PVE::QemuServer::vm_resume($vmid, $skiplock); |
1e3baf05 | 1100 | |
5fdbe4f0 DM |
1101 | return; |
1102 | }; | |
1103 | ||
1104 | return $rpcenv->fork_worker('qmresume', $vmid, $user, $realcmd); | |
1105 | }}); | |
1106 | ||
1107 | __PACKAGE__->register_method({ | |
1108 | name => 'vm_sendkey', | |
1109 | path => '{vmid}/sendkey', | |
1110 | method => 'PUT', | |
1111 | protected => 1, | |
1112 | proxyto => 'node', | |
1113 | description => "Send key event to virtual machine.", | |
1114 | parameters => { | |
1115 | additionalProperties => 0, | |
1116 | properties => { | |
1117 | node => get_standard_option('pve-node'), | |
1118 | vmid => get_standard_option('pve-vmid'), | |
1119 | skiplock => get_standard_option('skiplock'), | |
1120 | key => { | |
1121 | description => "The key (qemu monitor encoding).", | |
1122 | type => 'string' | |
1123 | } | |
1124 | }, | |
1125 | }, | |
1126 | returns => { type => 'null'}, | |
1127 | code => sub { | |
1128 | my ($param) = @_; | |
1129 | ||
1130 | my $rpcenv = PVE::RPCEnvironment::get(); | |
1131 | ||
1132 | my $user = $rpcenv->get_user(); | |
1133 | ||
1134 | my $node = extract_param($param, 'node'); | |
1135 | ||
1136 | my $vmid = extract_param($param, 'vmid'); | |
1137 | ||
1138 | my $skiplock = extract_param($param, 'skiplock'); | |
1139 | raise_param_exc({ skiplock => "Only root may use this option." }) | |
1140 | if $skiplock && $user ne 'root@pam'; | |
1141 | ||
1142 | PVE::QemuServer::vm_sendkey($vmid, $skiplock, $param->{key}); | |
1143 | ||
1144 | return; | |
1e3baf05 DM |
1145 | }}); |
1146 | ||
3ea94c60 DM |
1147 | __PACKAGE__->register_method({ |
1148 | name => 'migrate_vm', | |
1149 | path => '{vmid}/migrate', | |
1150 | method => 'POST', | |
1151 | protected => 1, | |
1152 | proxyto => 'node', | |
1153 | description => "Migrate virtual machine. Creates a new migration task.", | |
1154 | parameters => { | |
1155 | additionalProperties => 0, | |
1156 | properties => { | |
1157 | node => get_standard_option('pve-node'), | |
1158 | vmid => get_standard_option('pve-vmid'), | |
1159 | target => get_standard_option('pve-node', { description => "Target node." }), | |
1160 | online => { | |
1161 | type => 'boolean', | |
1162 | description => "Use online/live migration.", | |
1163 | optional => 1, | |
1164 | }, | |
1165 | force => { | |
1166 | type => 'boolean', | |
1167 | description => "Allow to migrate VMs which use local devices. Only root may use this option.", | |
1168 | optional => 1, | |
1169 | }, | |
1170 | }, | |
1171 | }, | |
1172 | returns => { | |
1173 | type => 'string', | |
1174 | description => "the task ID.", | |
1175 | }, | |
1176 | code => sub { | |
1177 | my ($param) = @_; | |
1178 | ||
1179 | my $rpcenv = PVE::RPCEnvironment::get(); | |
1180 | ||
1181 | my $user = $rpcenv->get_user(); | |
1182 | ||
1183 | my $target = extract_param($param, 'target'); | |
1184 | ||
1185 | my $localnode = PVE::INotify::nodename(); | |
1186 | raise_param_exc({ target => "target is local node."}) if $target eq $localnode; | |
1187 | ||
1188 | PVE::Cluster::check_cfs_quorum(); | |
1189 | ||
1190 | PVE::Cluster::check_node_exists($target); | |
1191 | ||
1192 | my $targetip = PVE::Cluster::remote_node_ip($target); | |
1193 | ||
1194 | my $vmid = extract_param($param, 'vmid'); | |
1195 | ||
1196 | raise_param_exc({ force => "Only root may use this option." }) if $user ne 'root@pam'; | |
1197 | ||
1198 | # test if VM exists | |
1199 | PVE::QemuServer::load_config($vmid); | |
1200 | ||
1201 | # try to detect errors early | |
1202 | if (PVE::QemuServer::check_running($vmid)) { | |
1203 | die "cant migrate running VM without --online\n" | |
1204 | if !$param->{online}; | |
1205 | } | |
1206 | ||
1207 | my $realcmd = sub { | |
1208 | my $upid = shift; | |
1209 | ||
1210 | PVE::QemuMigrate::migrate($target, $targetip, $vmid, $param->{online}, $param->{force}); | |
1211 | }; | |
1212 | ||
1213 | my $upid = $rpcenv->fork_worker('qmigrate', $vmid, $user, $realcmd); | |
1214 | ||
1215 | return $upid; | |
1216 | }}); | |
1e3baf05 DM |
1217 | |
1218 | 1; |