Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ include = [
"src/dstack/_internal/core/backends",
"src/dstack/_internal/cli/services/configurators",
"src/dstack/_internal/cli/commands",
"src/tests/_internal/core",
"src/tests/_internal/server/background/pipeline_tasks",
]
exclude = [
Expand Down
6 changes: 3 additions & 3 deletions src/dstack/_internal/core/compatibility/backends.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from dstack._internal.core.backends.gcp.models import GCPBackendConfigWithCreds
from dstack._internal.core.backends.hotaisle.models import HotAisleBackendConfigWithCreds
from dstack._internal.core.backends.models import AnyBackendConfigWithCreds
from dstack._internal.core.models.common import IncludeExcludeDictType
from dstack._internal.core.models.common import IncludeExcludeStrDictType


def get_backend_config_excludes(config: AnyBackendConfigWithCreds) -> IncludeExcludeDictType:
def get_backend_config_excludes(config: AnyBackendConfigWithCreds) -> IncludeExcludeStrDictType:
"""
Returns `config` exclude mapping to exclude certain fields from the create/update backend
request. Use this method to exclude new fields when they are not set to keep
clients backward-compatibility with older servers.
"""
excludes: IncludeExcludeDictType = {}
excludes: IncludeExcludeStrDictType = {}
if isinstance(config, GCPBackendConfigWithCreds) and config.tpu is None:
excludes["tpu"] = True
if isinstance(config, HotAisleBackendConfigWithCreds) and config.bare_metal is None:
Expand Down
6 changes: 3 additions & 3 deletions src/dstack/_internal/core/compatibility/events.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from dstack._internal.core.models.common import IncludeExcludeDictType
from dstack._internal.core.models.common import IncludeExcludeStrDictType
from dstack._internal.server.schemas.events import ListEventsRequest


def get_list_events_excludes(request: ListEventsRequest) -> IncludeExcludeDictType:
list_events_excludes: IncludeExcludeDictType = {}
def get_list_events_excludes(request: ListEventsRequest) -> IncludeExcludeStrDictType:
list_events_excludes: IncludeExcludeStrDictType = {}
if request.target_presets is None:
list_events_excludes["target_presets"] = True
if request.target_gateway_replicas is None:
Expand Down
10 changes: 5 additions & 5 deletions src/dstack/_internal/core/compatibility/exports.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from dstack._internal.core.models.common import IncludeExcludeDictType
from dstack._internal.core.models.common import IncludeExcludeStrDictType
from dstack._internal.server.schemas.exports import CreateExportRequest, UpdateExportRequest


def get_create_export_excludes(request: CreateExportRequest) -> IncludeExcludeDictType:
excludes: IncludeExcludeDictType = {}
def get_create_export_excludes(request: CreateExportRequest) -> IncludeExcludeStrDictType:
excludes: IncludeExcludeStrDictType = {}
return excludes


def get_update_export_excludes(request: UpdateExportRequest) -> IncludeExcludeDictType:
excludes: IncludeExcludeDictType = {}
def get_update_export_excludes(request: UpdateExportRequest) -> IncludeExcludeStrDictType:
excludes: IncludeExcludeStrDictType = {}
return excludes
16 changes: 8 additions & 8 deletions src/dstack/_internal/core/compatibility/fleets.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
from typing import Optional

from dstack._internal.core.compatibility.common import get_profile_excludes
from dstack._internal.core.models.common import IncludeExcludeDictType
from dstack._internal.core.models.common import IncludeExcludeStrDictType
from dstack._internal.core.models.fleets import ApplyFleetPlanInput, FleetSpec


def get_get_plan_excludes(fleet_spec: FleetSpec) -> IncludeExcludeDictType:
get_plan_excludes: IncludeExcludeDictType = {}
def get_get_plan_excludes(fleet_spec: FleetSpec) -> IncludeExcludeStrDictType:
get_plan_excludes: IncludeExcludeStrDictType = {}
spec_excludes = get_fleet_spec_excludes(fleet_spec)
if spec_excludes:
get_plan_excludes["spec"] = spec_excludes
return get_plan_excludes


def get_apply_plan_excludes(plan_input: ApplyFleetPlanInput) -> IncludeExcludeDictType:
apply_plan_excludes: IncludeExcludeDictType = {}
def get_apply_plan_excludes(plan_input: ApplyFleetPlanInput) -> IncludeExcludeStrDictType:
apply_plan_excludes: IncludeExcludeStrDictType = {}
spec_excludes = get_fleet_spec_excludes(plan_input.spec)
if spec_excludes:
apply_plan_excludes["spec"] = spec_excludes
current_resource = plan_input.current_resource
if current_resource is not None:
current_resource_excludes: IncludeExcludeDictType = {}
current_resource_excludes: IncludeExcludeStrDictType = {}
current_resource_spec_excludes = get_fleet_spec_excludes(current_resource.spec)
if current_resource_spec_excludes:
current_resource_excludes["spec"] = current_resource_spec_excludes
Expand All @@ -33,13 +33,13 @@ def get_apply_plan_excludes(plan_input: ApplyFleetPlanInput) -> IncludeExcludeDi
return {"plan": apply_plan_excludes}


def get_fleet_spec_excludes(fleet_spec: FleetSpec) -> Optional[IncludeExcludeDictType]:
def get_fleet_spec_excludes(fleet_spec: FleetSpec) -> Optional[IncludeExcludeStrDictType]:
"""
Returns `fleet_spec` exclude mapping to exclude certain fields from the request.
Use this method to exclude new fields when they are not set to keep
clients backward-compatibility with older servers.
"""
spec_excludes: IncludeExcludeDictType = {}
spec_excludes: IncludeExcludeStrDictType = {}
profile_excludes = get_profile_excludes(fleet_spec.profile)

spec_excludes["autocreated"] = True
Expand Down
26 changes: 14 additions & 12 deletions src/dstack/_internal/core/compatibility/gateways.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dstack._internal.core.models.common import IncludeExcludeDictType
from dstack._internal.core.models.common import IncludeExcludeStrDictType
from dstack._internal.core.models.gateways import (
ApplyGatewayPlanInput,
GatewayConfiguration,
Expand All @@ -10,12 +10,12 @@
)


def get_get_plan_excludes(body: GetGatewayPlanRequest) -> IncludeExcludeDictType:
def get_get_plan_excludes(body: GetGatewayPlanRequest) -> IncludeExcludeStrDictType:
return {"spec": get_gateway_spec_excludes(body.spec)}


def get_apply_plan_excludes(plan_input: ApplyGatewayPlanInput) -> IncludeExcludeDictType:
apply_plan_excludes: IncludeExcludeDictType = {
def get_apply_plan_excludes(plan_input: ApplyGatewayPlanInput) -> IncludeExcludeStrDictType:
apply_plan_excludes: IncludeExcludeStrDictType = {
"spec": get_gateway_spec_excludes(plan_input.spec)
}
if plan_input.current_resource is not None:
Expand All @@ -31,39 +31,41 @@ def get_apply_plan_excludes(plan_input: ApplyGatewayPlanInput) -> IncludeExclude
return {"plan": apply_plan_excludes}


def get_gateway_spec_excludes(gateway_spec: GatewaySpec) -> IncludeExcludeDictType:
def get_gateway_spec_excludes(gateway_spec: GatewaySpec) -> IncludeExcludeStrDictType:
"""
Returns `gateway_spec` exclude mapping to exclude certain fields from the request.
Use this method to exclude new fields when they are not set to keep
clients backward-compatibility with older servers.
"""
spec_excludes: IncludeExcludeDictType = {}
spec_excludes: IncludeExcludeStrDictType = {}
spec_excludes["configuration"] = _get_gateway_configuration_excludes(
gateway_spec.configuration
)
return spec_excludes


def get_create_gateway_excludes(configuration: GatewayConfiguration) -> IncludeExcludeDictType:
def get_create_gateway_excludes(configuration: GatewayConfiguration) -> IncludeExcludeStrDictType:
"""
Returns an exclude mapping to exclude certain fields from the create gateway request.
Use this method to exclude new fields when they are not set to keep
clients backward-compatibility with older servers.
"""
create_gateway_excludes: IncludeExcludeDictType = {}
create_gateway_excludes: IncludeExcludeStrDictType = {}
create_gateway_excludes["configuration"] = _get_gateway_configuration_excludes(configuration)
return create_gateway_excludes


def get_set_default_gateway_excludes(request: SetDefaultGatewayRequest) -> IncludeExcludeDictType:
excludes: IncludeExcludeDictType = {}
def get_set_default_gateway_excludes(
request: SetDefaultGatewayRequest,
) -> IncludeExcludeStrDictType:
excludes: IncludeExcludeStrDictType = {}
return excludes


def _get_gateway_configuration_excludes(
configuration: GatewayConfiguration,
) -> IncludeExcludeDictType:
configuration_excludes: IncludeExcludeDictType = {}
) -> IncludeExcludeStrDictType:
configuration_excludes: IncludeExcludeStrDictType = {}

if configuration.default is None:
configuration_excludes["default"] = True
Expand Down
6 changes: 3 additions & 3 deletions src/dstack/_internal/core/compatibility/gpus.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Optional

from dstack._internal.core.compatibility.runs import get_run_spec_excludes
from dstack._internal.core.models.common import IncludeExcludeDictType
from dstack._internal.core.models.common import IncludeExcludeStrDictType
from dstack._internal.server.schemas.gpus import ListGpusRequest


def get_list_gpus_excludes(request: ListGpusRequest) -> Optional[IncludeExcludeDictType]:
list_gpus_excludes: IncludeExcludeDictType = {} if request.reverse else {"reverse": True}
def get_list_gpus_excludes(request: ListGpusRequest) -> Optional[IncludeExcludeStrDictType]:
list_gpus_excludes: IncludeExcludeStrDictType = {} if request.reverse else {"reverse": True}
run_spec_excludes = get_run_spec_excludes(request.run_spec)
if run_spec_excludes is not None:
list_gpus_excludes["run_spec"] = run_spec_excludes
Expand Down
6 changes: 3 additions & 3 deletions src/dstack/_internal/core/compatibility/logs.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from typing import Optional

from dstack._internal.core.models.common import IncludeExcludeDictType
from dstack._internal.core.models.common import IncludeExcludeStrDictType
from dstack._internal.server.schemas.logs import PollLogsRequest


def get_poll_logs_excludes(request: PollLogsRequest) -> Optional[IncludeExcludeDictType]:
def get_poll_logs_excludes(request: PollLogsRequest) -> Optional[IncludeExcludeStrDictType]:
"""
Returns exclude mapping to exclude certain fields from the request.
Use this method to exclude new fields when they are not set to keep
clients backward-compatibility with older servers.
"""
excludes: IncludeExcludeDictType = {}
excludes: IncludeExcludeStrDictType = {}
return excludes if excludes else None
26 changes: 13 additions & 13 deletions src/dstack/_internal/core/compatibility/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from dstack._internal.core.compatibility.common import get_profile_excludes
from dstack._internal.core.models.common import (
IncludeExcludeDictType,
IncludeExcludeSetType,
IncludeExcludeStrDictType,
)
from dstack._internal.core.models.configurations import (
ServiceConfiguration,
Expand All @@ -24,19 +24,19 @@ def get_list_runs_excludes(list_runs_request: ListRunsRequest) -> IncludeExclude
return excludes


def get_apply_plan_excludes(plan: ApplyRunPlanInput) -> Optional[IncludeExcludeDictType]:
def get_apply_plan_excludes(plan: ApplyRunPlanInput) -> Optional[IncludeExcludeStrDictType]:
"""
Returns `plan` exclude mapping to exclude certain fields from the request.
Use this method to exclude new fields when they are not set to keep
clients backward-compatibility with older servers.
"""
apply_plan_excludes: IncludeExcludeDictType = {}
apply_plan_excludes: IncludeExcludeStrDictType = {}
run_spec_excludes = get_run_spec_excludes(plan.run_spec)
if run_spec_excludes is not None:
apply_plan_excludes["run_spec"] = run_spec_excludes
current_resource = plan.current_resource
if current_resource is not None:
current_resource_excludes: IncludeExcludeDictType = {}
current_resource_excludes: IncludeExcludeStrDictType = {}
apply_plan_excludes["current_resource"] = current_resource_excludes
current_resource_excludes["run_spec"] = get_run_spec_excludes(current_resource.run_spec)
current_resource_excludes["jobs"] = {
Expand All @@ -62,12 +62,12 @@ def get_apply_plan_excludes(plan: ApplyRunPlanInput) -> Optional[IncludeExcludeD
return {"plan": apply_plan_excludes}


def get_get_plan_excludes(request: GetRunPlanRequest) -> Optional[IncludeExcludeDictType]:
def get_get_plan_excludes(request: GetRunPlanRequest) -> Optional[IncludeExcludeStrDictType]:
"""
Excludes new fields when they are not set to keep
clients backward-compatibility with older servers.
"""
get_plan_excludes: IncludeExcludeDictType = (
get_plan_excludes: IncludeExcludeStrDictType = (
{} if request.reverse_offers else {"reverse_offers": True}
)
run_spec_excludes = get_run_spec_excludes(request.run_spec)
Expand All @@ -76,14 +76,14 @@ def get_get_plan_excludes(request: GetRunPlanRequest) -> Optional[IncludeExclude
return get_plan_excludes


def get_run_spec_excludes(run_spec: RunSpec) -> IncludeExcludeDictType:
def get_run_spec_excludes(run_spec: RunSpec) -> IncludeExcludeStrDictType:
"""
Returns `run_spec` exclude mapping to exclude certain fields from the request.
Use this method to exclude new fields when they are not set to keep
clients backward-compatibility with older servers.
"""
spec_excludes: IncludeExcludeDictType = {}
configuration_excludes: IncludeExcludeDictType = {}
spec_excludes: IncludeExcludeStrDictType = {}
configuration_excludes: IncludeExcludeStrDictType = {}
profile_excludes = get_profile_excludes(run_spec.profile)
for field in get_profile_excludes(run_spec.configuration):
configuration_excludes[field] = True
Expand All @@ -106,13 +106,13 @@ def get_run_spec_excludes(run_spec: RunSpec) -> IncludeExcludeDictType:
return spec_excludes


def get_job_spec_excludes(job_specs: list[JobSpec]) -> IncludeExcludeDictType:
def get_job_spec_excludes(job_specs: list[JobSpec]) -> IncludeExcludeStrDictType:
"""
Returns `job_spec` exclude mapping to exclude certain fields from the request.
Use this method to exclude new fields when they are not set to keep
clients backward-compatibility with older servers.
"""
spec_excludes: IncludeExcludeDictType = {}
spec_excludes: IncludeExcludeStrDictType = {}
if all(s.node_group_index == 0 for s in job_specs):
spec_excludes["node_group_index"] = True
if all(s.node_group_name == DEFAULT_REPLICA_GROUP_NAME for s in job_specs):
Expand All @@ -122,8 +122,8 @@ def get_job_spec_excludes(job_specs: list[JobSpec]) -> IncludeExcludeDictType:
return spec_excludes


def get_job_submission_excludes(job_submissions: list[JobSubmission]) -> IncludeExcludeDictType:
submission_excludes: IncludeExcludeDictType = {}
def get_job_submission_excludes(job_submissions: list[JobSubmission]) -> IncludeExcludeStrDictType:
submission_excludes: IncludeExcludeStrDictType = {}
# `Resources.description` is deprecated and never set since 0.21. Not sending it lets 0.22
# drop the field without breaking 0.21 clients.
submission_excludes["job_provisioning_data"] = {
Expand Down
14 changes: 7 additions & 7 deletions src/dstack/_internal/core/compatibility/volumes.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
from dstack._internal.core.models.common import IncludeExcludeDictType
from dstack._internal.core.models.common import IncludeExcludeStrDictType
from dstack._internal.core.models.volumes import (
AnyVolumeConfiguration,
VolumeSpec,
)


def get_volume_spec_excludes(volume_spec: VolumeSpec) -> IncludeExcludeDictType:
def get_volume_spec_excludes(volume_spec: VolumeSpec) -> IncludeExcludeStrDictType:
"""
Returns `volume_spec` exclude mapping to exclude certain fields from the request.
Use this method to exclude new fields when they are not set to keep
clients backward-compatibility with older servers.
"""
spec_excludes: IncludeExcludeDictType = {}
spec_excludes: IncludeExcludeStrDictType = {}
spec_excludes["configuration"] = _get_volume_configuration_excludes(volume_spec.configuration)
return spec_excludes


def get_create_volume_excludes(configuration: AnyVolumeConfiguration) -> IncludeExcludeDictType:
def get_create_volume_excludes(configuration: AnyVolumeConfiguration) -> IncludeExcludeStrDictType:
"""
Returns an exclude mapping to exclude certain fields from the create volume request.
Use this method to exclude new fields when they are not set to keep
clients backward-compatibility with older servers.
"""
create_volume_excludes: IncludeExcludeDictType = {}
create_volume_excludes: IncludeExcludeStrDictType = {}
create_volume_excludes["configuration"] = _get_volume_configuration_excludes(configuration)
return create_volume_excludes


def _get_volume_configuration_excludes(
configuration: AnyVolumeConfiguration,
) -> IncludeExcludeDictType:
configuration_excludes: IncludeExcludeDictType = {}
) -> IncludeExcludeStrDictType:
configuration_excludes: IncludeExcludeStrDictType = {}
return configuration_excludes
7 changes: 5 additions & 2 deletions src/dstack/_internal/core/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ def drop_merged_profile(schema: dict[str, Any]) -> None:
IncludeExcludeFieldType = Union[int, str]
IncludeExcludeSetType = Union[set[int], set[str]]
# `dict` rather than `Mapping`, so these stay assignable both *to* pydantic's `IncEx` and to the
# plain `Dict` parameters the plugin API declares. Keyed by int or str but not both, like `IncEx`.
# plain `Dict` parameters the plugin API declares.
# Keyed by field names, as include/exclude mappings for models are.
IncludeExcludeStrDictType = dict[str, Union["IncludeExcludeType", bool]]
# Keyed by int or str but not both, like `IncEx`.
IncludeExcludeDictType = Union[
dict[int, Union["IncludeExcludeType", bool]],
dict[str, Union["IncludeExcludeType", bool]],
IncludeExcludeStrDictType,
]
IncludeExcludeType = Union[IncludeExcludeSetType, IncludeExcludeDictType]

Expand Down
6 changes: 4 additions & 2 deletions src/tests/_internal/core/backends/base/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def test_fits_disk_only_for_offers_matching_other_requirements(self):
compute = _ComputeWithCachedOffers(
[gpu_offer, cpu_offer], {"gpu": configurable, "cpu": configurable}
)
requirements = Requirements(resources=ResourcesSpec(gpu=1, disk="200GB.."))
requirements = Requirements(
resources=ResourcesSpec.model_validate({"gpu": 1, "disk": "200GB.."})
)

offers = list(compute.get_offers(requirements, False, False))

Expand All @@ -77,7 +79,7 @@ def test_excludes_offers_whose_disk_does_not_fit(self):
[configurable_offer, fixed_offer],
{"configurable": Range[Memory](min=Memory.parse("50GB"), max=None), "fixed": None},
)
requirements = Requirements(resources=ResourcesSpec(disk="200GB.."))
requirements = Requirements(resources=ResourcesSpec.model_validate({"disk": "200GB.."}))

offers = list(compute.get_offers(requirements, False, False))

Expand Down
Loading
Loading