Skip to content

Commit 9f9745e

Browse files
alexcos78alvarolopez
authored andcommitted
feat: VolumeCreationTime variable added
1 parent c45fad7 commit 9f9745e

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# caso
1+
22

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

caso/extract/openstack/cinder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def _build_record(self, volume, extract_from, extract_to):
7070
active_duration=active_duration,
7171
measure_time=measure_time,
7272
start_time=vol_created,
73+
volume_creation=dateutil.parser.parse(vol_start),
7374
capacity=volume.size,
7475
user_dn=user,
7576
)

caso/record.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ def map_storage_fields(field: str) -> str:
423423
"attached_duration": "AttachedDuration",
424424
"compute_service": "CloudComputeService",
425425
"cloud_type": "CloudType",
426+
"volume_creation_epoch": "VolumeCreationTime",
426427
}
427428
return d.get(field, field)
428429

@@ -453,6 +454,7 @@ class StorageRecord(_BaseRecord):
453454
# easier for us to maintain them as datetime objects internally.
454455
_measure_time: datetime.datetime
455456
_start_time: datetime.datetime
457+
_volume_creation: datetime.datetime
456458

457459
storage_type: typing.Optional[str] = "Block Storage (cinder)"
458460

@@ -463,6 +465,7 @@ def __init__(
463465
self,
464466
start_time: datetime.datetime,
465467
measure_time: datetime.datetime,
468+
volume_creation: datetime.datetime,
466469
*args,
467470
**kwargs,
468471
):
@@ -471,6 +474,7 @@ def __init__(
471474

472475
self._start_time = start_time
473476
self._measure_time = measure_time
477+
self._volume_creation = volume_creation
474478

475479
@property
476480
def start_time(self) -> datetime.datetime:
@@ -504,6 +508,22 @@ def measure_time_epoch(self) -> int:
504508
"""Get measurement time as epoch."""
505509
return int(self._measure_time.timestamp())
506510

511+
@property
512+
def volume_creation(self) -> datetime.datetime:
513+
"""Get volume creation time."""
514+
return self._volume_creation
515+
516+
@volume_creation.setter
517+
def volume_creation(self, volume_creation: datetime.datetime) -> None:
518+
"""Set volume creation time."""
519+
self._volume_creation = volume_creation
520+
521+
@pydantic.computed_field() # type: ignore[misc]
522+
@property
523+
def volume_creation_epoch(self) -> int:
524+
"""Get volume creation time as epoch."""
525+
return int(self._volume_creation.timestamp())
526+
507527
def ssm_message(self):
508528
"""Render record as the expected SSM message."""
509529
ns = {"xmlns:sr": "http://eu-emi.eu/namespaces/2011/02/storagerecord"}

caso/tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@
253253
start_time=now - datetime.timedelta(days=5),
254254
capacity=322122547200,
255255
user_dn="[email protected]",
256+
volume_creation=now - datetime.timedelta(days=5),
256257
),
257258
dict(
258259
uuid="99cf5d02-a573-46a1-b90d-0f7327126876",
@@ -268,6 +269,7 @@
268269
start_time=now - datetime.timedelta(days=6),
269270
capacity=122122547200,
270271
user_dn="[email protected]",
272+
volume_creation=now - datetime.timedelta(days=6),
271273
),
272274
]
273275

@@ -288,6 +290,7 @@
288290
"Type": "Block Storage (cinder)",
289291
"Status": "in-use",
290292
"Capacity": 322122547200,
293+
"VolumeCreationTime": 1684619946,
291294
},
292295
{
293296
"SiteName": "TEST-Site",
@@ -305,6 +308,7 @@
305308
"Type": "Block Storage (cinder)",
306309
"Status": "in-use",
307310
"Capacity": 122122547200,
311+
"VolumeCreationTime": 1684533546,
308312
},
309313
]
310314

requirements.txt

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)