Skip to content

Commit

Permalink
feat: VolumeCreationTime variable added
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcos78 authored and alvarolopez committed Sep 27, 2024
1 parent c45fad7 commit 9f9745e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# caso


<img src="https://github.com/IFCA/caso/raw/master/doc/source/static/caso.png" width="300">

Expand Down
1 change: 1 addition & 0 deletions caso/extract/openstack/cinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
20 changes: 20 additions & 0 deletions caso/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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

Expand All @@ -463,6 +465,7 @@ def __init__(
self,
start_time: datetime.datetime,
measure_time: datetime.datetime,
volume_creation: datetime.datetime,
*args,
**kwargs,
):
Expand All @@ -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:
Expand Down Expand Up @@ -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"}
Expand Down
4 changes: 4 additions & 0 deletions caso/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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),
),
]

Expand All @@ -288,6 +290,7 @@
"Type": "Block Storage (cinder)",
"Status": "in-use",
"Capacity": 322122547200,
"VolumeCreationTime": 1684619946,
},
{
"SiteName": "TEST-Site",
Expand All @@ -305,6 +308,7 @@
"Type": "Block Storage (cinder)",
"Status": "in-use",
"Capacity": 122122547200,
"VolumeCreationTime": 1684533546,
},
]

Expand Down
23 changes: 0 additions & 23 deletions requirements.txt

This file was deleted.

0 comments on commit 9f9745e

Please sign in to comment.