|
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 |
12 | | -from dstack._internal.core.backends.local.compute import LocalCompute |
13 | | -from dstack._internal.core.models.backends.base import BackendType |
14 | | -from dstack._internal.settings import LOCAL_BACKEND_ENABLED |
15 | | - |
16 | | - |
17 | | -def _get_backends_with_compute_feature( |
18 | | - configurator_classes: list[type[Configurator]], |
19 | | - compute_feature_class: type, |
20 | | -) -> list[BackendType]: |
21 | | - backend_types_and_computes = [ |
22 | | - (configurator_class.TYPE, configurator_class.BACKEND_CLASS.COMPUTE_CLASS) |
23 | | - for configurator_class in configurator_classes |
24 | | - ] |
25 | | - if LOCAL_BACKEND_ENABLED: |
26 | | - backend_types_and_computes.append((BackendType.LOCAL, LocalCompute)) |
27 | | - backend_types = [] |
28 | | - for backend_type, compute_class in backend_types_and_computes: |
29 | | - if issubclass(compute_class, compute_feature_class): |
30 | | - backend_types.append(backend_type) |
31 | | - return backend_types |
32 | | - |
33 | | - |
34 | | -_configurator_classes = list_available_configurator_classes() |
35 | | - |
36 | | - |
37 | | -# The following backend lists do not include unavailable backends (i.e. backends missing deps). |
38 | | -BACKENDS_WITH_CREATE_INSTANCE_SUPPORT = _get_backends_with_compute_feature( |
39 | | - configurator_classes=_configurator_classes, |
40 | | - compute_feature_class=ComputeWithCreateInstanceSupport, |
41 | | -) |
42 | | -BACKENDS_WITH_MULTINODE_SUPPORT = [BackendType.REMOTE] + _get_backends_with_compute_feature( |
43 | | - configurator_classes=_configurator_classes, |
44 | | - compute_feature_class=ComputeWithMultinodeSupport, |
45 | | -) |
46 | | -BACKENDS_WITH_PLACEMENT_GROUPS_SUPPORT = _get_backends_with_compute_feature( |
47 | | - configurator_classes=_configurator_classes, |
48 | | - compute_feature_class=ComputeWithPlacementGroupSupport, |
49 | | -) |
50 | | -BACKENDS_WITH_RESERVATION_SUPPORT = _get_backends_with_compute_feature( |
51 | | - configurator_classes=_configurator_classes, |
52 | | - compute_feature_class=ComputeWithReservationSupport, |
53 | | -) |
54 | | -BACKENDS_WITH_GATEWAY_SUPPORT = _get_backends_with_compute_feature( |
55 | | - configurator_classes=_configurator_classes, |
56 | | - compute_feature_class=ComputeWithGatewaySupport, |
57 | | -) |
58 | | -BACKENDS_WITH_PRIVATE_GATEWAY_SUPPORT = _get_backends_with_compute_feature( |
59 | | - configurator_classes=_configurator_classes, |
60 | | - compute_feature_class=ComputeWithPrivateGatewaySupport, |
61 | | -) |
62 | | -BACKENDS_WITH_VOLUMES_SUPPORT = _get_backends_with_compute_feature( |
63 | | - configurator_classes=_configurator_classes, |
64 | | - compute_feature_class=ComputeWithVolumeSupport, |
65 | | -) |
0 commit comments