-
Notifications
You must be signed in to change notification settings - Fork 44
/
QemuServer.pm
8217 lines (6720 loc) · 238 KB
/
QemuServer.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package PVE::QemuServer;
use strict;
use warnings;
use Cwd 'abs_path';
use Digest::SHA;
use Fcntl ':flock';
use Fcntl;
use File::Basename;
use File::Copy qw(copy);
use File::Path;
use File::stat;
use Getopt::Long;
use IO::Dir;
use IO::File;
use IO::Handle;
use IO::Select;
use IO::Socket::UNIX;
use IPC::Open3;
use JSON;
use MIME::Base64;
use POSIX;
use Storable qw(dclone);
use Time::HiRes qw(gettimeofday usleep);
use URI::Escape;
use UUID;
use PVE::Cluster qw(cfs_register_file cfs_read_file cfs_write_file);
use PVE::CGroup;
use PVE::DataCenterConfig;
use PVE::Exception qw(raise raise_param_exc);
use PVE::Format qw(render_duration render_bytes);
use PVE::GuestHelpers qw(safe_string_ne safe_num_ne safe_boolean_ne);
use PVE::INotify;
use PVE::JSONSchema qw(get_standard_option parse_property_string);
use PVE::ProcFSTools;
use PVE::PBSClient;
use PVE::RPCEnvironment;
use PVE::Storage;
use PVE::SysFSTools;
use PVE::Systemd;
use PVE::Tools qw(run_command file_read_firstline file_get_contents dir_glob_foreach get_host_arch $IPV6RE);
use PVE::QMPClient;
use PVE::QemuConfig;
use PVE::QemuServer::Helpers qw(min_version config_aware_timeout);
use PVE::QemuServer::Cloudinit;
use PVE::QemuServer::CGroup;
use PVE::QemuServer::CPUConfig qw(print_cpu_device get_cpu_options);
use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit drive_is_cdrom drive_is_read_only parse_drive print_drive);
use PVE::QemuServer::Machine;
use PVE::QemuServer::Memory;
use PVE::QemuServer::Monitor qw(mon_cmd);
use PVE::QemuServer::PCI qw(print_pci_addr print_pcie_addr print_pcie_root_port parse_hostpci);
use PVE::QemuServer::USB qw(parse_usb_device);
my $have_sdn;
eval {
require PVE::Network::SDN::Zones;
$have_sdn = 1;
};
my $EDK2_FW_BASE = '/usr/share/pve-edk2-firmware/';
my $OVMF = {
x86_64 => {
'4m-no-smm' => [
"$EDK2_FW_BASE/OVMF_CODE_4M.fd",
"$EDK2_FW_BASE/OVMF_VARS_4M.fd",
],
'4m-no-smm-ms' => [
"$EDK2_FW_BASE/OVMF_CODE_4M.fd",
"$EDK2_FW_BASE/OVMF_VARS_4M.ms.fd",
],
'4m' => [
"$EDK2_FW_BASE/OVMF_CODE_4M.secboot.fd",
"$EDK2_FW_BASE/OVMF_VARS_4M.fd",
],
'4m-ms' => [
"$EDK2_FW_BASE/OVMF_CODE_4M.secboot.fd",
"$EDK2_FW_BASE/OVMF_VARS_4M.ms.fd",
],
default => [
"$EDK2_FW_BASE/OVMF_CODE.fd",
"$EDK2_FW_BASE/OVMF_VARS.fd",
],
},
aarch64 => {
default => [
"$EDK2_FW_BASE/AAVMF_CODE.fd",
"$EDK2_FW_BASE/AAVMF_VARS.fd",
],
},
};
my $cpuinfo = PVE::ProcFSTools::read_cpuinfo();
# Note about locking: we use flock on the config file protect against concurent actions.
# Aditionaly, we have a 'lock' setting in the config file. This can be set to 'migrate',
# 'backup', 'snapshot' or 'rollback'. Most actions are not allowed when such lock is set.
# But you can ignore this kind of lock with the --skiplock flag.
cfs_register_file('/qemu-server/',
\&parse_vm_config,
\&write_vm_config);
PVE::JSONSchema::register_standard_option('pve-qm-stateuri', {
description => "Some command save/restore state from this location.",
type => 'string',
maxLength => 128,
optional => 1,
});
PVE::JSONSchema::register_standard_option('pve-qemu-machine', {
description => "Specifies the Qemu machine type.",
type => 'string',
pattern => '(pc|pc(-i440fx)?-\d+(\.\d+)+(\+pve\d+)?(\.pxe)?|q35|pc-q35-\d+(\.\d+)+(\+pve\d+)?(\.pxe)?|virt(?:-\d+(\.\d+)+)?(\+pve\d+)?)',
maxLength => 40,
optional => 1,
});
PVE::JSONSchema::register_standard_option('pve-targetstorage', {
description => "Mapping from source to target storages. Providing only a single storage ID maps all source storages to that storage. Providing the special value '1' will map each source storage to itself.",
type => 'string',
format => 'storage-pair-list',
optional => 1,
});
#no warnings 'redefine';
my $nodename_cache;
sub nodename {
$nodename_cache //= PVE::INotify::nodename();
return $nodename_cache;
}
my $watchdog_fmt = {
model => {
default_key => 1,
type => 'string',
enum => [qw(i6300esb ib700)],
description => "Watchdog type to emulate.",
default => 'i6300esb',
optional => 1,
},
action => {
type => 'string',
enum => [qw(reset shutdown poweroff pause debug none)],
description => "The action to perform if after activation the guest fails to poll the watchdog in time.",
optional => 1,
},
};
PVE::JSONSchema::register_format('pve-qm-watchdog', $watchdog_fmt);
my $agent_fmt = {
enabled => {
description => "Enable/disable communication with a Qemu Guest Agent (QGA) running in the VM.",
type => 'boolean',
default => 0,
default_key => 1,
},
fstrim_cloned_disks => {
description => "Run fstrim after moving a disk or migrating the VM.",
type => 'boolean',
optional => 1,
default => 0
},
type => {
description => "Select the agent type",
type => 'string',
default => 'virtio',
optional => 1,
enum => [qw(virtio isa)],
},
};
my $vga_fmt = {
type => {
description => "Select the VGA type.",
type => 'string',
default => 'std',
optional => 1,
default_key => 1,
enum => [qw(cirrus qxl qxl2 qxl3 qxl4 none serial0 serial1 serial2 serial3 std virtio virtio-gl vmware)],
},
memory => {
description => "Sets the VGA memory (in MiB). Has no effect with serial display.",
type => 'integer',
optional => 1,
minimum => 4,
maximum => 512,
},
};
my $ivshmem_fmt = {
size => {
type => 'integer',
minimum => 1,
description => "The size of the file in MB.",
},
name => {
type => 'string',
pattern => '[a-zA-Z0-9\-]+',
optional => 1,
format_description => 'string',
description => "The name of the file. Will be prefixed with 'pve-shm-'. Default is the VMID. Will be deleted when the VM is stopped.",
},
};
my $audio_fmt = {
device => {
type => 'string',
enum => [qw(ich9-intel-hda intel-hda AC97)],
description => "Configure an audio device."
},
driver => {
type => 'string',
enum => ['spice', 'none'],
default => 'spice',
optional => 1,
description => "Driver backend for the audio device."
},
};
my $spice_enhancements_fmt = {
foldersharing => {
type => 'boolean',
optional => 1,
default => '0',
description => "Enable folder sharing via SPICE. Needs Spice-WebDAV daemon installed in the VM."
},
videostreaming => {
type => 'string',
enum => ['off', 'all', 'filter'],
default => 'off',
optional => 1,
description => "Enable video streaming. Uses compression for detected video streams."
},
};
my $rng_fmt = {
source => {
type => 'string',
enum => ['/dev/urandom', '/dev/random', '/dev/hwrng'],
default_key => 1,
description => "The file on the host to gather entropy from. In most cases '/dev/urandom'"
." should be preferred over '/dev/random' to avoid entropy-starvation issues on the"
." host. Using urandom does *not* decrease security in any meaningful way, as it's"
." still seeded from real entropy, and the bytes provided will most likely be mixed"
." with real entropy on the guest as well. '/dev/hwrng' can be used to pass through"
." a hardware RNG from the host.",
},
max_bytes => {
type => 'integer',
description => "Maximum bytes of entropy allowed to get injected into the guest every"
." 'period' milliseconds. Prefer a lower value when using '/dev/random' as source. Use"
." `0` to disable limiting (potentially dangerous!).",
optional => 1,
# default is 1 KiB/s, provides enough entropy to the guest to avoid boot-starvation issues
# (e.g. systemd etc...) while allowing no chance of overwhelming the host, provided we're
# reading from /dev/urandom
default => 1024,
},
period => {
type => 'integer',
description => "Every 'period' milliseconds the entropy-injection quota is reset, allowing"
." the guest to retrieve another 'max_bytes' of entropy.",
optional => 1,
default => 1000,
},
};
my $meta_info_fmt = {
'ctime' => {
type => 'integer',
description => "The guest creation timestamp as UNIX epoch time",
minimum => 0,
optional => 1,
},
'creation-qemu' => {
type => 'string',
description => "The QEMU (machine) version from the time this VM was created.",
pattern => '\d+(\.\d+)+',
optional => 1,
},
};
my $confdesc = {
onboot => {
optional => 1,
type => 'boolean',
description => "Specifies whether a VM will be started during system bootup.",
default => 0,
},
autostart => {
optional => 1,
type => 'boolean',
description => "Automatic restart after crash (currently ignored).",
default => 0,
},
hotplug => {
optional => 1,
type => 'string', format => 'pve-hotplug-features',
description => "Selectively enable hotplug features. This is a comma separated list of"
." hotplug features: 'network', 'disk', 'cpu', 'memory' and 'usb'. Use '0' to disable"
." hotplug completely. Using '1' as value is an alias for the default `network,disk,usb`.",
default => 'network,disk,usb',
},
reboot => {
optional => 1,
type => 'boolean',
description => "Allow reboot. If set to '0' the VM exit on reboot.",
default => 1,
},
lock => {
optional => 1,
type => 'string',
description => "Lock/unlock the VM.",
enum => [qw(backup clone create migrate rollback snapshot snapshot-delete suspending suspended)],
},
cpulimit => {
optional => 1,
type => 'number',
description => "Limit of CPU usage.",
verbose_description => "Limit of CPU usage.\n\nNOTE: If the computer has 2 CPUs, it has"
." total of '2' CPU time. Value '0' indicates no CPU limit.",
minimum => 0,
maximum => 128,
default => 0,
},
cpuunits => {
optional => 1,
type => 'integer',
description => "CPU weight for a VM, will be clamped to [1, 10000] in cgroup v2.",
verbose_description => "CPU weight for a VM. Argument is used in the kernel fair scheduler."
." The larger the number is, the more CPU time this VM gets. Number is relative to"
." weights of all the other running VMs.",
minimum => 1,
maximum => 262144,
default => 'cgroup v1: 1024, cgroup v2: 100',
},
memory => {
optional => 1,
type => 'integer',
description => "Amount of RAM for the VM in MB. This is the maximum available memory when"
." you use the balloon device.",
minimum => 16,
default => 512,
},
balloon => {
optional => 1,
type => 'integer',
description => "Amount of target RAM for the VM in MB. Using zero disables the ballon driver.",
minimum => 0,
},
shares => {
optional => 1,
type => 'integer',
description => "Amount of memory shares for auto-ballooning. The larger the number is, the"
." more memory this VM gets. Number is relative to weights of all other running VMs."
." Using zero disables auto-ballooning. Auto-ballooning is done by pvestatd.",
minimum => 0,
maximum => 50000,
default => 1000,
},
keyboard => {
optional => 1,
type => 'string',
description => "Keyboard layout for VNC server. This option is generally not required and"
." is often better handled from within the guest OS.",
enum => PVE::Tools::kvmkeymaplist(),
default => undef,
},
name => {
optional => 1,
type => 'string', format => 'dns-name',
description => "Set a name for the VM. Only used on the configuration web interface.",
},
scsihw => {
optional => 1,
type => 'string',
description => "SCSI controller model",
enum => [qw(lsi lsi53c810 virtio-scsi-pci virtio-scsi-single megasas pvscsi)],
default => 'lsi',
},
description => {
optional => 1,
type => 'string',
description => "Description for the VM. Shown in the web-interface VM's summary."
." This is saved as comment inside the configuration file.",
maxLength => 1024 * 8,
},
ostype => {
optional => 1,
type => 'string',
enum => [qw(other wxp w2k w2k3 w2k8 wvista win7 win8 win10 win11 l24 l26 solaris)],
description => "Specify guest operating system.",
verbose_description => <<EODESC,
Specify guest operating system. This is used to enable special
optimization/features for specific operating systems:
[horizontal]
other;; unspecified OS
wxp;; Microsoft Windows XP
w2k;; Microsoft Windows 2000
w2k3;; Microsoft Windows 2003
w2k8;; Microsoft Windows 2008
wvista;; Microsoft Windows Vista
win7;; Microsoft Windows 7
win8;; Microsoft Windows 8/2012/2012r2
win10;; Microsoft Windows 10/2016/2019
win11;; Microsoft Windows 11/2022
l24;; Linux 2.4 Kernel
l26;; Linux 2.6 - 5.X Kernel
solaris;; Solaris/OpenSolaris/OpenIndiania kernel
EODESC
},
boot => {
optional => 1,
type => 'string', format => 'pve-qm-boot',
description => "Specify guest boot order. Use the 'order=' sub-property as usage with no"
." key or 'legacy=' is deprecated.",
},
bootdisk => {
optional => 1,
type => 'string', format => 'pve-qm-bootdisk',
description => "Enable booting from specified disk. Deprecated: Use 'boot: order=foo;bar' instead.",
pattern => '(ide|sata|scsi|virtio)\d+',
},
smp => {
optional => 1,
type => 'integer',
description => "The number of CPUs. Please use option -sockets instead.",
minimum => 1,
default => 1,
},
sockets => {
optional => 1,
type => 'integer',
description => "The number of CPU sockets.",
minimum => 1,
default => 1,
},
cores => {
optional => 1,
type => 'integer',
description => "The number of cores per socket.",
minimum => 1,
default => 1,
},
numa => {
optional => 1,
type => 'boolean',
description => "Enable/disable NUMA.",
default => 0,
},
hugepages => {
optional => 1,
type => 'string',
description => "Enable/disable hugepages memory.",
enum => [qw(any 2 1024)],
},
keephugepages => {
optional => 1,
type => 'boolean',
default => 0,
description => "Use together with hugepages. If enabled, hugepages will not not be deleted"
." after VM shutdown and can be used for subsequent starts.",
},
vcpus => {
optional => 1,
type => 'integer',
description => "Number of hotplugged vcpus.",
minimum => 1,
default => 0,
},
acpi => {
optional => 1,
type => 'boolean',
description => "Enable/disable ACPI.",
default => 1,
},
agent => {
optional => 1,
description => "Enable/disable communication with the Qemu Guest Agent and its properties.",
type => 'string',
format => $agent_fmt,
},
kvm => {
optional => 1,
type => 'boolean',
description => "Enable/disable KVM hardware virtualization.",
default => 1,
},
tdf => {
optional => 1,
type => 'boolean',
description => "Enable/disable time drift fix.",
default => 0,
},
localtime => {
optional => 1,
type => 'boolean',
description => "Set the real time clock (RTC) to local time. This is enabled by default if"
." the `ostype` indicates a Microsoft Windows OS.",
},
freeze => {
optional => 1,
type => 'boolean',
description => "Freeze CPU at startup (use 'c' monitor command to start execution).",
},
vga => {
optional => 1,
type => 'string', format => $vga_fmt,
description => "Configure the VGA hardware.",
verbose_description => "Configure the VGA Hardware. If you want to use high resolution"
." modes (>= 1280x1024x16) you may need to increase the vga memory option. Since QEMU"
." 2.9 the default VGA display type is 'std' for all OS types besides some Windows"
." versions (XP and older) which use 'cirrus'. The 'qxl' option enables the SPICE"
." display server. For win* OS you can select how many independent displays you want,"
." Linux guests can add displays them self.\nYou can also run without any graphic card,"
." using a serial device as terminal.",
},
watchdog => {
optional => 1,
type => 'string', format => 'pve-qm-watchdog',
description => "Create a virtual hardware watchdog device.",
verbose_description => "Create a virtual hardware watchdog device. Once enabled (by a guest"
." action), the watchdog must be periodically polled by an agent inside the guest or"
." else the watchdog will reset the guest (or execute the respective action specified)",
},
startdate => {
optional => 1,
type => 'string',
typetext => "(now | YYYY-MM-DD | YYYY-MM-DDTHH:MM:SS)",
description => "Set the initial date of the real time clock. Valid format for date are:"
."'now' or '2006-06-17T16:01:21' or '2006-06-17'.",
pattern => '(now|\d{4}-\d{1,2}-\d{1,2}(T\d{1,2}:\d{1,2}:\d{1,2})?)',
default => 'now',
},
startup => get_standard_option('pve-startup-order'),
template => {
optional => 1,
type => 'boolean',
description => "Enable/disable Template.",
default => 0,
},
args => {
optional => 1,
type => 'string',
description => "Arbitrary arguments passed to kvm.",
verbose_description => <<EODESCR,
Arbitrary arguments passed to kvm, for example:
args: -no-reboot -no-hpet
NOTE: this option is for experts only.
EODESCR
},
tablet => {
optional => 1,
type => 'boolean',
default => 1,
description => "Enable/disable the USB tablet device.",
verbose_description => "Enable/disable the USB tablet device. This device is usually needed"
." to allow absolute mouse positioning with VNC. Else the mouse runs out of sync with"
." normal VNC clients. If you're running lots of console-only guests on one host, you"
." may consider disabling this to save some context switches. This is turned off by"
." default if you use spice (`qm set <vmid> --vga qxl`).",
},
migrate_speed => {
optional => 1,
type => 'integer',
description => "Set maximum speed (in MB/s) for migrations. Value 0 is no limit.",
minimum => 0,
default => 0,
},
migrate_downtime => {
optional => 1,
type => 'number',
description => "Set maximum tolerated downtime (in seconds) for migrations.",
minimum => 0,
default => 0.1,
},
cdrom => {
optional => 1,
type => 'string', format => 'pve-qm-ide',
typetext => '<volume>',
description => "This is an alias for option -ide2",
},
cpu => {
optional => 1,
description => "Emulated CPU type.",
type => 'string',
format => 'pve-vm-cpu-conf',
},
parent => get_standard_option('pve-snapshot-name', {
optional => 1,
description => "Parent snapshot name. This is used internally, and should not be modified.",
}),
snaptime => {
optional => 1,
description => "Timestamp for snapshots.",
type => 'integer',
minimum => 0,
},
vmstate => {
optional => 1,
type => 'string', format => 'pve-volume-id',
description => "Reference to a volume which stores the VM state. This is used internally"
." for snapshots.",
},
vmstatestorage => get_standard_option('pve-storage-id', {
description => "Default storage for VM state volumes/files.",
optional => 1,
}),
runningmachine => get_standard_option('pve-qemu-machine', {
description => "Specifies the QEMU machine type of the running vm. This is used internally"
." for snapshots.",
}),
runningcpu => {
description => "Specifies the QEMU '-cpu' parameter of the running vm. This is used"
." internally for snapshots.",
optional => 1,
type => 'string',
pattern => $PVE::QemuServer::CPUConfig::qemu_cmdline_cpu_re,
format_description => 'QEMU -cpu parameter'
},
machine => get_standard_option('pve-qemu-machine'),
arch => {
description => "Virtual processor architecture. Defaults to the host.",
optional => 1,
type => 'string',
enum => [qw(x86_64 aarch64)],
},
smbios1 => {
description => "Specify SMBIOS type 1 fields.",
type => 'string', format => 'pve-qm-smbios1',
maxLength => 512,
optional => 1,
},
protection => {
optional => 1,
type => 'boolean',
description => "Sets the protection flag of the VM. This will disable the remove VM and"
." remove disk operations.",
default => 0,
},
bios => {
optional => 1,
type => 'string',
enum => [ qw(seabios ovmf) ],
description => "Select BIOS implementation.",
default => 'seabios',
},
vmgenid => {
type => 'string',
pattern => '(?:[a-fA-F0-9]{8}(?:-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}|[01])',
format_description => 'UUID',
description => "Set VM Generation ID. Use '1' to autogenerate on create or update, pass '0'"
." to disable explicitly.",
verbose_description => "The VM generation ID (vmgenid) device exposes a 128-bit integer"
." value identifier to the guest OS. This allows to notify the guest operating system"
." when the virtual machine is executed with a different configuration (e.g. snapshot"
." execution or creation from a template). The guest operating system notices the"
." change, and is then able to react as appropriate by marking its copies of"
." distributed databases as dirty, re-initializing its random number generator, etc.\n"
."Note that auto-creation only works when done through API/CLI create or update methods"
.", but not when manually editing the config file.",
default => "1 (autogenerated)",
optional => 1,
},
hookscript => {
type => 'string',
format => 'pve-volume-id',
optional => 1,
description => "Script that will be executed during various steps in the vms lifetime.",
},
ivshmem => {
type => 'string',
format => $ivshmem_fmt,
description => "Inter-VM shared memory. Useful for direct communication between VMs, or to"
." the host.",
optional => 1,
},
audio0 => {
type => 'string',
format => $audio_fmt,
description => "Configure a audio device, useful in combination with QXL/Spice.",
optional => 1
},
spice_enhancements => {
type => 'string',
format => $spice_enhancements_fmt,
description => "Configure additional enhancements for SPICE.",
optional => 1
},
tags => {
type => 'string', format => 'pve-tag-list',
description => 'Tags of the VM. This is only meta information.',
optional => 1,
},
rng0 => {
type => 'string',
format => $rng_fmt,
description => "Configure a VirtIO-based Random Number Generator.",
optional => 1,
},
meta => {
type => 'string',
format => $meta_info_fmt,
description => "Some (read-only) meta-information about this guest.",
optional => 1,
},
};
my $cicustom_fmt = {
meta => {
type => 'string',
optional => 1,
description => 'Specify a custom file containing all meta data passed to the VM via"
." cloud-init. This is provider specific meaning configdrive2 and nocloud differ.',
format => 'pve-volume-id',
format_description => 'volume',
},
network => {
type => 'string',
optional => 1,
description => 'Specify a custom file containing all network data passed to the VM via'
.' cloud-init.',
format => 'pve-volume-id',
format_description => 'volume',
},
user => {
type => 'string',
optional => 1,
description => 'Specify a custom file containing all user data passed to the VM via'
.' cloud-init.',
format => 'pve-volume-id',
format_description => 'volume',
},
vendor => {
type => 'string',
optional => 1,
description => 'Specify a custom file containing all vendor data passed to the VM via'
.' cloud-init.',
format => 'pve-volume-id',
format_description => 'volume',
},
};
PVE::JSONSchema::register_format('pve-qm-cicustom', $cicustom_fmt);
my $confdesc_cloudinit = {
citype => {
optional => 1,
type => 'string',
description => 'Specifies the cloud-init configuration format. The default depends on the'
.' configured operating system type (`ostype`. We use the `nocloud` format for Linux,'
.' and `configdrive2` for windows.',
enum => ['configdrive2', 'nocloud', 'opennebula'],
},
ciuser => {
optional => 1,
type => 'string',
description => "cloud-init: User name to change ssh keys and password for instead of the"
." image's configured default user.",
},
cipassword => {
optional => 1,
type => 'string',
description => 'cloud-init: Password to assign the user. Using this is generally not'
.' recommended. Use ssh keys instead. Also note that older cloud-init versions do not'
.' support hashed passwords.',
},
cicustom => {
optional => 1,
type => 'string',
description => 'cloud-init: Specify custom files to replace the automatically generated'
.' ones at start.',
format => 'pve-qm-cicustom',
},
searchdomain => {
optional => 1,
type => 'string',
description => "cloud-init: Sets DNS search domains for a container. Create will'
.' automatically use the setting from the host if neither searchdomain nor nameserver'
.' are set.",
},
nameserver => {
optional => 1,
type => 'string', format => 'address-list',
description => "cloud-init: Sets DNS server IP address for a container. Create will'
.' automatically use the setting from the host if neither searchdomain nor nameserver'
.' are set.",
},
sshkeys => {
optional => 1,
type => 'string',
format => 'urlencoded',
description => "cloud-init: Setup public SSH keys (one key per line, OpenSSH format).",
},
};
# what about other qemu settings ?
#cpu => 'string',
#machine => 'string',
#fda => 'file',
#fdb => 'file',
#mtdblock => 'file',
#sd => 'file',
#pflash => 'file',
#snapshot => 'bool',
#bootp => 'file',
##tftp => 'dir',
##smb => 'dir',
#kernel => 'file',
#append => 'string',
#initrd => 'file',
##soundhw => 'string',
while (my ($k, $v) = each %$confdesc) {
PVE::JSONSchema::register_standard_option("pve-qm-$k", $v);
}
my $MAX_USB_DEVICES = 5;
my $MAX_NETS = 32;
my $MAX_SERIAL_PORTS = 4;
my $MAX_PARALLEL_PORTS = 3;
my $MAX_NUMA = 8;
my $numa_fmt = {
cpus => {
type => "string",
pattern => qr/\d+(?:-\d+)?(?:;\d+(?:-\d+)?)*/,
description => "CPUs accessing this NUMA node.",
format_description => "id[-id];...",
},
memory => {
type => "number",
description => "Amount of memory this NUMA node provides.",
optional => 1,
},
hostnodes => {
type => "string",
pattern => qr/\d+(?:-\d+)?(?:;\d+(?:-\d+)?)*/,
description => "Host NUMA nodes to use.",
format_description => "id[-id];...",
optional => 1,
},
policy => {
type => 'string',
enum => [qw(preferred bind interleave)],
description => "NUMA allocation policy.",
optional => 1,
},
};
PVE::JSONSchema::register_format('pve-qm-numanode', $numa_fmt);
my $numadesc = {
optional => 1,
type => 'string', format => $numa_fmt,
description => "NUMA topology.",
};
PVE::JSONSchema::register_standard_option("pve-qm-numanode", $numadesc);
for (my $i = 0; $i < $MAX_NUMA; $i++) {
$confdesc->{"numa$i"} = $numadesc;
}
my $nic_model_list = [
'e1000',
'e1000-82540em',
'e1000-82544gc',
'e1000-82545em',
'e1000e',
'i82551',
'i82557b',
'i82559er',
'ne2k_isa',
'ne2k_pci',
'pcnet',
'rtl8139',
'virtio',
'vmxnet3',
];
my $nic_model_list_txt = join(' ', sort @$nic_model_list);
my $net_fmt_bridge_descr = <<__EOD__;
Bridge to attach the network device to. The Proxmox VE standard bridge
is called 'vmbr0'.
If you do not specify a bridge, we create a kvm user (NATed) network
device, which provides DHCP and DNS services. The following addresses
are used:
10.0.2.2 Gateway
10.0.2.3 DNS Server
10.0.2.4 SMB Server
The DHCP server assign addresses to the guest starting from 10.0.2.15.
__EOD__
my $net_fmt = {
macaddr => get_standard_option('mac-addr', {
description => "MAC address. That address must be unique withing your network. This is"
." automatically generated if not specified.",
}),
model => {
type => 'string',
description => "Network Card Model. The 'virtio' model provides the best performance with"
." very low CPU overhead. If your guest does not support this driver, it is usually"
." best to use 'e1000'.",
enum => $nic_model_list,
default_key => 1,
},
(map { $_ => { keyAlias => 'model', alias => 'macaddr' }} @$nic_model_list),
bridge => get_standard_option('pve-bridge-id', {
description => $net_fmt_bridge_descr,
optional => 1,
}),
queues => {
type => 'integer',
minimum => 0, maximum => 16,
description => 'Number of packet queues to be used on the device.',
optional => 1,
},
rate => {
type => 'number',
minimum => 0,
description => "Rate limit in mbps (megabytes per second) as floating point number.",
optional => 1,
},
tag => {
type => 'integer',
minimum => 1, maximum => 4094,
description => 'VLAN tag to apply to packets on this interface.',
optional => 1,
},
trunks => {
type => 'string',
pattern => qr/\d+(?:-\d+)?(?:;\d+(?:-\d+)?)*/,
description => 'VLAN trunks to pass through this interface.',
format_description => 'vlanid[;vlanid...]',
optional => 1,
},
firewall => {
type => 'boolean',
description => 'Whether this interface should be protected by the firewall.',
optional => 1,
},
link_down => {
type => 'boolean',
description => 'Whether this interface should be disconnected (like pulling the plug).',
optional => 1,
},
mtu => {
type => 'integer',
minimum => 1, maximum => 65520,
description => "Force MTU, for VirtIO only. Set to '1' to use the bridge MTU",
optional => 1,
},
};
my $netdesc = {
optional => 1,
type => 'string', format => $net_fmt,
description => "Specify network devices.",
};
PVE::JSONSchema::register_standard_option("pve-qm-net", $netdesc);
my $ipconfig_fmt = {
ip => {
type => 'string',
format => 'pve-ipv4-config',
format_description => 'IPv4Format/CIDR',
description => 'IPv4 address in CIDR format.',
optional => 1,
default => 'dhcp',
},
gw => {
type => 'string',
format => 'ipv4',
format_description => 'GatewayIPv4',
description => 'Default gateway for IPv4 traffic.',
optional => 1,
requires => 'ip',
},
ip6 => {
type => 'string',
format => 'pve-ipv6-config',
format_description => 'IPv6Format/CIDR',
description => 'IPv6 address in CIDR format.',
optional => 1,
default => 'dhcp',
},
gw6 => {
type => 'string',
format => 'ipv6',
format_description => 'GatewayIPv6',