Skip to content

Commit

Permalink
[fix][azure] Map properties of base classes (#1774)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias committed Sep 15, 2023
1 parent 60ea3b2 commit 02e9905
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
47 changes: 21 additions & 26 deletions plugins/azure/resoto_plugin_azure/resource/compute.py
Expand Up @@ -967,33 +967,28 @@ class AzureGallery(AzureResource):
soft_delete_policy: Optional[bool] = field(default=None, metadata={'description': 'Contains information about the soft deletion policy of the gallery.'}) # fmt: skip


@define(eq=False, slots=False)
class AzureSubResource:
kind: ClassVar[str] = "azure_sub_resource"
mapping: ClassVar[Dict[str, Bender]] = {"id": S("id")}
id: Optional[str] = field(default=None, metadata={"description": "Resource id."})


@define(eq=False, slots=False)
class AzureDiskEncryptionSetParameters(AzureSubResource):
kind: ClassVar[str] = "azure_disk_encryption_set_parameters"
mapping: ClassVar[Dict[str, Bender]] = {}


@define(eq=False, slots=False)
class AzureImageDisk:
kind: ClassVar[str] = "azure_image_disk"
mapping: ClassVar[Dict[str, Bender]] = {
"blob_uri": S("blobUri"),
"caching": S("caching"),
"disk_encryption_set": S("diskEncryptionSet") >> Bend(AzureDiskEncryptionSetParameters.mapping),
"disk_encryption_set": S("diskEncryptionSet") >> Bend(AzureSubResource.mapping),
"disk_size_gb": S("diskSizeGB"),
"managed_disk": S("managedDisk", "id"),
"snapshot": S("snapshot", "id"),
"storage_account_type": S("storageAccountType"),
}
blob_uri: Optional[str] = field(default=None, metadata={"description": "The virtual hard disk."})
caching: Optional[str] = field(default=None, metadata={'description': 'Specifies the caching requirements. Possible values are: **none,** **readonly,** **readwrite. ** the default values are: **none for standard storage. Readonly for premium storage. **.'}) # fmt: skip
disk_encryption_set: Optional[AzureDiskEncryptionSetParameters] = field(default=None, metadata={'description': 'Describes the parameter of customer managed disk encryption set resource id that can be specified for disk. **note:** the disk encryption set resource id can only be specified for managed disk. Please refer https://aka. Ms/mdssewithcmkoverview for more details.'}) # fmt: skip
disk_encryption_set: Optional[AzureSubResource] = field(default=None, metadata={'description': 'Describes the parameter of customer managed disk encryption set resource id that can be specified for disk. **note:** the disk encryption set resource id can only be specified for managed disk. Please refer https://aka. Ms/mdssewithcmkoverview for more details.'}) # fmt: skip
disk_size_gb: Optional[int] = field(default=None, metadata={'description': 'Specifies the size of empty data disks in gigabytes. This element can be used to overwrite the name of the disk in a virtual machine image. This value cannot be larger than 1023 gb.'}) # fmt: skip
managed_disk: Optional[str] = field(default=None, metadata={"description": ""})
snapshot: Optional[str] = field(default=None, metadata={"description": ""})
Expand All @@ -1003,7 +998,7 @@ class AzureImageDisk:
@define(eq=False, slots=False)
class AzureImageOSDisk(AzureImageDisk):
kind: ClassVar[str] = "azure_image_os_disk"
mapping: ClassVar[Dict[str, Bender]] = {"os_state": S("osState"), "os_type": S("osType")}
mapping: ClassVar[Dict[str, Bender]] = AzureImageDisk.mapping | {"os_state": S("osState"), "os_type": S("osType")}
os_state: Optional[str] = field(default=None, metadata={'description': 'The os state. For managed images, use generalized.'}) # fmt: skip
os_type: Optional[str] = field(default=None, metadata={'description': 'This property allows you to specify the type of the os that is included in the disk if creating a vm from a custom image. Possible values are: **windows,** **linux. **.'}) # fmt: skip

Expand Down Expand Up @@ -1056,7 +1051,7 @@ class AzureImage(AzureResource):
@define(eq=False, slots=False)
class AzureSubResourceWithColocationStatus(AzureSubResource):
kind: ClassVar[str] = "azure_sub_resource_with_colocation_status"
mapping: ClassVar[Dict[str, Bender]] = {
mapping: ClassVar[Dict[str, Bender]] = AzureSubResource.mapping | {
"colocation_status": S("colocationStatus") >> Bend(AzureInstanceViewStatus.mapping)
}
colocation_status: Optional[AzureInstanceViewStatus] = field(default=None, metadata={'description': 'Instance view status.'}) # fmt: skip
Expand Down Expand Up @@ -1313,22 +1308,22 @@ class AzureDiskEncryptionSettings:
class AzureVMDiskSecurityProfile:
kind: ClassVar[str] = "azure_vm_disk_security_profile"
mapping: ClassVar[Dict[str, Bender]] = {
"disk_encryption_set": S("diskEncryptionSet") >> Bend(AzureDiskEncryptionSetParameters.mapping),
"disk_encryption_set": S("diskEncryptionSet") >> Bend(AzureSubResource.mapping),
"security_encryption_type": S("securityEncryptionType"),
}
disk_encryption_set: Optional[AzureDiskEncryptionSetParameters] = field(default=None, metadata={'description': 'Describes the parameter of customer managed disk encryption set resource id that can be specified for disk. **note:** the disk encryption set resource id can only be specified for managed disk. Please refer https://aka. Ms/mdssewithcmkoverview for more details.'}) # fmt: skip
disk_encryption_set: Optional[AzureSubResource] = field(default=None, metadata={'description': 'Describes the parameter of customer managed disk encryption set resource id that can be specified for disk. **note:** the disk encryption set resource id can only be specified for managed disk. Please refer https://aka. Ms/mdssewithcmkoverview for more details.'}) # fmt: skip
security_encryption_type: Optional[str] = field(default=None, metadata={'description': 'Specifies the encryptiontype of the managed disk. It is set to diskwithvmgueststate for encryption of the managed disk along with vmgueststate blob, and vmgueststateonly for encryption of just the vmgueststate blob. **note:** it can be set for only confidential vms.'}) # fmt: skip


@define(eq=False, slots=False)
class AzureManagedDiskParameters(AzureSubResource):
kind: ClassVar[str] = "azure_managed_disk_parameters"
mapping: ClassVar[Dict[str, Bender]] = {
"disk_encryption_set": S("diskEncryptionSet") >> Bend(AzureDiskEncryptionSetParameters.mapping),
mapping: ClassVar[Dict[str, Bender]] = AzureSubResource.mapping | {
"disk_encryption_set": S("diskEncryptionSet") >> Bend(AzureSubResource.mapping),
"disk_parameters_security_profile": S("securityProfile") >> Bend(AzureVMDiskSecurityProfile.mapping),
"storage_account_type": S("storageAccountType"),
}
disk_encryption_set: Optional[AzureDiskEncryptionSetParameters] = field(default=None, metadata={'description': 'Describes the parameter of customer managed disk encryption set resource id that can be specified for disk. **note:** the disk encryption set resource id can only be specified for managed disk. Please refer https://aka. Ms/mdssewithcmkoverview for more details.'}) # fmt: skip
disk_encryption_set: Optional[AzureSubResource] = field(default=None, metadata={'description': 'Describes the parameter of customer managed disk encryption set resource id that can be specified for disk. **note:** the disk encryption set resource id can only be specified for managed disk. Please refer https://aka. Ms/mdssewithcmkoverview for more details.'}) # fmt: skip
disk_parameters_security_profile: Optional[AzureVMDiskSecurityProfile] = field(default=None, metadata={'description': 'Specifies the security profile settings for the managed disk. **note:** it can only be set for confidential vms.'}) # fmt: skip
storage_account_type: Optional[str] = field(default=None, metadata={'description': 'Specifies the storage account type for the managed disk. Managed os disk storage account type can only be set when you create the scale set. Note: ultrassd_lrs can only be used with data disks. It cannot be used with os disk. Standard_lrs uses standard hdd. Standardssd_lrs uses standard ssd. Premium_lrs uses premium ssd. Ultrassd_lrs uses ultra disk. Premium_zrs uses premium ssd zone redundant storage. Standardssd_zrs uses standard ssd zone redundant storage. For more information regarding disks supported for windows virtual machines, refer to https://docs. Microsoft. Com/azure/virtual-machines/windows/disks-types and, for linux virtual machines, refer to https://docs. Microsoft. Com/azure/virtual-machines/linux/disks-types.'}) # fmt: skip

Expand All @@ -1344,17 +1339,17 @@ class AzureSubResourceReadOnly:
class AzureRestorePointEncryption:
kind: ClassVar[str] = "azure_restore_point_encryption"
mapping: ClassVar[Dict[str, Bender]] = {
"disk_encryption_set": S("diskEncryptionSet") >> Bend(AzureDiskEncryptionSetParameters.mapping),
"disk_encryption_set": S("diskEncryptionSet") >> Bend(AzureSubResource.mapping),
"type": S("type"),
}
disk_encryption_set: Optional[AzureDiskEncryptionSetParameters] = field(default=None, metadata={'description': 'Describes the parameter of customer managed disk encryption set resource id that can be specified for disk. **note:** the disk encryption set resource id can only be specified for managed disk. Please refer https://aka. Ms/mdssewithcmkoverview for more details.'}) # fmt: skip
disk_encryption_set: Optional[AzureSubResource] = field(default=None, metadata={'description': 'Describes the parameter of customer managed disk encryption set resource id that can be specified for disk. **note:** the disk encryption set resource id can only be specified for managed disk. Please refer https://aka. Ms/mdssewithcmkoverview for more details.'}) # fmt: skip
type: Optional[str] = field(default=None, metadata={'description': 'The type of key used to encrypt the data of the disk restore point.'}) # fmt: skip


@define(eq=False, slots=False)
class AzureDiskRestorePointAttributes(AzureSubResourceReadOnly):
kind: ClassVar[str] = "azure_disk_restore_point_attributes"
mapping: ClassVar[Dict[str, Bender]] = {
mapping: ClassVar[Dict[str, Bender]] = AzureSubResourceReadOnly.mapping | {
"encryption": S("encryption") >> Bend(AzureRestorePointEncryption.mapping),
"source_disk_restore_point": S("sourceDiskRestorePoint", "id"),
}
Expand Down Expand Up @@ -1704,7 +1699,7 @@ class AzureRestorePointInstanceView:
@define(eq=False, slots=False)
class AzureRestorePoint(AzureProxyResource):
kind: ClassVar[str] = "azure_restore_point"
mapping: ClassVar[Dict[str, Bender]] = {
mapping: ClassVar[Dict[str, Bender]] = AzureProxyResource.mapping | {
"consistency_mode": S("properties", "consistencyMode"),
"exclude_disks": S("properties") >> S("excludeDisks", default=[]) >> ForallBend(S("id")),
"restore_point_instance_view": S("properties", "instanceView") >> Bend(AzureRestorePointInstanceView.mapping),
Expand Down Expand Up @@ -1890,7 +1885,7 @@ class AzurePlan:
@define(eq=False, slots=False)
class AzureImageReference(AzureSubResource):
kind: ClassVar[str] = "azure_image_reference"
mapping: ClassVar[Dict[str, Bender]] = {
mapping: ClassVar[Dict[str, Bender]] = AzureSubResource.mapping | {
"community_gallery_image_id": S("communityGalleryImageId"),
"exact_version": S("exactVersion"),
"offer": S("offer"),
Expand Down Expand Up @@ -2011,7 +2006,7 @@ class AzureAdditionalCapabilities:
@define(eq=False, slots=False)
class AzureNetworkInterfaceReference(AzureSubResource):
kind: ClassVar[str] = "azure_network_interface_reference"
mapping: ClassVar[Dict[str, Bender]] = {
mapping: ClassVar[Dict[str, Bender]] = AzureSubResource.mapping | {
"delete_option": S("properties", "deleteOption"),
"primary": S("properties", "primary"),
}
Expand Down Expand Up @@ -2674,11 +2669,11 @@ class AzureVirtualMachineScaleSetOSProfile:
class AzureVirtualMachineScaleSetManagedDiskParameters:
kind: ClassVar[str] = "azure_virtual_machine_scale_set_managed_disk_parameters"
mapping: ClassVar[Dict[str, Bender]] = {
"disk_encryption_set": S("diskEncryptionSet") >> Bend(AzureDiskEncryptionSetParameters.mapping),
"disk_encryption_set": S("diskEncryptionSet") >> Bend(AzureSubResource.mapping),
"security_profile": S("securityProfile") >> Bend(AzureVMDiskSecurityProfile.mapping),
"storage_account_type": S("storageAccountType"),
}
disk_encryption_set: Optional[AzureDiskEncryptionSetParameters] = field(default=None, metadata={'description': 'Describes the parameter of customer managed disk encryption set resource id that can be specified for disk. **note:** the disk encryption set resource id can only be specified for managed disk. Please refer https://aka. Ms/mdssewithcmkoverview for more details.'}) # fmt: skip
disk_encryption_set: Optional[AzureSubResource] = field(default=None, metadata={'description': 'Describes the parameter of customer managed disk encryption set resource id that can be specified for disk. **note:** the disk encryption set resource id can only be specified for managed disk. Please refer https://aka. Ms/mdssewithcmkoverview for more details.'}) # fmt: skip
security_profile: Optional[AzureVMDiskSecurityProfile] = field(default=None, metadata={'description': 'Specifies the security profile settings for the managed disk. **note:** it can only be set for confidential vms.'}) # fmt: skip
storage_account_type: Optional[str] = field(default=None, metadata={'description': 'Specifies the storage account type for the managed disk. Managed os disk storage account type can only be set when you create the scale set. Note: ultrassd_lrs can only be used with data disks. It cannot be used with os disk. Standard_lrs uses standard hdd. Standardssd_lrs uses standard ssd. Premium_lrs uses premium ssd. Ultrassd_lrs uses ultra disk. Premium_zrs uses premium ssd zone redundant storage. Standardssd_zrs uses standard ssd zone redundant storage. For more information regarding disks supported for windows virtual machines, refer to https://docs. Microsoft. Com/azure/virtual-machines/windows/disks-types and, for linux virtual machines, refer to https://docs. Microsoft. Com/azure/virtual-machines/linux/disks-types.'}) # fmt: skip

Expand Down Expand Up @@ -2874,7 +2869,7 @@ class AzureVirtualMachineScaleSetNetworkProfile:
@define(eq=False, slots=False)
class AzureVirtualMachineScaleSetExtension(AzureSubResourceReadOnly):
kind: ClassVar[str] = "azure_virtual_machine_scale_set_extension"
mapping: ClassVar[Dict[str, Bender]] = {
mapping: ClassVar[Dict[str, Bender]] = AzureSubResourceReadOnly.mapping | {
"auto_upgrade_minor_version": S("properties", "autoUpgradeMinorVersion"),
"enable_automatic_upgrade": S("properties", "enableAutomaticUpgrade"),
"force_update_tag": S("properties", "forceUpdateTag"),
Expand Down Expand Up @@ -3043,7 +3038,7 @@ class AzureVirtualMachineScaleSet(AzureResource, BaseAutoScalingGroup):
"automatic_repairs_policy": S("properties", "automaticRepairsPolicy")
>> Bend(AzureAutomaticRepairsPolicy.mapping),
"constrained_maximum_capacity": S("properties", "constrainedMaximumCapacity"),
"do_not_run_extensions_on_overprovisioned_v_ms": S("properties", "doNotRunExtensionsOnOverprovisionedVMs"),
"do_not_run_extensions_on_overprovisioned_vm_s": S("properties", "doNotRunExtensionsOnOverprovisionedVMs"),
"extended_location": S("extendedLocation") >> Bend(AzureExtendedLocation.mapping),
"host_group": S("properties", "hostGroup", "id"),
"scale_set_identity": S("identity") >> Bend(AzureVirtualMachineScaleSetIdentity.mapping),
Expand All @@ -3068,7 +3063,7 @@ class AzureVirtualMachineScaleSet(AzureResource, BaseAutoScalingGroup):
scale_set_capabilities: Optional[AzureAdditionalCapabilities] = field(default=None, metadata={'description': 'Enables or disables a capability on the virtual machine or virtual machine scale set.'}) # fmt: skip
automatic_repairs_policy: Optional[AzureAutomaticRepairsPolicy] = field(default=None, metadata={'description': 'Specifies the configuration parameters for automatic repairs on the virtual machine scale set.'}) # fmt: skip
constrained_maximum_capacity: Optional[bool] = field(default=None, metadata={'description': 'Optional property which must either be set to true or omitted.'}) # fmt: skip
do_not_run_extensions_on_overprovisioned_v_ms: Optional[bool] = field(default=None, metadata={'description': 'When overprovision is enabled, extensions are launched only on the requested number of vms which are finally kept. This property will hence ensure that the extensions do not run on the extra overprovisioned vms.'}) # fmt: skip
do_not_run_extensions_on_overprovisioned_vm_s: Optional[bool] = field(default=None, metadata={'description': 'When overprovision is enabled, extensions are launched only on the requested number of vms which are finally kept. This property will hence ensure that the extensions do not run on the extra overprovisioned vms.'}) # fmt: skip
extended_location: Optional[AzureExtendedLocation] = field(default=None, metadata={'description': 'The complex type of the extended location.'}) # fmt: skip
host_group: Optional[str] = field(default=None, metadata={"description": ""})
scale_set_identity: Optional[AzureVirtualMachineScaleSetIdentity] = field(default=None, metadata={'description': 'Identity for the virtual machine scale set.'}) # fmt: skip
Expand Down
9 changes: 6 additions & 3 deletions plugins/azure/tools/azure_model_gen.py
Expand Up @@ -14,8 +14,6 @@

Json = Dict[str, Any]

Debug = False


def to_snake(name: str) -> str:
name = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", name)
Expand Down Expand Up @@ -154,7 +152,10 @@ def to_class(self) -> str:
base_mappings[bp] = "K(None)"
base_mappings["tags"] = "S('tags', default={})"

mapping = " mapping: ClassVar[Dict[str, Bender]] = {\n"
# take class hierarchy into account and assemble the mappings
bmp = " | ".join(f"Azure{base}.mapping" for base in self.base_classes if base != "AzureResource")
bmp = f"{bmp} | " if bmp else ""
mapping = f" mapping: ClassVar[Dict[str, Bender]] = {bmp} {{\n"
if self.aggregate_root:
mapping += ",\n".join(f' "{k}": {v}' for k, v in base_mappings.items())
mapping += ",\n"
Expand Down Expand Up @@ -582,6 +583,8 @@ def safe_idx(seq, index):

# endregion

# To run this script, make sure you have resoto venv plus: pip install "prance[osv,cli]"
Debug = False
if __name__ == "__main__":
specs_path = os.environ.get("AZURE_REST_API_SPECS", "../../../../azure-rest-api-specs")
assert specs_path, (
Expand Down

0 comments on commit 02e9905

Please sign in to comment.