|
| 1 | +from dstack._internal.core.backends.base.compute import ( |
| 2 | + ComputeWithCreateInstanceSupport, |
| 3 | + ComputeWithGatewaySupport, |
| 4 | + ComputeWithMultinodeSupport, |
| 5 | + ComputeWithPlacementGroupSupport, |
| 6 | + ComputeWithPrivateGatewaySupport, |
| 7 | + ComputeWithReservationSupport, |
| 8 | + ComputeWithVolumeSupport, |
| 9 | +) |
| 10 | +from dstack._internal.core.backends.base.configurator import Configurator |
| 11 | +from dstack._internal.core.backends.configurators import list_available_configurator_classes |
1 | 12 | from dstack._internal.core.models.backends.base import BackendType |
2 | 13 |
|
3 | | -BACKENDS_WITH_MULTINODE_SUPPORT = [ |
4 | | - BackendType.AWS, |
5 | | - BackendType.AZURE, |
6 | | - BackendType.GCP, |
7 | | - BackendType.REMOTE, |
8 | | - BackendType.OCI, |
9 | | - BackendType.VULTR, |
10 | | -] |
11 | | -BACKENDS_WITH_CREATE_INSTANCE_SUPPORT = [ |
12 | | - BackendType.AWS, |
13 | | - BackendType.DSTACK, |
14 | | - BackendType.AZURE, |
15 | | - BackendType.CUDO, |
16 | | - BackendType.DATACRUNCH, |
17 | | - BackendType.GCP, |
18 | | - BackendType.LAMBDA, |
19 | | - BackendType.OCI, |
20 | | - BackendType.TENSORDOCK, |
21 | | - BackendType.VULTR, |
22 | | -] |
23 | | -BACKENDS_WITH_PLACEMENT_GROUPS_SUPPORT = [ |
24 | | - BackendType.AWS, |
25 | | -] |
26 | | -BACKENDS_WITH_RESERVATION_SUPPORT = [ |
27 | | - BackendType.AWS, |
28 | | -] |
29 | 14 |
|
30 | | -BACKENDS_WITH_GATEWAY_SUPPORT = [ |
31 | | - BackendType.AWS, |
32 | | - BackendType.AZURE, |
33 | | - BackendType.GCP, |
34 | | - BackendType.KUBERNETES, |
35 | | -] |
36 | | -BACKENDS_WITH_PRIVATE_GATEWAY_SUPPORT = [BackendType.AWS] |
37 | | -BACKENDS_WITH_VOLUMES_SUPPORT = [ |
38 | | - BackendType.AWS, |
39 | | - BackendType.GCP, |
40 | | - BackendType.LOCAL, |
41 | | - BackendType.RUNPOD, |
42 | | -] |
| 15 | +def _get_backends_with_compute_feature( |
| 16 | + configurator_classes: list[type[Configurator]], |
| 17 | + compute_feature_class: type, |
| 18 | +) -> list[BackendType]: |
| 19 | + backend_types = [] |
| 20 | + for configurator_class in configurator_classes: |
| 21 | + compute_class = configurator_class.BACKEND_CLASS.COMPUTE_CLASS |
| 22 | + if issubclass(compute_class, compute_feature_class): |
| 23 | + backend_types.append(configurator_class.TYPE) |
| 24 | + return backend_types |
| 25 | + |
| 26 | + |
| 27 | +_configurator_classes = list_available_configurator_classes() |
| 28 | + |
| 29 | + |
| 30 | +# The following backend lists do not include unavailable backends (i.e. backends missing deps). |
| 31 | +# TODO: Add LocalBackend to lists if it's enabled |
| 32 | +BACKENDS_WITH_CREATE_INSTANCE_SUPPORT = _get_backends_with_compute_feature( |
| 33 | + configurator_classes=_configurator_classes, |
| 34 | + compute_feature_class=ComputeWithCreateInstanceSupport, |
| 35 | +) |
| 36 | +BACKENDS_WITH_MULTINODE_SUPPORT = [BackendType.REMOTE] + _get_backends_with_compute_feature( |
| 37 | + configurator_classes=_configurator_classes, |
| 38 | + compute_feature_class=ComputeWithMultinodeSupport, |
| 39 | +) |
| 40 | +BACKENDS_WITH_PLACEMENT_GROUPS_SUPPORT = _get_backends_with_compute_feature( |
| 41 | + configurator_classes=_configurator_classes, |
| 42 | + compute_feature_class=ComputeWithPlacementGroupSupport, |
| 43 | +) |
| 44 | +BACKENDS_WITH_RESERVATION_SUPPORT = _get_backends_with_compute_feature( |
| 45 | + configurator_classes=_configurator_classes, |
| 46 | + compute_feature_class=ComputeWithReservationSupport, |
| 47 | +) |
| 48 | +BACKENDS_WITH_GATEWAY_SUPPORT = _get_backends_with_compute_feature( |
| 49 | + configurator_classes=_configurator_classes, |
| 50 | + compute_feature_class=ComputeWithGatewaySupport, |
| 51 | +) |
| 52 | +BACKENDS_WITH_PRIVATE_GATEWAY_SUPPORT = _get_backends_with_compute_feature( |
| 53 | + configurator_classes=_configurator_classes, |
| 54 | + compute_feature_class=ComputeWithPrivateGatewaySupport, |
| 55 | +) |
| 56 | +BACKENDS_WITH_VOLUMES_SUPPORT = _get_backends_with_compute_feature( |
| 57 | + configurator_classes=_configurator_classes, |
| 58 | + compute_feature_class=ComputeWithVolumeSupport, |
| 59 | +) |
0 commit comments