summaryrefslogtreecommitdiff
path: root/nova/objects/fields.py
blob: cae1ea4a4d731baa6c7b8741abf44efaf9431311 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
#    Copyright 2013 Red Hat, Inc.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import os
import re

from cursive import signature_utils
from oslo_serialization import jsonutils
from oslo_versionedobjects import fields

from nova import exception
from nova.i18n import _
from nova.network import model as network_model
from nova.virt import arch


# Import field errors from oslo.versionedobjects
KeyTypeError = fields.KeyTypeError
ElementTypeError = fields.ElementTypeError


# Import fields from oslo.versionedobjects
BooleanField = fields.BooleanField
UnspecifiedDefault = fields.UnspecifiedDefault
IntegerField = fields.IntegerField
NonNegativeIntegerField = fields.NonNegativeIntegerField
UUIDField = fields.UUIDField
FloatField = fields.FloatField
NonNegativeFloatField = fields.NonNegativeFloatField
StringField = fields.StringField
SensitiveStringField = fields.SensitiveStringField
EnumField = fields.EnumField
DateTimeField = fields.DateTimeField
DictOfStringsField = fields.DictOfStringsField
DictOfNullableStringsField = fields.DictOfNullableStringsField
DictOfIntegersField = fields.DictOfIntegersField
ListOfStringsField = fields.ListOfStringsField
ListOfUUIDField = fields.ListOfUUIDField
SetOfIntegersField = fields.SetOfIntegersField
ListOfSetsOfIntegersField = fields.ListOfSetsOfIntegersField
ListOfDictOfNullableStringsField = fields.ListOfDictOfNullableStringsField
DictProxyField = fields.DictProxyField
ObjectField = fields.ObjectField
ListOfObjectsField = fields.ListOfObjectsField
VersionPredicateField = fields.VersionPredicateField
FlexibleBooleanField = fields.FlexibleBooleanField
DictOfListOfStringsField = fields.DictOfListOfStringsField
IPAddressField = fields.IPAddressField
IPV4AddressField = fields.IPV4AddressField
IPV6AddressField = fields.IPV6AddressField
IPV4AndV6AddressField = fields.IPV4AndV6AddressField
IPNetworkField = fields.IPNetworkField
IPV4NetworkField = fields.IPV4NetworkField
IPV6NetworkField = fields.IPV6NetworkField
AutoTypedField = fields.AutoTypedField
BaseEnumField = fields.BaseEnumField
MACAddressField = fields.MACAddressField
ListOfIntegersField = fields.ListOfIntegersField
PCIAddressField = fields.PCIAddressField


# NOTE(danms): These are things we need to import for some of our
# own implementations below, our tests, or other transitional
# bits of code. These should be removable after we finish our
# conversion. So do not use these nova fields directly in any new code;
# instead, use the oslo.versionedobjects fields.
Enum = fields.Enum
Field = fields.Field
FieldType = fields.FieldType
Set = fields.Set
Dict = fields.Dict
List = fields.List
Object = fields.Object
IPAddress = fields.IPAddress
IPV4Address = fields.IPV4Address
IPV6Address = fields.IPV6Address
IPNetwork = fields.IPNetwork
IPV4Network = fields.IPV4Network
IPV6Network = fields.IPV6Network


class ResourceClass(fields.StringPattern):

    PATTERN = r"^[A-Z0-9_]+$"
    _REGEX = re.compile(PATTERN)

    @staticmethod
    def coerce(obj, attr, value):
        if isinstance(value, str):
            uppered = value.upper()
            if ResourceClass._REGEX.match(uppered):
                return uppered
        raise ValueError(_("Malformed Resource Class %s") % value)


class ResourceClassField(AutoTypedField):
    AUTO_TYPE = ResourceClass()


class SetOfStringsField(AutoTypedField):
    AUTO_TYPE = Set(fields.String())


class BaseNovaEnum(Enum):
    def __init__(self, **kwargs):
        super(BaseNovaEnum, self).__init__(valid_values=self.__class__.ALL)


class Architecture(BaseNovaEnum):
    """Represents CPU architectures.

    Provides the standard names for all known processor architectures.
    Many have multiple variants to deal with big-endian vs little-endian
    modes, as well as 32 vs 64 bit word sizes. These names are chosen to
    be identical to the architecture names expected by libvirt, so if
    ever adding new ones then ensure it matches libvirt's expectation.
    """

    ALPHA = arch.ALPHA
    ARMV6 = arch.ARMV6
    ARMV7 = arch.ARMV7
    ARMV7B = arch.ARMV7B

    AARCH64 = arch.AARCH64
    CRIS = arch.CRIS
    I686 = arch.I686
    IA64 = arch.IA64
    LM32 = arch.LM32

    M68K = arch.M68K
    MICROBLAZE = arch.MICROBLAZE
    MICROBLAZEEL = arch.MICROBLAZEEL
    MIPS = arch.MIPS
    MIPSEL = arch.MIPSEL

    MIPS64 = arch.MIPS64
    MIPS64EL = arch.MIPS64EL
    OPENRISC = arch.OPENRISC
    PARISC = arch.PARISC
    PARISC64 = arch.PARISC64

    PPC = arch.PPC
    PPCLE = arch.PPCLE
    PPC64 = arch.PPC64
    PPC64LE = arch.PPC64LE
    PPCEMB = arch.PPCEMB

    S390 = arch.S390
    S390X = arch.S390X
    SH4 = arch.SH4
    SH4EB = arch.SH4EB
    SPARC = arch.SPARC

    SPARC64 = arch.SPARC64
    UNICORE32 = arch.UNICORE32
    X86_64 = arch.X86_64
    XTENSA = arch.XTENSA
    XTENSAEB = arch.XTENSAEB

    ALL = arch.ALL

    @classmethod
    def from_host(cls):
        """Get the architecture of the host OS

        :returns: the canonicalized host architecture
        """

        return cls.canonicalize(os.uname().machine)

    @classmethod
    def is_valid(cls, name):
        """Check if a string is a valid architecture

        :param name: architecture name to validate

        :returns: True if @name is valid
        """

        return name in cls.ALL

    @classmethod
    def canonicalize(cls, name):
        """Canonicalize the architecture name

        :param name: architecture name to canonicalize

        :returns: a canonical architecture name
        """

        if name is None:
            return None

        newname = name.lower()

        if newname in ("i386", "i486", "i586"):
            newname = cls.I686

        # Xen mistake from Icehouse or earlier
        if newname in ("x86_32", "x86_32p"):
            newname = cls.I686

        if newname == "amd64":
            newname = cls.X86_64

        if not cls.is_valid(newname):
            raise exception.InvalidArchitectureName(arch=name)

        return newname

    def coerce(self, obj, attr, value):
        try:
            value = self.canonicalize(value)
        except exception.InvalidArchitectureName:
            msg = _("Architecture name '%s' is not valid") % value
            raise ValueError(msg)
        return super(Architecture, self).coerce(obj, attr, value)


class BlockDeviceDestinationType(BaseNovaEnum):
    """Represents possible destination_type values for a BlockDeviceMapping."""

    LOCAL = 'local'
    VOLUME = 'volume'

    ALL = (LOCAL, VOLUME)


class BlockDeviceSourceType(BaseNovaEnum):
    """Represents the possible source_type values for a BlockDeviceMapping."""

    BLANK = 'blank'
    IMAGE = 'image'
    SNAPSHOT = 'snapshot'
    VOLUME = 'volume'

    ALL = (BLANK, IMAGE, SNAPSHOT, VOLUME)


class BlockDeviceType(BaseNovaEnum):
    """Represents possible device_type values for a BlockDeviceMapping."""

    CDROM = 'cdrom'
    DISK = 'disk'
    FLOPPY = 'floppy'
    FS = 'fs'
    LUN = 'lun'

    ALL = (CDROM, DISK, FLOPPY, FS, LUN)


class BlockDeviceEncryptionFormatType(BaseNovaEnum):
    PLAIN = 'plain'
    LUKS = 'luks'
    LUKSv2 = 'luksv2'

    ALL = (PLAIN, LUKS, LUKSv2)


class ConfigDrivePolicy(BaseNovaEnum):
    OPTIONAL = "optional"
    MANDATORY = "mandatory"

    ALL = (OPTIONAL, MANDATORY)


class CPUAllocationPolicy(BaseNovaEnum):

    DEDICATED = "dedicated"
    SHARED = "shared"
    MIXED = "mixed"

    ALL = (DEDICATED, SHARED, MIXED)


class CPUThreadAllocationPolicy(BaseNovaEnum):

    # prefer (default): The host may or may not have hyperthreads. This
    #  retains the legacy behavior, whereby siblings are preferred when
    #  available. This is the default if no policy is specified.
    PREFER = "prefer"
    # isolate: The host may or many not have hyperthreads. If hyperthreads are
    #  present, each vCPU will be placed on a different core and no vCPUs from
    #  other guests will be able to be placed on the same core, i.e. one
    #  thread sibling is guaranteed to always be unused. If hyperthreads are
    #  not present, each vCPU will still be placed on a different core and
    #  there are no thread siblings to be concerned with.
    ISOLATE = "isolate"
    # require: The host must have hyperthreads. Each vCPU will be allocated on
    #   thread siblings.
    REQUIRE = "require"

    ALL = (PREFER, ISOLATE, REQUIRE)


class CPUEmulatorThreadsPolicy(BaseNovaEnum):

    # share (default): Emulator threads float across the pCPUs
    # associated to the guest.
    SHARE = "share"
    # isolate: Emulator threads are isolated on a single pCPU.
    ISOLATE = "isolate"

    ALL = (SHARE, ISOLATE)


class CPUMode(BaseNovaEnum):

    CUSTOM = 'custom'
    HOST_MODEL = 'host-model'
    HOST_PASSTHROUGH = 'host-passthrough'

    ALL = (CUSTOM, HOST_MODEL, HOST_PASSTHROUGH)


class CPUMatch(BaseNovaEnum):

    MINIMUM = 'minimum'
    EXACT = 'exact'
    STRICT = 'strict'

    ALL = (MINIMUM, EXACT, STRICT)


class CPUFeaturePolicy(BaseNovaEnum):

    FORCE = 'force'
    REQUIRE = 'require'
    OPTIONAL = 'optional'
    DISABLE = 'disable'
    FORBID = 'forbid'

    ALL = (FORCE, REQUIRE, OPTIONAL, DISABLE, FORBID)


class DiskBus(BaseNovaEnum):

    # NOTE(aspiers): If you change this, don't forget to update the
    # docs and metadata for hw_*_bus in glance.
    # NOTE(lyarwood): Also update the possible values in the api-ref for the
    # block_device_mapping_v2.disk_bus parameter.
    FDC = "fdc"
    IDE = "ide"
    SATA = "sata"
    SCSI = "scsi"
    USB = "usb"
    VIRTIO = "virtio"
    XEN = "xen"
    LXC = "lxc"
    UML = "uml"

    ALL = (FDC, IDE, SATA, SCSI, USB, VIRTIO, XEN, LXC, UML)


class DiskConfig(BaseNovaEnum):

    MANUAL = "MANUAL"
    AUTO = "AUTO"

    ALL = (MANUAL, AUTO)

    def coerce(self, obj, attr, value):
        enum_value = DiskConfig.AUTO if value else DiskConfig.MANUAL
        return super(DiskConfig, self).coerce(obj, attr, enum_value)


class FirmwareType(BaseNovaEnum):

    UEFI = "uefi"
    BIOS = "bios"

    ALL = (UEFI, BIOS)


class HVType(BaseNovaEnum):
    """Represents virtualization types.

    Provide the standard names for all known guest virtualization
    types. This is not to be confused with the Nova hypervisor driver
    types, since one driver may support multiple virtualization types
    and one virtualization type may be supported by multiple drivers.
    """

    BAREMETAL = 'baremetal'
    BHYVE = 'bhyve'
    DOCKER = 'docker'
    FAKE = 'fake'
    HYPERV = 'hyperv'
    IRONIC = 'ironic'
    KQEMU = 'kqemu'
    KVM = 'kvm'
    LXC = 'lxc'
    LXD = 'lxd'
    OPENVZ = 'openvz'
    PARALLELS = 'parallels'
    VIRTUOZZO = 'vz'
    PHYP = 'phyp'
    QEMU = 'qemu'
    TEST = 'test'
    UML = 'uml'
    VBOX = 'vbox'
    VMWARE = 'vmware'
    XEN = 'xen'
    ZVM = 'zvm'
    PRSM = 'prsm'

    ALL = (BAREMETAL, BHYVE, DOCKER, FAKE, HYPERV, IRONIC, KQEMU, KVM, LXC,
           LXD, OPENVZ, PARALLELS, PHYP, QEMU, TEST, UML, VBOX, VIRTUOZZO,
           VMWARE, XEN, ZVM, PRSM)

    def coerce(self, obj, attr, value):
        try:
            value = self.canonicalize(value)
        except exception.InvalidHypervisorVirtType:
            msg = _("Hypervisor virt type '%s' is not valid") % value
            raise ValueError(msg)

        return super(HVType, self).coerce(obj, attr, value)

    @classmethod
    def is_valid(cls, name):
        """Check if a string is a valid hypervisor type

        :param name: hypervisor type name to validate

        :returns: True if @name is valid
        """
        return name in cls.ALL

    @classmethod
    def canonicalize(cls, name):
        """Canonicalize the hypervisor type name

        :param name: hypervisor type name to canonicalize

        :returns: a canonical hypervisor type name
        """
        if name is None:
            return None

        newname = name.lower()

        if newname == 'xapi':
            newname = cls.XEN

        if not cls.is_valid(newname):
            raise exception.InvalidHypervisorVirtType(hv_type=name)

        return newname


class ImageSignatureHashType(BaseNovaEnum):
    # Represents the possible hash methods used for image signing
    ALL = tuple(sorted(signature_utils.HASH_METHODS.keys()))


class ImageSignatureKeyType(BaseNovaEnum):
    # Represents the possible keypair types used for image signing
    ALL = (
        'DSA', 'ECC_SECP384R1', 'ECC_SECP521R1', 'ECC_SECT409K1',
        'ECC_SECT409R1', 'ECC_SECT571K1', 'ECC_SECT571R1', 'RSA-PSS'
    )


class InputBus(BaseNovaEnum):

    USB = 'usb'
    VIRTIO = 'virtio'

    ALL = (USB, VIRTIO)


class MigrationType(BaseNovaEnum):

    MIGRATION = 'migration'  # cold migration
    RESIZE = 'resize'
    LIVE_MIGRATION = 'live-migration'
    EVACUATION = 'evacuation'

    ALL = (MIGRATION, RESIZE, LIVE_MIGRATION, EVACUATION)


class OSType(BaseNovaEnum):

    LINUX = "linux"
    WINDOWS = "windows"

    ALL = (LINUX, WINDOWS)

    def coerce(self, obj, attr, value):
        # Some code/docs use upper case or initial caps
        # so canonicalize to all lower case
        value = value.lower()
        return super(OSType, self).coerce(obj, attr, value)


class RNGModel(BaseNovaEnum):

    # NOTE(kchamart): Along with "virtio", we may need to extend this (if a
    # good reason shows up) to allow two more values for VirtIO
    # transitional and non-transitional devices (available since libvirt
    # 5.2.0):
    #
    #   - virtio-transitional
    #   - virtio-nontransitional
    #
    # This allows one to choose whether you want to have compatibility
    # with older guest operating systems.  The value you select will in
    # turn decide the kind of PCI topology the guest will get.
    #
    # Details:
    # https://libvirt.org/formatdomain.html#elementsVirtioTransitional
    VIRTIO = "virtio"

    ALL = (VIRTIO,)


class TPMModel(BaseNovaEnum):

    TIS = "tpm-tis"
    CRB = "tpm-crb"

    ALL = (TIS, CRB)


class TPMVersion(BaseNovaEnum):
    v1_2 = "1.2"
    v2_0 = "2.0"

    ALL = (v1_2, v2_0)


class SCSIModel(BaseNovaEnum):

    BUSLOGIC = "buslogic"
    IBMVSCSI = "ibmvscsi"
    LSILOGIC = "lsilogic"
    LSISAS1068 = "lsisas1068"
    LSISAS1078 = "lsisas1078"
    VIRTIO_SCSI = "virtio-scsi"
    VMPVSCSI = "vmpvscsi"

    ALL = (BUSLOGIC, IBMVSCSI, LSILOGIC, LSISAS1068,
           LSISAS1078, VIRTIO_SCSI, VMPVSCSI)

    def coerce(self, obj, attr, value):
        # Some compat for strings we'd see in the legacy
        # vmware_adaptertype image property
        value = value.lower()
        if value == "lsilogicsas":
            value = SCSIModel.LSISAS1068
        elif value == "paravirtual":
            value = SCSIModel.VMPVSCSI

        return super(SCSIModel, self).coerce(obj, attr, value)


class SecureBoot(BaseNovaEnum):

    REQUIRED = "required"
    DISABLED = "disabled"
    OPTIONAL = "optional"

    ALL = (REQUIRED, DISABLED, OPTIONAL)


class VideoModel(BaseNovaEnum):

    CIRRUS = "cirrus"
    QXL = "qxl"
    VGA = "vga"
    VMVGA = "vmvga"
    XEN = "xen"
    VIRTIO = 'virtio'
    GOP = 'gop'
    NONE = 'none'
    BOCHS = 'bochs'

    ALL = (CIRRUS, QXL, VGA, VMVGA, XEN, VIRTIO, GOP, NONE, BOCHS)


class VIFModel(BaseNovaEnum):

    LEGACY_VALUES = {"virtuale1000":
                     network_model.VIF_MODEL_E1000,
                     "virtuale1000e":
                     network_model.VIF_MODEL_E1000E,
                     "virtualpcnet32":
                     network_model.VIF_MODEL_PCNET,
                     "virtualsriovethernetcard":
                     network_model.VIF_MODEL_SRIOV,
                     "virtualvmxnet":
                     network_model.VIF_MODEL_VMXNET,
                     "virtualvmxnet3":
                     network_model.VIF_MODEL_VMXNET3,
                    }

    ALL = network_model.VIF_MODEL_ALL

    def coerce(self, obj, attr, value):
        # Some compat for strings we'd see in the legacy
        # hw_vif_model image property
        value = value.lower()
        value = VIFModel.LEGACY_VALUES.get(value, value)
        return super(VIFModel, self).coerce(obj, attr, value)


class VIOMMUModel(BaseNovaEnum):

    INTEL = 'intel'
    SMMUV3 = 'smmuv3'
    VIRTIO = 'virtio'
    AUTO = 'auto'

    ALL = (INTEL, SMMUV3, VIRTIO, AUTO)


class VMMode(BaseNovaEnum):
    """Represents possible vm modes for instances.

    Compute instance VM modes represent the host/guest ABI used for the
    virtual machine or container. Individual hypervisors may support
    multiple different vm modes per host. Available VM modes for a
    hypervisor driver may also vary according to the architecture it is
    running on.
    """
    HVM = 'hvm'  # Native ABI (aka fully virtualized)
    XEN = 'xen'  # Xen 3.0 paravirtualized
    UML = 'uml'  # User Mode Linux paravirtualized
    EXE = 'exe'  # Executables in containers

    ALL = (HVM, XEN, UML, EXE)

    def coerce(self, obj, attr, value):
        try:
            value = self.canonicalize(value)
        except exception.InvalidVirtualMachineMode:
            msg = _("Virtual machine mode '%s' is not valid") % value
            raise ValueError(msg)

        return super(VMMode, self).coerce(obj, attr, value)

    @classmethod
    def get_from_instance(cls, instance):
        """Get the vm mode for an instance

        :param instance: instance object to query

        :returns: canonicalized vm mode for the instance
        """
        mode = instance.vm_mode

        return cls.canonicalize(mode)

    @classmethod
    def is_valid(cls, name):
        """Check if a string is a valid vm mode

        :param name: vm mode name to validate

        :returns: True if @name is valid
        """
        return name in cls.ALL

    @classmethod
    def canonicalize(cls, mode):
        """Canonicalize the vm mode

        :param name: vm mode name to canonicalize

        :returns: a canonical vm mode name
        """
        if mode is None:
            return None

        mode = mode.lower()

        # For compatibility with pre-Folsom deployments
        if mode == 'pv':
            mode = cls.XEN

        if mode == 'hv':
            mode = cls.HVM

        if mode == 'baremetal':
            mode = cls.HVM

        if not cls.is_valid(mode):
            raise exception.InvalidVirtualMachineMode(vmmode=mode)

        return mode


class WatchdogAction(BaseNovaEnum):

    NONE = "none"
    PAUSE = "pause"
    POWEROFF = "poweroff"
    RESET = "reset"
    DISABLED = "disabled"

    ALL = (NONE, PAUSE, POWEROFF, RESET, DISABLED)


class MonitorMetricType(BaseNovaEnum):

    CPU_FREQUENCY = "cpu.frequency"
    CPU_USER_TIME = "cpu.user.time"
    CPU_KERNEL_TIME = "cpu.kernel.time"
    CPU_IDLE_TIME = "cpu.idle.time"
    CPU_IOWAIT_TIME = "cpu.iowait.time"
    CPU_USER_PERCENT = "cpu.user.percent"
    CPU_KERNEL_PERCENT = "cpu.kernel.percent"
    CPU_IDLE_PERCENT = "cpu.idle.percent"
    CPU_IOWAIT_PERCENT = "cpu.iowait.percent"
    CPU_PERCENT = "cpu.percent"
    NUMA_MEM_BW_MAX = "numa.membw.max"
    NUMA_MEM_BW_CURRENT = "numa.membw.current"

    ALL = (
        CPU_FREQUENCY,
        CPU_USER_TIME,
        CPU_KERNEL_TIME,
        CPU_IDLE_TIME,
        CPU_IOWAIT_TIME,
        CPU_USER_PERCENT,
        CPU_KERNEL_PERCENT,
        CPU_IDLE_PERCENT,
        CPU_IOWAIT_PERCENT,
        CPU_PERCENT,
        NUMA_MEM_BW_MAX,
        NUMA_MEM_BW_CURRENT,
    )


class HostStatus(BaseNovaEnum):

    UP = "UP"  # The nova-compute is up.
    DOWN = "DOWN"  # The nova-compute is forced_down.
    MAINTENANCE = "MAINTENANCE"  # The nova-compute is disabled.
    UNKNOWN = "UNKNOWN"  # The nova-compute has not reported.
    NONE = ""  # No host or nova-compute.

    ALL = (UP, DOWN, MAINTENANCE, UNKNOWN, NONE)


class PciDeviceStatus(BaseNovaEnum):

    AVAILABLE = "available"
    CLAIMED = "claimed"
    ALLOCATED = "allocated"
    REMOVED = "removed"  # The device has been hot-removed and not yet deleted
    DELETED = "deleted"  # The device is marked not available/deleted.
    UNCLAIMABLE = "unclaimable"
    UNAVAILABLE = "unavailable"

    ALL = (AVAILABLE, CLAIMED, ALLOCATED, REMOVED, DELETED, UNAVAILABLE,
           UNCLAIMABLE)


class PciDeviceType(BaseNovaEnum):

    # NOTE(jaypipes): It's silly that the word "type-" is in these constants,
    # but alas, these were the original constant strings used...
    STANDARD = "type-PCI"
    SRIOV_PF = "type-PF"
    SRIOV_VF = "type-VF"
    # NOTE(sean-k-mooney): The DB field is Column(String(8), nullable=False)
    # type-vdpa is 9 long...and as Jay notes above the prefix is silly so
    # for the new vdpa value we drop the prefix to avoid a DB migration
    VDPA = "vdpa"

    ALL = (STANDARD, SRIOV_PF, SRIOV_VF, VDPA)


class PCINUMAAffinityPolicy(BaseNovaEnum):

    REQUIRED = "required"
    LEGACY = "legacy"
    PREFERRED = "preferred"
    SOCKET = "socket"

    ALL = (REQUIRED, LEGACY, PREFERRED, SOCKET)


class DiskFormat(BaseNovaEnum):
    RBD = "rbd"
    LVM = "lvm"
    QCOW2 = "qcow2"
    RAW = "raw"
    PLOOP = "ploop"
    VHD = "vhd"
    VMDK = "vmdk"
    VDI = "vdi"
    ISO = "iso"

    ALL = (RBD, LVM, QCOW2, RAW, PLOOP, VHD, VMDK, VDI, ISO)


# TODO(stephenfin): Remove the xenapi value when we bump the 'Diagnostics'
# object (the only user of this enum) to 2.0
class HypervisorDriver(BaseNovaEnum):
    LIBVIRT = "libvirt"
    XENAPI = "xenapi"
    VMWAREAPI = "vmwareapi"
    IRONIC = "ironic"
    HYPERV = "hyperv"

    ALL = (LIBVIRT, XENAPI, VMWAREAPI, IRONIC, HYPERV)


class PointerModelType(BaseNovaEnum):

    USBTABLET = "usbtablet"

    ALL = (USBTABLET,)


class NotificationPriority(BaseNovaEnum):
    AUDIT = 'audit'
    CRITICAL = 'critical'
    DEBUG = 'debug'
    INFO = 'info'
    ERROR = 'error'
    SAMPLE = 'sample'
    WARN = 'warn'

    ALL = (AUDIT, CRITICAL, DEBUG, INFO, ERROR, SAMPLE, WARN)


class NotificationPhase(BaseNovaEnum):
    START = 'start'
    END = 'end'
    ERROR = 'error'
    PROGRESS = 'progress'

    ALL = (START, END, ERROR, PROGRESS)


class NotificationSource(BaseNovaEnum):
    """Represents possible nova binary service names in notification envelope.

    The publisher_id field of the nova notifications consists of the name of
    the host and the name of the service binary that emits the notification.
    The below values are the ones that is used in every notification. Please
    note that on the REST API the nova-api service binary is called
    nova-osapi_compute. This is not reflected here as notifications always used
    the name nova-api instead.
    """

    COMPUTE = 'nova-compute'
    API = 'nova-api'
    CONDUCTOR = 'nova-conductor'
    SCHEDULER = 'nova-scheduler'
    # TODO(stephenfin): Remove 'NETWORK' when 'NotificationPublisher' is
    # updated to version 3.0
    NETWORK = 'nova-network'
    # TODO(stephenfin): Remove 'CONSOLEAUTH' when 'NotificationPublisher' is
    # updated to version 3.0
    CONSOLEAUTH = 'nova-consoleauth'
    # TODO(stephenfin): Remove when 'NotificationPublisher' object version is
    # bumped to 3.0
    CELLS = 'nova-cells'
    # TODO(stephenfin): Remove when 'NotificationPublisher' object version is
    # bumped to 3.0
    CONSOLE = 'nova-console'
    METADATA = 'nova-metadata'

    ALL = (API, COMPUTE, CONDUCTOR, SCHEDULER,
           NETWORK, CONSOLEAUTH, CELLS, CONSOLE, METADATA)

    @staticmethod
    def get_source_by_binary(binary):
        # nova-osapi_compute binary name needs to be translated to nova-api
        # notification source enum value.
        return "nova-api" if binary == "nova-osapi_compute" else binary


class NotificationAction(BaseNovaEnum):
    UPDATE = 'update'
    EXCEPTION = 'exception'
    DELETE = 'delete'
    PAUSE = 'pause'
    UNPAUSE = 'unpause'
    RESIZE = 'resize'
    VOLUME_SWAP = 'volume_swap'
    SUSPEND = 'suspend'
    POWER_ON = 'power_on'
    POWER_OFF = 'power_off'
    REBOOT = 'reboot'
    SHUTDOWN = 'shutdown'
    SNAPSHOT = 'snapshot'
    INTERFACE_ATTACH = 'interface_attach'
    SHELVE = 'shelve'
    RESUME = 'resume'
    RESTORE = 'restore'
    EXISTS = 'exists'
    RESCUE = 'rescue'
    VOLUME_ATTACH = 'volume_attach'
    VOLUME_DETACH = 'volume_detach'
    CREATE = 'create'
    IMPORT = 'import'
    EVACUATE = 'evacuate'
    RESIZE_FINISH = 'resize_finish'
    LIVE_MIGRATION_ABORT = 'live_migration_abort'
    LIVE_MIGRATION_POST_DEST = 'live_migration_post_dest'
    LIVE_MIGRATION_POST = 'live_migration_post'
    LIVE_MIGRATION_PRE = 'live_migration_pre'
    LIVE_MIGRATION_ROLLBACK_DEST = 'live_migration_rollback_dest'
    LIVE_MIGRATION_ROLLBACK = 'live_migration_rollback'
    LIVE_MIGRATION_FORCE_COMPLETE = 'live_migration_force_complete'
    REBUILD = 'rebuild'
    REBUILD_SCHEDULED = 'rebuild_scheduled'
    INTERFACE_DETACH = 'interface_detach'
    RESIZE_CONFIRM = 'resize_confirm'
    RESIZE_PREP = 'resize_prep'
    RESIZE_REVERT = 'resize_revert'
    SELECT_DESTINATIONS = 'select_destinations'
    SHELVE_OFFLOAD = 'shelve_offload'
    SOFT_DELETE = 'soft_delete'
    TRIGGER_CRASH_DUMP = 'trigger_crash_dump'
    UNRESCUE = 'unrescue'
    UNSHELVE = 'unshelve'
    ADD_HOST = 'add_host'
    REMOVE_HOST = 'remove_host'
    ADD_MEMBER = 'add_member'
    UPDATE_METADATA = 'update_metadata'
    LOCK = 'lock'
    UNLOCK = 'unlock'
    UPDATE_PROP = 'update_prop'
    CONNECT = 'connect'
    USAGE = 'usage'
    BUILD_INSTANCES = 'build_instances'
    MIGRATE_SERVER = 'migrate_server'
    REBUILD_SERVER = 'rebuild_server'
    IMAGE_CACHE = 'cache_images'

    ALL = (UPDATE, EXCEPTION, DELETE, PAUSE, UNPAUSE, RESIZE, VOLUME_SWAP,
           SUSPEND, POWER_ON, REBOOT, SHUTDOWN, SNAPSHOT, INTERFACE_ATTACH,
           POWER_OFF, SHELVE, RESUME, RESTORE, EXISTS, RESCUE, VOLUME_ATTACH,
           VOLUME_DETACH, CREATE, IMPORT, EVACUATE, RESIZE_FINISH,
           LIVE_MIGRATION_ABORT, LIVE_MIGRATION_POST_DEST, LIVE_MIGRATION_POST,
           LIVE_MIGRATION_PRE, LIVE_MIGRATION_ROLLBACK,
           LIVE_MIGRATION_ROLLBACK_DEST, REBUILD, INTERFACE_DETACH,
           RESIZE_CONFIRM, RESIZE_PREP, RESIZE_REVERT, SHELVE_OFFLOAD,
           SOFT_DELETE, TRIGGER_CRASH_DUMP, UNRESCUE, UNSHELVE, ADD_HOST,
           REMOVE_HOST, ADD_MEMBER, UPDATE_METADATA, LOCK, UNLOCK,
           REBUILD_SCHEDULED, UPDATE_PROP, LIVE_MIGRATION_FORCE_COMPLETE,
           CONNECT, USAGE, BUILD_INSTANCES, MIGRATE_SERVER, REBUILD_SERVER,
           SELECT_DESTINATIONS, IMAGE_CACHE)


# TODO(rlrossit): These should be changed over to be a StateMachine enum from
# oslo.versionedobjects using the valid state transitions described in
# nova.compute.vm_states
class InstanceState(BaseNovaEnum):
    ACTIVE = 'active'
    BUILDING = 'building'
    PAUSED = 'paused'
    SUSPENDED = 'suspended'
    STOPPED = 'stopped'
    RESCUED = 'rescued'
    RESIZED = 'resized'
    SOFT_DELETED = 'soft-delete'
    DELETED = 'deleted'
    ERROR = 'error'
    SHELVED = 'shelved'
    SHELVED_OFFLOADED = 'shelved_offloaded'

    ALL = (ACTIVE, BUILDING, PAUSED, SUSPENDED, STOPPED, RESCUED, RESIZED,
           SOFT_DELETED, DELETED, ERROR, SHELVED, SHELVED_OFFLOADED)


# TODO(rlrossit): These should be changed over to be a StateMachine enum from
# oslo.versionedobjects using the valid state transitions described in
# nova.compute.task_states
class InstanceTaskState(BaseNovaEnum):
    SCHEDULING = 'scheduling'
    BLOCK_DEVICE_MAPPING = 'block_device_mapping'
    NETWORKING = 'networking'
    SPAWNING = 'spawning'
    IMAGE_SNAPSHOT = 'image_snapshot'
    IMAGE_SNAPSHOT_PENDING = 'image_snapshot_pending'
    IMAGE_PENDING_UPLOAD = 'image_pending_upload'
    IMAGE_UPLOADING = 'image_uploading'
    IMAGE_BACKUP = 'image_backup'
    UPDATING_PASSWORD = 'updating_password'
    RESIZE_PREP = 'resize_prep'
    RESIZE_MIGRATING = 'resize_migrating'
    RESIZE_MIGRATED = 'resize_migrated'
    RESIZE_FINISH = 'resize_finish'
    RESIZE_REVERTING = 'resize_reverting'
    RESIZE_CONFIRMING = 'resize_confirming'
    REBOOTING = 'rebooting'
    REBOOT_PENDING = 'reboot_pending'
    REBOOT_STARTED = 'reboot_started'
    REBOOTING_HARD = 'rebooting_hard'
    REBOOT_PENDING_HARD = 'reboot_pending_hard'
    REBOOT_STARTED_HARD = 'reboot_started_hard'
    PAUSING = 'pausing'
    UNPAUSING = 'unpausing'
    SUSPENDING = 'suspending'
    RESUMING = 'resuming'
    POWERING_OFF = 'powering-off'
    POWERING_ON = 'powering-on'
    RESCUING = 'rescuing'
    UNRESCUING = 'unrescuing'
    REBUILDING = 'rebuilding'
    REBUILD_BLOCK_DEVICE_MAPPING = "rebuild_block_device_mapping"
    REBUILD_SPAWNING = 'rebuild_spawning'
    MIGRATING = "migrating"
    DELETING = 'deleting'
    SOFT_DELETING = 'soft-deleting'
    RESTORING = 'restoring'
    SHELVING = 'shelving'
    SHELVING_IMAGE_PENDING_UPLOAD = 'shelving_image_pending_upload'
    SHELVING_IMAGE_UPLOADING = 'shelving_image_uploading'
    SHELVING_OFFLOADING = 'shelving_offloading'
    UNSHELVING = 'unshelving'

    ALL = (SCHEDULING, BLOCK_DEVICE_MAPPING, NETWORKING, SPAWNING,
           IMAGE_SNAPSHOT, IMAGE_SNAPSHOT_PENDING, IMAGE_PENDING_UPLOAD,
           IMAGE_UPLOADING, IMAGE_BACKUP, UPDATING_PASSWORD, RESIZE_PREP,
           RESIZE_MIGRATING, RESIZE_MIGRATED, RESIZE_FINISH, RESIZE_REVERTING,
           RESIZE_CONFIRMING, REBOOTING, REBOOT_PENDING, REBOOT_STARTED,
           REBOOTING_HARD, REBOOT_PENDING_HARD, REBOOT_STARTED_HARD, PAUSING,
           UNPAUSING, SUSPENDING, RESUMING, POWERING_OFF, POWERING_ON,
           RESCUING, UNRESCUING, REBUILDING, REBUILD_BLOCK_DEVICE_MAPPING,
           REBUILD_SPAWNING, MIGRATING, DELETING, SOFT_DELETING, RESTORING,
           SHELVING, SHELVING_IMAGE_PENDING_UPLOAD, SHELVING_IMAGE_UPLOADING,
           SHELVING_OFFLOADING, UNSHELVING)


class InstancePowerState(Enum):
    _UNUSED = '_unused'
    NOSTATE = 'pending'
    RUNNING = 'running'
    PAUSED = 'paused'
    SHUTDOWN = 'shutdown'
    CRASHED = 'crashed'
    SUSPENDED = 'suspended'
    # The order is important here. If you make changes, only *append*
    # values to the end of the list.
    ALL = (
        NOSTATE,
        RUNNING,
        _UNUSED,
        PAUSED,
        SHUTDOWN,
        _UNUSED,
        CRASHED,
        SUSPENDED,
    )

    def __init__(self):
        super(InstancePowerState, self).__init__(
            valid_values=InstancePowerState.ALL)

    def coerce(self, obj, attr, value):
        try:
            value = int(value)
            value = self.from_index(value)
        except (ValueError, KeyError):
            pass
        return super(InstancePowerState, self).coerce(obj, attr, value)

    @classmethod
    def index(cls, value):
        """Return an index into the Enum given a value."""
        return cls.ALL.index(value)

    @classmethod
    def from_index(cls, index):
        """Return the Enum value at a given index."""
        return cls.ALL[index]


class NetworkModel(FieldType):
    @staticmethod
    def coerce(obj, attr, value):
        if isinstance(value, network_model.NetworkInfo):
            return value
        elif isinstance(value, str):
            # Hmm, do we need this?
            return network_model.NetworkInfo.hydrate(value)
        else:
            raise ValueError(_('A NetworkModel is required in field %s') %
                             attr)

    @staticmethod
    def to_primitive(obj, attr, value):
        return value.json()

    @staticmethod
    def from_primitive(obj, attr, value):
        return network_model.NetworkInfo.hydrate(value)

    def stringify(self, value):
        return 'NetworkModel(%s)' % (
            ','.join([str(vif['id']) for vif in value]))

    def get_schema(self):
        return {'type': ['string']}


class NetworkVIFModel(FieldType):
    """Represents a nova.network.model.VIF object, which is a dict of stuff."""

    @staticmethod
    def coerce(obj, attr, value):
        if isinstance(value, network_model.VIF):
            return value
        elif isinstance(value, str):
            return NetworkVIFModel.from_primitive(obj, attr, value)
        else:
            raise ValueError(_('A nova.network.model.VIF object is required '
                               'in field %s') % attr)

    @staticmethod
    def to_primitive(obj, attr, value):
        return jsonutils.dumps(value)

    @staticmethod
    def from_primitive(obj, attr, value):
        return network_model.VIF.hydrate(jsonutils.loads(value))

    def get_schema(self):
        return {'type': ['string']}


class AddressBase(FieldType):
    @staticmethod
    def coerce(obj, attr, value):
        if re.match(obj.PATTERN, str(value)):
            return str(value)
        else:
            raise ValueError(_('Value must match %s') % obj.PATTERN)

    def get_schema(self):
        return {'type': ['string'], 'pattern': self.PATTERN}


class USBAddress(AddressBase):
    PATTERN = '[a-f0-9]+:[a-f0-9]+'

    @staticmethod
    def coerce(obj, attr, value):
        return AddressBase.coerce(USBAddress, attr, value)


class SCSIAddress(AddressBase):
    PATTERN = '[a-f0-9]+:[a-f0-9]+:[a-f0-9]+:[a-f0-9]+'

    @staticmethod
    def coerce(obj, attr, value):
        return AddressBase.coerce(SCSIAddress, attr, value)


class IDEAddress(AddressBase):
    PATTERN = '[0-1]:[0-1]'

    @staticmethod
    def coerce(obj, attr, value):
        return AddressBase.coerce(IDEAddress, attr, value)


class XenAddress(AddressBase):
    PATTERN = '(00[0-9]{2}00)|[1-9][0-9]+'

    @staticmethod
    def coerce(obj, attr, value):
        return AddressBase.coerce(XenAddress, attr, value)


class USBAddressField(AutoTypedField):
    AUTO_TYPE = USBAddress()


class SCSIAddressField(AutoTypedField):
    AUTO_TYPE = SCSIAddress()


class IDEAddressField(AutoTypedField):
    AUTO_TYPE = IDEAddress()


class XenAddressField(AutoTypedField):
    AUTO_TYPE = XenAddress()


class ArchitectureField(BaseEnumField):
    AUTO_TYPE = Architecture()


class BlockDeviceDestinationTypeField(BaseEnumField):
    AUTO_TYPE = BlockDeviceDestinationType()


class BlockDeviceSourceTypeField(BaseEnumField):
    AUTO_TYPE = BlockDeviceSourceType()


class BlockDeviceTypeField(BaseEnumField):
    AUTO_TYPE = BlockDeviceType()


class BlockDeviceEncryptionFormatTypeField(BaseEnumField):
    AUTO_TYPE = BlockDeviceEncryptionFormatType()


class ConfigDrivePolicyField(BaseEnumField):
    AUTO_TYPE = ConfigDrivePolicy()


class CPUAllocationPolicyField(BaseEnumField):
    AUTO_TYPE = CPUAllocationPolicy()


class CPUThreadAllocationPolicyField(BaseEnumField):
    AUTO_TYPE = CPUThreadAllocationPolicy()


class CPUEmulatorThreadsPolicyField(BaseEnumField):
    AUTO_TYPE = CPUEmulatorThreadsPolicy()


class CPUModeField(BaseEnumField):
    AUTO_TYPE = CPUMode()


class CPUMatchField(BaseEnumField):
    AUTO_TYPE = CPUMatch()


class CPUFeaturePolicyField(BaseEnumField):
    AUTO_TYPE = CPUFeaturePolicy()


class DiskBusField(BaseEnumField):
    AUTO_TYPE = DiskBus()


class DiskConfigField(BaseEnumField):
    AUTO_TYPE = DiskConfig()


class FirmwareTypeField(BaseEnumField):
    AUTO_TYPE = FirmwareType()


class HVTypeField(BaseEnumField):
    AUTO_TYPE = HVType()


class ImageSignatureHashTypeField(BaseEnumField):
    AUTO_TYPE = ImageSignatureHashType()


class ImageSignatureKeyTypeField(BaseEnumField):
    AUTO_TYPE = ImageSignatureKeyType()


class InputBusField(BaseEnumField):
    AUTO_TYPE = InputBus()


class MigrationTypeField(BaseEnumField):
    AUTO_TYPE = MigrationType()


class OSTypeField(BaseEnumField):
    AUTO_TYPE = OSType()


class RNGModelField(BaseEnumField):
    AUTO_TYPE = RNGModel()


class TPMModelField(BaseEnumField):
    AUTO_TYPE = TPMModel()


class TPMVersionField(BaseEnumField):
    AUTO_TYPE = TPMVersion()


class SCSIModelField(BaseEnumField):
    AUTO_TYPE = SCSIModel()


class SecureBootField(BaseEnumField):
    AUTO_TYPE = SecureBoot()


class VideoModelField(BaseEnumField):
    AUTO_TYPE = VideoModel()


class VIFModelField(BaseEnumField):
    AUTO_TYPE = VIFModel()


class VIOMMUModelField(BaseEnumField):
    AUTO_TYPE = VIOMMUModel()


class VMModeField(BaseEnumField):
    AUTO_TYPE = VMMode()


class WatchdogActionField(BaseEnumField):
    AUTO_TYPE = WatchdogAction()


class MonitorMetricTypeField(BaseEnumField):
    AUTO_TYPE = MonitorMetricType()


class PciDeviceStatusField(BaseEnumField):
    AUTO_TYPE = PciDeviceStatus()


class PciDeviceTypeField(BaseEnumField):
    AUTO_TYPE = PciDeviceType()


class PCINUMAAffinityPolicyField(BaseEnumField):
    AUTO_TYPE = PCINUMAAffinityPolicy()


class DiskFormatField(BaseEnumField):
    AUTO_TYPE = DiskFormat()


class HypervisorDriverField(BaseEnumField):
    AUTO_TYPE = HypervisorDriver()


class PointerModelField(BaseEnumField):
    AUTO_TYPE = PointerModelType()


class NotificationPriorityField(BaseEnumField):
    AUTO_TYPE = NotificationPriority()


class NotificationPhaseField(BaseEnumField):
    AUTO_TYPE = NotificationPhase()


class NotificationActionField(BaseEnumField):
    AUTO_TYPE = NotificationAction()


class NotificationSourceField(BaseEnumField):
    AUTO_TYPE = NotificationSource()


class InstanceStateField(BaseEnumField):
    AUTO_TYPE = InstanceState()


class InstanceTaskStateField(BaseEnumField):
    AUTO_TYPE = InstanceTaskState()


class InstancePowerStateField(BaseEnumField):
    AUTO_TYPE = InstancePowerState()


class NetworkModelField(AutoTypedField):
    AUTO_TYPE = NetworkModel()


class NetworkVIFModelField(AutoTypedField):
    AUTO_TYPE = NetworkVIFModel()


class ListOfListsOfStringsField(AutoTypedField):
    AUTO_TYPE = List(List(fields.String()))


class DictOfSetOfIntegersField(AutoTypedField):
    AUTO_TYPE = Dict(Set(fields.Integer()))