Skip to content

Commit

Permalink
Merge branch 'fix_timestamp' into 'v2.2'
Browse files Browse the repository at this point in the history
csi_driver: fixed creation_time field for ListSnapshots endpoint (VCSI-72)

See merge request dev/vast-csi!58
  • Loading branch information
koreno committed Mar 8, 2023
2 parents 908877e + 2ec7c9a commit 27ba5f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
18 changes: 10 additions & 8 deletions vast_csi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@
from easypy.bunch import Bunch

from .logging import logger, init_logging
from .utils import patch_traceback_format, get_mount, normalize_mount_options, parse_load_balancing_strategy
from .utils import (
patch_traceback_format,
get_mount,
normalize_mount_options,
parse_load_balancing_strategy,
string_to_proto_timestamp
)
from . import csi_pb2_grpc
from .csi_pb2_grpc import ControllerServicer, NodeServicer, IdentityServicer
from . import csi_types as types
Expand Down Expand Up @@ -573,14 +579,11 @@ def CreateSnapshot(self, source_volume_id, name, parameters=None):
if not handled:
raise Abort(INVALID_ARGUMENT, str(exc))

creation_time = types.Timestamp()
creation_time.FromJsonString(snap.created)

snp = types.Snapshot(
size_bytes=0, # indicates 'unspecified'
snapshot_id=str(snap.id),
source_volume_id=volume_id,
creation_time=creation_time,
creation_time=string_to_proto_timestamp(snap.created),
ready_to_use=True,
)

Expand Down Expand Up @@ -650,7 +653,6 @@ def to_snapshot(dentry):
)
else:
page_size = max_entries or 250
ts = types.Timestamp()

if starting_token:
ret = self.vms_session.get_by_token(starting_token)
Expand All @@ -663,7 +665,7 @@ def to_snapshot(dentry):
size_bytes=0, # indicates 'unspecified'
snapshot_id=str(snap.id),
source_volume_id=self._to_volume_id(snap.path) or "n/a",
creation_time=ts.FromJsonString(snap.created),
creation_time=string_to_proto_timestamp(snap.created),
ready_to_use=True,
))])

Expand All @@ -672,7 +674,7 @@ def to_snapshot(dentry):
size_bytes=0, # indicates 'unspecified'
snapshot_id=str(snap.id),
source_volume_id=self._to_volume_id(snap.path) or "n/a",
creation_time=ts.FromJsonString(snap.created),
creation_time=string_to_proto_timestamp(snap.created),
ready_to_use=True,
)) for snap in ret.results])

Expand Down
9 changes: 9 additions & 0 deletions vast_csi/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from datetime import datetime
from requests.exceptions import HTTPError # noqa

from plumbum import local
Expand All @@ -9,6 +10,8 @@
ROUNDROBIN,
RANDOM,
)
from . import csi_types as types


LOAD_BALANCING_STRATEGIES = {ROUNDROBIN, RANDOM}

Expand Down Expand Up @@ -119,3 +122,9 @@ def normalize_mount_options(mount_options: str):
s = mount_options.strip()
mount_options = list({p for p in s.split(",") if p})
return mount_options


def string_to_proto_timestamp(str_ts: str):
"""Convert string to protobuf.Timestamp"""
t = datetime.fromisoformat(str_ts.rstrip("Z")).timestamp()
return types.Timestamp(seconds=int(t), nanos=int(t % 1 * 1e9))

0 comments on commit 27ba5f9

Please sign in to comment.