Skip to content

Commit

Permalink
pylxd/models: Adapt StorageVolumes to use old API versions
Browse files Browse the repository at this point in the history
Signed-off-by: hamistao <[email protected]>
  • Loading branch information
hamistao committed Jul 5, 2024
1 parent e382293 commit b5ebdc5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pylxd/models/storage_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,10 @@ def get(cls, volume, name):
# This field is normally empty so derive it from its volume.
snapshot.content_type = volume.content_type

# When dealing with older API version the response parsing can be messy, so we set those values to None.
if not isinstance(snapshot.created_at, str):
snapshot.created_at = None

# Snapshot names are namespaced in LXD, as volume-name/snapshot-name.
# We hide that implementation detail.
snapshot.name = snapshot.name.split("/")[-1]
Expand Down Expand Up @@ -737,6 +741,12 @@ def parse_response_item(snapshot_json):
# We hide that implementation detail.
snapshot_object.name = snapshot_object.name.split("/")[-1]

# When dealing with older API versions, the response parsing can be messy, so we manually set those values to None.
if not isinstance(snapshot_object.created_at, str):
snapshot_object.created_at = None
if snapshot_json["expires_at"] in (None, "0001-01-01T00:00:00Z"):
snapshot_object.expires_at = None

return snapshot_object

response = volume.api.snapshots.get(params={"recursion": 1})
Expand Down

0 comments on commit b5ebdc5

Please sign in to comment.