Skip to content

Commit 7b6cf06

Browse files
committed
added missing fields to the volume class
1 parent 6982df7 commit 7b6cf06

File tree

3 files changed

+210
-0
lines changed

3 files changed

+210
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added missing fields to the `Volume` class: `pseudo_path`, `mount_command`, `create_directory_command`, `filesystem_to_fstab_command`, `instances`, `contract`, `base_hourly_cost`, `monthly_price`, `currency`, `long_term`
13+
1014
## [1.23.1] - 2026-03-25
1115

1216
### Fixed

tests/unit_tests/volumes/test_volumes.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@
5050
'created_at': NVME_VOL_CREATED_AT,
5151
'target': TARGET_VDA,
5252
'ssh_key_ids': SSH_KEY_ID,
53+
'pseudo_path': 'volume-nxC2tf9F',
54+
'mount_command': 'mount -t nfs -o nconnect=16 nfs.fin-01.datacrunch.io:volume-nxC2tf9F /mnt/volume',
55+
'create_directory_command': 'mkdir -p /mnt/volume',
56+
'filesystem_to_fstab_command': "grep -qxF 'nfs.fin-01.datacrunch.io:volume-nxC2tf9F /mnt/volume nfs defaults 0 0' /etc/fstab || echo 'nfs.fin-01.datacrunch.io:volume-nxC2tf9F /mnt/volume nfs defaults 0 0' | sudo tee -a /etc/fstab",
57+
'instances': [
58+
{
59+
'id': INSTANCE_ID,
60+
'ip': '123.123.123.123',
61+
'instance_type': '4A100.88V',
62+
'status': 'running',
63+
'hostname': 'hazy-star-swims-fin-01',
64+
}
65+
],
66+
'contract': 'PAY_AS_YOU_GO',
67+
'base_hourly_cost': 0.0273972602739726,
68+
'monthly_price': 20,
69+
'currency': 'eur',
70+
'long_term': None,
5371
}
5472

5573
HDD_VOLUME = {
@@ -64,6 +82,16 @@
6482
'created_at': HDD_VOL_CREATED_AT,
6583
'target': None,
6684
'ssh_key_ids': [],
85+
'pseudo_path': 'volume-iHdL4ysR',
86+
'mount_command': 'mount -t nfs -o nconnect=16 nfs.fin-01.datacrunch.io:volume-iHdL4ysR /mnt/volume',
87+
'create_directory_command': 'mkdir -p /mnt/volume',
88+
'filesystem_to_fstab_command': "grep -qxF 'nfs.fin-01.datacrunch.io:volume-iHdL4ysR /mnt/volume nfs defaults 0 0' /etc/fstab || echo 'nfs.fin-01.datacrunch.io:volume-iHdL4ysR /mnt/volume nfs defaults 0 0' | sudo tee -a /etc/fstab",
89+
'instances': [],
90+
'contract': 'PAY_AS_YOU_GO',
91+
'base_hourly_cost': 0.01,
92+
'monthly_price': 10,
93+
'currency': 'eur',
94+
'long_term': None,
6795
}
6896

6997
PAYLOAD = [NVME_VOLUME, HDD_VOLUME]
@@ -101,6 +129,34 @@ def test_initialize_a_volume(self):
101129
assert volume.target is None
102130
assert volume.ssh_key_ids == []
103131

132+
def test_create_from_dict_without_new_fields(self):
133+
"""Test that create_from_dict handles API responses missing the new fields."""
134+
minimal_dict = {
135+
'id': RANDOM_VOL_ID,
136+
'status': VolumeStatus.DETACHED,
137+
'name': HDD_VOL_NAME,
138+
'size': HDD_VOL_SIZE,
139+
'type': HDD,
140+
'is_os_volume': False,
141+
'created_at': HDD_VOL_CREATED_AT,
142+
'target': None,
143+
'location': Locations.FIN_01,
144+
'instance_id': None,
145+
'ssh_key_ids': [],
146+
}
147+
volume = Volume.create_from_dict(minimal_dict)
148+
assert volume.id == RANDOM_VOL_ID
149+
assert volume.pseudo_path is None
150+
assert volume.mount_command is None
151+
assert volume.create_directory_command is None
152+
assert volume.filesystem_to_fstab_command is None
153+
assert volume.instances is None
154+
assert volume.contract is None
155+
assert volume.base_hourly_cost is None
156+
assert volume.monthly_price is None
157+
assert volume.currency is None
158+
assert volume.long_term is None
159+
104160
def test_get_volumes(self, volumes_service, endpoint):
105161
# arrange - add response mock
106162
responses.add(responses.GET, endpoint, json=PAYLOAD, status=200)
@@ -126,6 +182,16 @@ def test_get_volumes(self, volumes_service, endpoint):
126182
assert volume_nvme.created_at == NVME_VOL_CREATED_AT
127183
assert volume_nvme.target == TARGET_VDA
128184
assert volume_nvme.ssh_key_ids == SSH_KEY_ID
185+
assert volume_nvme.pseudo_path == NVME_VOLUME['pseudo_path']
186+
assert volume_nvme.mount_command == NVME_VOLUME['mount_command']
187+
assert volume_nvme.create_directory_command == NVME_VOLUME['create_directory_command']
188+
assert volume_nvme.filesystem_to_fstab_command == NVME_VOLUME['filesystem_to_fstab_command']
189+
assert volume_nvme.instances == NVME_VOLUME['instances']
190+
assert volume_nvme.contract == 'PAY_AS_YOU_GO'
191+
assert volume_nvme.base_hourly_cost == NVME_VOLUME['base_hourly_cost']
192+
assert volume_nvme.monthly_price == 20
193+
assert volume_nvme.currency == 'eur'
194+
assert volume_nvme.long_term is None
129195

130196
assert volume_hdd.id == HDD_VOL_ID
131197
assert volume_hdd.status == HDD_VOL_STATUS

verda/volumes/_volumes.py

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ def __init__(
2121
instance_id: str | None = None,
2222
ssh_key_ids: list[str] = [],
2323
deleted_at: str | None = None,
24+
pseudo_path: str | None = None,
25+
mount_command: str | None = None,
26+
create_directory_command: str | None = None,
27+
filesystem_to_fstab_command: str | None = None,
28+
instances: list[dict] | None = None,
29+
contract: str | None = None,
30+
base_hourly_cost: float | None = None,
31+
monthly_price: float | None = None,
32+
currency: str | None = None,
33+
long_term: dict | None = None,
2434
) -> None:
2535
"""Initialize the volume object.
2636
@@ -48,6 +58,26 @@ def __init__(
4858
:type ssh_key_ids: list[str]
4959
:param deleted_at: the time the volume was deleted (UTC), defaults to None
5060
:type deleted_at: str, optional
61+
:param pseudo_path: volume pseudo path for NFS export, defaults to None
62+
:type pseudo_path: str, optional
63+
:param mount_command: ready-to-use NFS mount command, defaults to None
64+
:type mount_command: str, optional
65+
:param create_directory_command: mkdir command for mount point, defaults to None
66+
:type create_directory_command: str, optional
67+
:param filesystem_to_fstab_command: fstab entry command for persistent mounts, defaults to None
68+
:type filesystem_to_fstab_command: str, optional
69+
:param instances: list of attached instance details, defaults to None
70+
:type instances: list[dict], optional
71+
:param contract: volume contract type e.g. "LONG_TERM", "PAY_AS_YOU_GO", defaults to None
72+
:type contract: str, optional
73+
:param base_hourly_cost: volume base hourly cost, defaults to None
74+
:type base_hourly_cost: float, optional
75+
:param monthly_price: volume monthly price, defaults to None
76+
:type monthly_price: float, optional
77+
:param currency: volume currency e.g. "usd", "eur", defaults to None
78+
:type currency: str, optional
79+
:param long_term: long term contract details, defaults to None
80+
:type long_term: dict, optional
5181
"""
5282
self._id = id
5383
self._status = status
@@ -61,6 +91,16 @@ def __init__(
6191
self._instance_id = instance_id
6292
self._ssh_key_ids = ssh_key_ids
6393
self._deleted_at = deleted_at
94+
self._pseudo_path = pseudo_path
95+
self._mount_command = mount_command
96+
self._create_directory_command = create_directory_command
97+
self._filesystem_to_fstab_command = filesystem_to_fstab_command
98+
self._instances = instances
99+
self._contract = contract
100+
self._base_hourly_cost = base_hourly_cost
101+
self._monthly_price = monthly_price
102+
self._currency = currency
103+
self._long_term = long_term
64104

65105
@property
66106
def id(self) -> str:
@@ -170,6 +210,96 @@ def deleted_at(self) -> str | None:
170210
"""
171211
return self._deleted_at
172212

213+
@property
214+
def pseudo_path(self) -> str | None:
215+
"""Get the volume pseudo path for NFS export.
216+
217+
:return: volume pseudo path
218+
:rtype: str, optional
219+
"""
220+
return self._pseudo_path
221+
222+
@property
223+
def mount_command(self) -> str | None:
224+
"""Get the ready-to-use NFS mount command.
225+
226+
:return: mount command
227+
:rtype: str, optional
228+
"""
229+
return self._mount_command
230+
231+
@property
232+
def create_directory_command(self) -> str | None:
233+
"""Get the mkdir command for creating the mount point directory.
234+
235+
:return: create directory command
236+
:rtype: str, optional
237+
"""
238+
return self._create_directory_command
239+
240+
@property
241+
def filesystem_to_fstab_command(self) -> str | None:
242+
"""Get the fstab entry command for persistent mounts.
243+
244+
:return: fstab command
245+
:rtype: str, optional
246+
"""
247+
return self._filesystem_to_fstab_command
248+
249+
@property
250+
def instances(self) -> list[dict] | None:
251+
"""Get the list of attached instance details.
252+
253+
:return: list of instance details
254+
:rtype: list[dict], optional
255+
"""
256+
return self._instances
257+
258+
@property
259+
def contract(self) -> str | None:
260+
"""Get the volume contract type.
261+
262+
:return: contract type e.g. "LONG_TERM", "PAY_AS_YOU_GO"
263+
:rtype: str, optional
264+
"""
265+
return self._contract
266+
267+
@property
268+
def base_hourly_cost(self) -> float | None:
269+
"""Get the volume base hourly cost.
270+
271+
:return: base hourly cost
272+
:rtype: float, optional
273+
"""
274+
return self._base_hourly_cost
275+
276+
@property
277+
def monthly_price(self) -> float | None:
278+
"""Get the volume monthly price.
279+
280+
:return: monthly price
281+
:rtype: float, optional
282+
"""
283+
return self._monthly_price
284+
285+
@property
286+
def currency(self) -> str | None:
287+
"""Get the volume currency.
288+
289+
:return: currency e.g. "usd", "eur"
290+
:rtype: str, optional
291+
"""
292+
return self._currency
293+
294+
@property
295+
def long_term(self) -> dict | None:
296+
"""Get the long term contract details.
297+
298+
:return: long term contract details
299+
:rtype: dict, optional
300+
"""
301+
return self._long_term
302+
173303
@classmethod
174304
def create_from_dict(cls: 'Volume', volume_dict: dict) -> 'Volume':
175305
"""Create a Volume object from a dictionary.
@@ -192,6 +322,16 @@ def create_from_dict(cls: 'Volume', volume_dict: dict) -> 'Volume':
192322
instance_id=volume_dict['instance_id'],
193323
ssh_key_ids=volume_dict['ssh_key_ids'],
194324
deleted_at=volume_dict.get('deleted_at'),
325+
pseudo_path=volume_dict.get('pseudo_path'),
326+
mount_command=volume_dict.get('mount_command'),
327+
create_directory_command=volume_dict.get('create_directory_command'),
328+
filesystem_to_fstab_command=volume_dict.get('filesystem_to_fstab_command'),
329+
instances=volume_dict.get('instances'),
330+
contract=volume_dict.get('contract'),
331+
base_hourly_cost=volume_dict.get('base_hourly_cost'),
332+
monthly_price=volume_dict.get('monthly_price'),
333+
currency=volume_dict.get('currency'),
334+
long_term=volume_dict.get('long_term'),
195335
)
196336

197337
def __str__(self) -> str:

0 commit comments

Comments
 (0)