Skip to content

Commit 3803290

Browse files
authored
feat(block): improve arguments configuration (#753)
1 parent f0a70cf commit 3803290

File tree

4 files changed

+32
-36
lines changed

4 files changed

+32
-36
lines changed

scaleway-async/scaleway_async/block/v1alpha1/api.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010
from scaleway_core.utils import (
1111
WaitForOptions,
12+
random_name,
1213
validate_path_param,
1314
fetch_all_pages_async,
1415
wait_for_resource_async,
@@ -231,8 +232,8 @@ async def list_volumes_all(
231232
async def create_volume(
232233
self,
233234
*,
234-
name: str,
235235
zone: Optional[Zone] = None,
236+
name: Optional[str] = None,
236237
perf_iops: Optional[int] = None,
237238
project_id: Optional[str] = None,
238239
from_empty: Optional[CreateVolumeRequestFromEmpty] = None,
@@ -243,8 +244,8 @@ async def create_volume(
243244
Create a volume.
244245
To create a new volume from scratch, you must specify `from_empty` and the `size`.
245246
To create a volume from an existing snapshot, specify `from_snapshot` and the `snapshot_id` in the request payload instead, size is optional and can be specified if you need to extend the original size. The volume will take on the same volume class and underlying IOPS limitations as the original snapshot.
246-
:param name: Name of the volume.
247247
:param zone: Zone to target. If none is passed will use default zone from the config.
248+
:param name: Name of the volume.
248249
:param perf_iops: The maximum IO/s expected, according to the different options available in stock (`5000 | 15000`).
249250
One-Of ('requirements'): at most one of 'perf_iops' could be set.
250251
:param project_id: UUID of the project the volume belongs to.
@@ -258,9 +259,7 @@ async def create_volume(
258259
Usage:
259260
::
260261
261-
result = await api.create_volume(
262-
name="example",
263-
)
262+
result = await api.create_volume()
264263
"""
265264

266265
param_zone = validate_path_param("zone", zone or self.client.default_zone)
@@ -270,8 +269,8 @@ async def create_volume(
270269
f"/block/v1alpha1/zones/{param_zone}/volumes",
271270
body=marshal_CreateVolumeRequest(
272271
CreateVolumeRequest(
273-
name=name,
274272
zone=zone,
273+
name=name or random_name(prefix="vol"),
275274
project_id=project_id,
276275
tags=tags,
277276
from_empty=from_empty,
@@ -610,8 +609,8 @@ async def create_snapshot(
610609
self,
611610
*,
612611
volume_id: str,
613-
name: str,
614612
zone: Optional[Zone] = None,
613+
name: Optional[str] = None,
615614
project_id: Optional[str] = None,
616615
tags: Optional[List[str]] = None,
617616
) -> Snapshot:
@@ -620,8 +619,8 @@ async def create_snapshot(
620619
To create a snapshot, the volume must be in the `in_use` or the `available` status.
621620
If your volume is in a transient state, you need to wait until the end of the current operation.
622621
:param volume_id: UUID of the volume to snapshot.
623-
:param name: Name of the snapshot.
624622
:param zone: Zone to target. If none is passed will use default zone from the config.
623+
:param name: Name of the snapshot.
625624
:param project_id: UUID of the project to which the volume and the snapshot belong.
626625
:param tags: List of tags assigned to the snapshot.
627626
:return: :class:`Snapshot <Snapshot>`
@@ -631,7 +630,6 @@ async def create_snapshot(
631630
632631
result = await api.create_snapshot(
633632
volume_id="example",
634-
name="example",
635633
)
636634
"""
637635

@@ -643,8 +641,8 @@ async def create_snapshot(
643641
body=marshal_CreateSnapshotRequest(
644642
CreateSnapshotRequest(
645643
volume_id=volume_id,
646-
name=name,
647644
zone=zone,
645+
name=name or random_name(prefix="snp"),
648646
project_id=project_id,
649647
tags=tags,
650648
),

scaleway-async/scaleway_async/block/v1alpha1/types.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,14 @@ class CreateSnapshotRequest:
358358
UUID of the volume to snapshot.
359359
"""
360360

361-
name: str
361+
zone: Optional[Zone]
362362
"""
363-
Name of the snapshot.
363+
Zone to target. If none is passed will use default zone from the config.
364364
"""
365365

366-
zone: Optional[Zone]
366+
name: Optional[str]
367367
"""
368-
Zone to target. If none is passed will use default zone from the config.
368+
Name of the snapshot.
369369
"""
370370

371371
project_id: Optional[str]
@@ -381,14 +381,14 @@ class CreateSnapshotRequest:
381381

382382
@dataclass
383383
class CreateVolumeRequest:
384-
name: str
384+
zone: Optional[Zone]
385385
"""
386-
Name of the volume.
386+
Zone to target. If none is passed will use default zone from the config.
387387
"""
388388

389-
zone: Optional[Zone]
389+
name: Optional[str]
390390
"""
391-
Zone to target. If none is passed will use default zone from the config.
391+
Name of the volume.
392392
"""
393393

394394
project_id: Optional[str]

scaleway/scaleway/block/v1alpha1/api.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010
from scaleway_core.utils import (
1111
WaitForOptions,
12+
random_name,
1213
validate_path_param,
1314
fetch_all_pages,
1415
wait_for_resource,
@@ -231,8 +232,8 @@ def list_volumes_all(
231232
def create_volume(
232233
self,
233234
*,
234-
name: str,
235235
zone: Optional[Zone] = None,
236+
name: Optional[str] = None,
236237
perf_iops: Optional[int] = None,
237238
project_id: Optional[str] = None,
238239
from_empty: Optional[CreateVolumeRequestFromEmpty] = None,
@@ -243,8 +244,8 @@ def create_volume(
243244
Create a volume.
244245
To create a new volume from scratch, you must specify `from_empty` and the `size`.
245246
To create a volume from an existing snapshot, specify `from_snapshot` and the `snapshot_id` in the request payload instead, size is optional and can be specified if you need to extend the original size. The volume will take on the same volume class and underlying IOPS limitations as the original snapshot.
246-
:param name: Name of the volume.
247247
:param zone: Zone to target. If none is passed will use default zone from the config.
248+
:param name: Name of the volume.
248249
:param perf_iops: The maximum IO/s expected, according to the different options available in stock (`5000 | 15000`).
249250
One-Of ('requirements'): at most one of 'perf_iops' could be set.
250251
:param project_id: UUID of the project the volume belongs to.
@@ -258,9 +259,7 @@ def create_volume(
258259
Usage:
259260
::
260261
261-
result = api.create_volume(
262-
name="example",
263-
)
262+
result = api.create_volume()
264263
"""
265264

266265
param_zone = validate_path_param("zone", zone or self.client.default_zone)
@@ -270,8 +269,8 @@ def create_volume(
270269
f"/block/v1alpha1/zones/{param_zone}/volumes",
271270
body=marshal_CreateVolumeRequest(
272271
CreateVolumeRequest(
273-
name=name,
274272
zone=zone,
273+
name=name or random_name(prefix="vol"),
275274
project_id=project_id,
276275
tags=tags,
277276
from_empty=from_empty,
@@ -608,8 +607,8 @@ def create_snapshot(
608607
self,
609608
*,
610609
volume_id: str,
611-
name: str,
612610
zone: Optional[Zone] = None,
611+
name: Optional[str] = None,
613612
project_id: Optional[str] = None,
614613
tags: Optional[List[str]] = None,
615614
) -> Snapshot:
@@ -618,8 +617,8 @@ def create_snapshot(
618617
To create a snapshot, the volume must be in the `in_use` or the `available` status.
619618
If your volume is in a transient state, you need to wait until the end of the current operation.
620619
:param volume_id: UUID of the volume to snapshot.
621-
:param name: Name of the snapshot.
622620
:param zone: Zone to target. If none is passed will use default zone from the config.
621+
:param name: Name of the snapshot.
623622
:param project_id: UUID of the project to which the volume and the snapshot belong.
624623
:param tags: List of tags assigned to the snapshot.
625624
:return: :class:`Snapshot <Snapshot>`
@@ -629,7 +628,6 @@ def create_snapshot(
629628
630629
result = api.create_snapshot(
631630
volume_id="example",
632-
name="example",
633631
)
634632
"""
635633

@@ -641,8 +639,8 @@ def create_snapshot(
641639
body=marshal_CreateSnapshotRequest(
642640
CreateSnapshotRequest(
643641
volume_id=volume_id,
644-
name=name,
645642
zone=zone,
643+
name=name or random_name(prefix="snp"),
646644
project_id=project_id,
647645
tags=tags,
648646
),

scaleway/scaleway/block/v1alpha1/types.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,14 @@ class CreateSnapshotRequest:
358358
UUID of the volume to snapshot.
359359
"""
360360

361-
name: str
361+
zone: Optional[Zone]
362362
"""
363-
Name of the snapshot.
363+
Zone to target. If none is passed will use default zone from the config.
364364
"""
365365

366-
zone: Optional[Zone]
366+
name: Optional[str]
367367
"""
368-
Zone to target. If none is passed will use default zone from the config.
368+
Name of the snapshot.
369369
"""
370370

371371
project_id: Optional[str]
@@ -381,14 +381,14 @@ class CreateSnapshotRequest:
381381

382382
@dataclass
383383
class CreateVolumeRequest:
384-
name: str
384+
zone: Optional[Zone]
385385
"""
386-
Name of the volume.
386+
Zone to target. If none is passed will use default zone from the config.
387387
"""
388388

389-
zone: Optional[Zone]
389+
name: Optional[str]
390390
"""
391-
Zone to target. If none is passed will use default zone from the config.
391+
Name of the volume.
392392
"""
393393

394394
project_id: Optional[str]

0 commit comments

Comments
 (0)