Skip to content

Commit ef720c2

Browse files
authored
Merge pull request #2395 from dstackai/issue_2372_backend_configs
Move backend/compute configs from config.py to models.py
2 parents 3f54a50 + 748935a commit ef720c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+139
-185
lines changed

contributing/BACKENDS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Refer to examples:
127127
##### 2.4.5. Create and register the backend config models
128128

129129
Under the backend directory, create the `models.py` file and define the backend config model classes there.
130-
Every backend must define two models:
130+
Every backend must define at least two models:
131131

132132
* `*BackendConfig` that contains all backend parameters available for user configuration except for creds.
133133
* `*BackendConfigWithCreds` that contains all backends parameters available for user configuration and also creds.
@@ -136,7 +136,7 @@ These models are used in server/config.yaml, the API, and for backend configurat
136136

137137
The models should be added to `AnyBackendConfig*` unions in [`src/dstack/_internal/core/backends/models.py`](https://github.com/dstackai/dstack/blob/master/src/dstack/_internal/core/backends/models.py).
138138

139-
It's not required but recommended to define `*BackendStoredConfig` that extends `*BackendConfig` to be able to store extra parameters in the DB. By the same logic, it's recommended to define `*Config` that extends `*BackendStoredConfig` with creds and use it as the main `Backend` and `Compute` config instead of using `*BackendConfigWithCreds` directly.
139+
It's not required but recommended to also define `*BackendStoredConfig` that extends `*BackendConfig` to be able to store extra parameters in the DB. By the same logic, it's recommended to define `*Config` that extends `*BackendStoredConfig` with creds and use it as the main `Backend` and `Compute` config instead of using `*BackendConfigWithCreds` directly.
140140

141141
Refer to examples:
142142
[datacrunch](https://github.com/dstackai/dstack/blob/master/src/dstack/_internal/core/backends/datacrunch/models.py),

src/dstack/_internal/core/backends/aws/backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import botocore.exceptions
22

33
from dstack._internal.core.backends.aws.compute import AWSCompute
4-
from dstack._internal.core.backends.aws.config import AWSConfig
4+
from dstack._internal.core.backends.aws.models import AWSConfig
55
from dstack._internal.core.backends.base.backend import Backend
66
from dstack._internal.core.errors import BackendInvalidCredentialsError
77
from dstack._internal.core.models.backends.base import BackendType

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
import dstack._internal.core.backends.aws.resources as aws_resources
1010
from dstack._internal import settings
11-
from dstack._internal.core.backends.aws.config import AWSConfig
12-
from dstack._internal.core.backends.aws.models import AWSAccessKeyCreds
11+
from dstack._internal.core.backends.aws.models import AWSAccessKeyCreds, AWSConfig
1312
from dstack._internal.core.backends.base.compute import (
1413
Compute,
1514
ComputeWithCreateInstanceSupport,

src/dstack/_internal/core/backends/aws/config.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/dstack/_internal/core/backends/aws/configurator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
from dstack._internal.core.backends.aws import auth, compute, resources
88
from dstack._internal.core.backends.aws.backend import AWSBackend
9-
from dstack._internal.core.backends.aws.config import AWSConfig
109
from dstack._internal.core.backends.aws.models import (
1110
AnyAWSBackendConfig,
1211
AWSAccessKeyCreds,
1312
AWSBackendConfig,
1413
AWSBackendConfigWithCreds,
14+
AWSConfig,
1515
AWSCreds,
1616
AWSDefaultCreds,
1717
AWSStoredConfig,

src/dstack/_internal/core/backends/aws/models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,19 @@ class AWSBackendConfigWithCreds(AWSBackendConfig):
117117

118118
class AWSStoredConfig(AWSBackendConfig):
119119
pass
120+
121+
122+
class AWSConfig(AWSStoredConfig):
123+
creds: AnyAWSCreds
124+
125+
@property
126+
def allocate_public_ips(self) -> bool:
127+
if self.public_ips is not None:
128+
return self.public_ips
129+
return True
130+
131+
@property
132+
def use_default_vpcs(self) -> bool:
133+
if self.default_vpcs is not None:
134+
return self.default_vpcs
135+
return True

src/dstack/_internal/core/backends/azure/backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dstack._internal.core.backends.azure import auth
22
from dstack._internal.core.backends.azure.compute import AzureCompute
3-
from dstack._internal.core.backends.azure.config import AzureConfig
3+
from dstack._internal.core.backends.azure.models import AzureConfig
44
from dstack._internal.core.backends.base.backend import Backend
55
from dstack._internal.core.models.backends.base import BackendType
66

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from dstack._internal import settings
3737
from dstack._internal.core.backends.azure import resources as azure_resources
3838
from dstack._internal.core.backends.azure import utils as azure_utils
39-
from dstack._internal.core.backends.azure.config import AzureConfig
39+
from dstack._internal.core.backends.azure.models import AzureConfig
4040
from dstack._internal.core.backends.base.compute import (
4141
Compute,
4242
ComputeWithCreateInstanceSupport,

src/dstack/_internal/core/backends/azure/config.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/dstack/_internal/core/backends/azure/configurator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
from dstack._internal.core.backends.azure import auth, compute, resources
2323
from dstack._internal.core.backends.azure import utils as azure_utils
2424
from dstack._internal.core.backends.azure.backend import AzureBackend
25-
from dstack._internal.core.backends.azure.config import AzureConfig
2625
from dstack._internal.core.backends.azure.models import (
2726
AnyAzureBackendConfig,
2827
AzureBackendConfig,
2928
AzureBackendConfigWithCreds,
3029
AzureClientCreds,
30+
AzureConfig,
3131
AzureCreds,
3232
AzureDefaultCreds,
3333
AzureStoredConfig,

0 commit comments

Comments
 (0)