Skip to content

Commit

Permalink
Support additional attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Anja Strunk <anja.strunk@cloudandheat.com>
  • Loading branch information
anjastrunk committed Dec 21, 2023
1 parent 948887b commit bb93b2f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 6 deletions.
14 changes: 9 additions & 5 deletions generator/common/gx_schema.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):

Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down
61 changes: 60 additions & 1 deletion generator/discovery/openstack/vm_images_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit bb93b2f

Please sign in to comment.