From 17a24b799916296407bfea15b840daa08db35b7e Mon Sep 17 00:00:00 2001 From: Anja Strunk Date: Thu, 21 Dec 2023 15:05:52 +0100 Subject: [PATCH] Support additional attributes Signed-off-by: Anja Strunk --- generator/common/gx_schema.py | 14 +++-- .../openstack/vm_images_discovery.py | 61 ++++++++++++++++++- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/generator/common/gx_schema.py b/generator/common/gx_schema.py index 57a648a..99d6757 100644 --- a/generator/common/gx_schema.py +++ b/generator/common/gx_schema.py @@ -1,5 +1,5 @@ # Auto generated from gaia-x.yaml by pythongen.py version: 0.0.1 -# Generation date: 2023-12-19T11:59:13 +# Generation date: 2023-12-20T13:27:56 # Schema: gaia-x # # id: http://w3id.org/gaia-x/gx-trust-framework/gaia-x @@ -4262,14 +4262,18 @@ def _addvals(cls): PermissibleValue( text="sha-1", description="TBD")) - setattr(cls, "ripemd-160", + setattr(cls, "sha-2", PermissibleValue( - text="ripemd-160", + text="sha-2", description="TBD")) setattr(cls, "sha-3", PermissibleValue( text="sha-3", description="TBD")) + setattr(cls, "ripemd-160", + PermissibleValue( + text="ripemd-160", + description="TBD")) class KeyManagement(EnumDefinitionImpl): @@ -5378,7 +5382,7 @@ def _addvals(cls): class OSDistribution(EnumDefinitionImpl): """ - Possible values for operationg system distribution. + Possible values for operating system distribution. """ Debian = PermissibleValue(text="Debian") Fedora = PermissibleValue(text="Fedora") @@ -5395,7 +5399,7 @@ class OSDistribution(EnumDefinitionImpl): _defn = EnumDefinition( name="OSDistribution", - description="Possible values for operationg system distribution.", + description="Possible values for operating system distribution.", ) @classmethod diff --git a/generator/discovery/openstack/vm_images_discovery.py b/generator/discovery/openstack/vm_images_discovery.py index 14e641f..95b88da 100644 --- a/generator/discovery/openstack/vm_images_discovery.py +++ b/generator/discovery/openstack/vm_images_discovery.py @@ -7,6 +7,9 @@ from generator.common.gx_schema import MemorySize from generator.common.gx_schema import OperatingSystem from generator.common.gx_schema import UpdateStrategy +from generator.common.gx_schema import CheckSum +from generator.common.gx_schema import ChecksumAlgorithm + from generator.common.gx_schema import UpdateFrequency from generator.common.gx_schema import VMImage as GX_Image @@ -70,6 +73,9 @@ def _convert_to_gx_image(self, os_image: OS_Image) -> GX_Image: self._add_operation_system_info(os_image, gx_image) self._add_build_date(os_image, gx_image) self._add_license_included(os_image, gx_image) + self._add_patch_level(os_image, gx_image) + self._add_version(os_image, gx_image) + self._add_checksum(os_image, gx_image) # Discover mandatory attribute self._add_license(os_image, gx_image) @@ -357,7 +363,60 @@ def _add_license_included(os_image: OS_Image, gx_image: GX_Image) -> None: try: gx_image.licenseIncluded = os_image.properties['licenseIncluded'] except KeyError: - gx_image.licenseIncluded = False + pass + + @staticmethod + def _add_patch_level(os_image: OS_Image, gx_image: GX_Image) -> None: + try: + gx_image.patchLevel = os_image.properties['patchlevel'] + except KeyError: + pass + + @staticmethod + def _add_version(os_image: OS_Image, gx_image: GX_Image) -> None: + try: + gx_image.version = os_image.properties['internal_version'] + except KeyError: + pass + + @staticmethod + def _add_checksum(os_image: OS_Image, gx_image: GX_Image) -> None: + try: + algo = VmDiscovery._get_algo(os_image.hash_algo) + value = os_image.hash_value + gx_image.checksum = CheckSum(checkSum=value, checkSumCalculation=algo) + except AttributeError: + pass + + @staticmethod + def _get_algo(algo: str) -> str: + if algo in ['sha512', 'sha224', 'sha256' 'sha384']: + return 'sha-2' + if algo in ['sha-3', 'md5', 'ripemd-160', 'blake2', 'blake3']: + return algo + return ChecksumAlgorithm.other + + + @staticmethod + def _add_maintenance_until(os_image: OS_Image, gx_image: GX_Image) -> None: + try: + gx_image.maintenance = os_image.properties['maintained_until'] + except KeyError: + pass + + @staticmethod + def _add_file_size(os_image: OS_Image, gx_image: GX_Image) -> None: + gx_image.file = MemorySize(value=float(os_image.size * 1.073741824), unit=const.UNIT_GB) + + @staticmethod + def _add_signature(os_image: OS_Image, gx_image: GX_Image) -> None: + try: + os_image.img_signature # value + os_image.img_signature_hash_method # hash algo + os_image.img_signature_key_type # signature algo + + except AttributeError: + pass # ToDo: add aggrenation of