From 9f9745ee58b046ce20688c27c0430fdad96ecec5 Mon Sep 17 00:00:00 2001 From: Alessandro Costantini Date: Wed, 19 Jun 2024 19:11:13 +0200 Subject: [PATCH] feat: VolumeCreationTime variable added --- README.md | 2 +- caso/extract/openstack/cinder.py | 1 + caso/record.py | 20 ++++++++++++++++++++ caso/tests/conftest.py | 4 ++++ requirements.txt | 23 ----------------------- 5 files changed, 26 insertions(+), 24 deletions(-) delete mode 100644 requirements.txt diff --git a/README.md b/README.md index f1d1fbee..42552ba7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# caso + diff --git a/caso/extract/openstack/cinder.py b/caso/extract/openstack/cinder.py index 3211a578..9d76b368 100644 --- a/caso/extract/openstack/cinder.py +++ b/caso/extract/openstack/cinder.py @@ -70,6 +70,7 @@ def _build_record(self, volume, extract_from, extract_to): active_duration=active_duration, measure_time=measure_time, start_time=vol_created, + volume_creation=dateutil.parser.parse(vol_start), capacity=volume.size, user_dn=user, ) diff --git a/caso/record.py b/caso/record.py index 9939f01d..9a70a9c7 100644 --- a/caso/record.py +++ b/caso/record.py @@ -423,6 +423,7 @@ def map_storage_fields(field: str) -> str: "attached_duration": "AttachedDuration", "compute_service": "CloudComputeService", "cloud_type": "CloudType", + "volume_creation_epoch": "VolumeCreationTime", } return d.get(field, field) @@ -453,6 +454,7 @@ class StorageRecord(_BaseRecord): # easier for us to maintain them as datetime objects internally. _measure_time: datetime.datetime _start_time: datetime.datetime + _volume_creation: datetime.datetime storage_type: typing.Optional[str] = "Block Storage (cinder)" @@ -463,6 +465,7 @@ def __init__( self, start_time: datetime.datetime, measure_time: datetime.datetime, + volume_creation: datetime.datetime, *args, **kwargs, ): @@ -471,6 +474,7 @@ def __init__( self._start_time = start_time self._measure_time = measure_time + self._volume_creation = volume_creation @property def start_time(self) -> datetime.datetime: @@ -504,6 +508,22 @@ def measure_time_epoch(self) -> int: """Get measurement time as epoch.""" return int(self._measure_time.timestamp()) + @property + def volume_creation(self) -> datetime.datetime: + """Get volume creation time.""" + return self._volume_creation + + @volume_creation.setter + def volume_creation(self, volume_creation: datetime.datetime) -> None: + """Set volume creation time.""" + self._volume_creation = volume_creation + + @pydantic.computed_field() # type: ignore[misc] + @property + def volume_creation_epoch(self) -> int: + """Get volume creation time as epoch.""" + return int(self._volume_creation.timestamp()) + def ssm_message(self): """Render record as the expected SSM message.""" ns = {"xmlns:sr": "http://eu-emi.eu/namespaces/2011/02/storagerecord"} diff --git a/caso/tests/conftest.py b/caso/tests/conftest.py index 2e25861d..edaf4af5 100644 --- a/caso/tests/conftest.py +++ b/caso/tests/conftest.py @@ -253,6 +253,7 @@ start_time=now - datetime.timedelta(days=5), capacity=322122547200, user_dn="d4e547e6f298fe34389@foobar.eu", + volume_creation=now - datetime.timedelta(days=5), ), dict( uuid="99cf5d02-a573-46a1-b90d-0f7327126876", @@ -268,6 +269,7 @@ start_time=now - datetime.timedelta(days=6), capacity=122122547200, user_dn="d4e547e6f298fe34389@foobar.eu", + volume_creation=now - datetime.timedelta(days=6), ), ] @@ -288,6 +290,7 @@ "Type": "Block Storage (cinder)", "Status": "in-use", "Capacity": 322122547200, + "VolumeCreationTime": 1684619946, }, { "SiteName": "TEST-Site", @@ -305,6 +308,7 @@ "Type": "Block Storage (cinder)", "Status": "in-use", "Capacity": 122122547200, + "VolumeCreationTime": 1684533546, }, ] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 2e02f3c0..00000000 --- a/requirements.txt +++ /dev/null @@ -1,23 +0,0 @@ -# The order of packages is significant, because pip processes them in the order -# of appearance. Changing the order has an impact on the overall integration -# process, which may cause wedges in the gate later. -pbr>=4.1.0 -six>=1.9.0 - -dirq -python-dateutil>=2.4.2 - -oslo.config>=2.3.0 # Apache-2.0 -oslo.concurrency>=3.20.0 # Apache-2.0 -oslo.log>=1.8.0 # Apache-2.0 -oslo-utils>=4.10.1 - -python-cinderclient>=5.0.0 # Apache-2.0 -python-novaclient>=2.28.1 # Apache-2.0 -python-keystoneclient>=3.0.0 # Apache-2.0 -python-glanceclient>=0.18.0 # Apache-2.0 -python-neutronclient>=6.7.0 # Apache-2.0 -keystoneauth1>=3.4.0 # Apache-2.0 - -stevedore -pydantic>=2.0.0