Skip to content

Commit 638e38d

Browse files
authored
Prepare future OCI spot instances support (#1401)
This commit implements launching OCI spot instances. However, spot offers will not be added to `gpuhunt` catalog yet, as they would break previous `dstack` versions that do not distinguish between on-demand and spot offers. We can add spot offers to catalog later, once `dstack` versions 0.18.3 and 0.18.4 become irrelevant.
1 parent d3fa99e commit 638e38d

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/dstack/_internal/core/backends/oci/compute.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def create_instance(
151151
display_name=instance_config.instance_name,
152152
cloud_init_user_data=cloud_init_user_data,
153153
shape=instance_offer.instance.name,
154+
is_spot=instance_offer.instance.resources.spot,
154155
disk_size_gb=round(instance_offer.instance.resources.disk.size_mib / 1024),
155156
image_id=package.image_id,
156157
)

src/dstack/_internal/core/backends/oci/resources.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,16 @@ def launch_instance(
284284
display_name: str,
285285
cloud_init_user_data: str,
286286
shape: str,
287+
is_spot: bool,
287288
disk_size_gb: int,
288289
image_id: str,
289290
) -> oci.core.models.Instance:
291+
preemptible_config = None
292+
if is_spot:
293+
preemptible_config = oci.core.models.PreemptibleInstanceConfigDetails(
294+
preemption_action=oci.core.models.TerminatePreemptionAction(preserve_boot_volume=False)
295+
)
296+
290297
return region.compute_client.launch_instance(
291298
oci.core.models.LaunchInstanceDetails(
292299
availability_domain=availability_domain,
@@ -301,6 +308,7 @@ def launch_instance(
301308
metadata=dict(
302309
user_data=base64.b64encode(cloud_init_user_data.encode()).decode(),
303310
),
311+
preemptible_instance_config=preemptible_config,
304312
shape=shape,
305313
source_details=oci.core.models.InstanceSourceViaImageDetails(
306314
image_id=image_id,

0 commit comments

Comments
 (0)