You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contributing/BACKENDS.md
+35-37Lines changed: 35 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,69 +84,67 @@ See the Appendix at the end of this document and make sure the provider meets th
84
84
85
85
#### 2.2. Set up the development environment
86
86
87
-
Follow [DEVELOPMENT.md](DEVELOPMENT.md)`.
87
+
Follow [DEVELOPMENT.md](DEVELOPMENT.md).
88
88
89
89
#### 2.3. Add dependencies to setup.py
90
90
91
91
Add any dependencies required by your cloud provider to `setup.py`. Create a separate section with the provider's name for these dependencies, and ensure that you update the `all` section to include them as well.
92
92
93
-
#### 2.4. Implement the provider backend
93
+
#### 2.4. Add a new backend type
94
94
95
-
##### 2.4.1. Define the backend type
95
+
Add a new enumeration member for your provider to `BackendType` ([`src/dstack/_internal/core/models/backends/base.py`](https://github.com/dstackai/dstack/blob/master/src/dstack/_internal/core/models/backends/base.py)).
96
96
97
-
Add a new enumeration member for your provider to `BackendType` (`src/dstack/_internal/core/models/backends/base.py`).
98
-
Use the name of the provider.
97
+
#### 2.5. Create backend files and classes
99
98
100
-
##### 2.4.2. Create the backend directory
99
+
`dstack` provides a helper script to generate all the necessary files and classes for a new backend.
100
+
To add a new backend named `ExampleXYZ`, you should run:
101
101
102
-
Create a new directory under `src/dstack/_internal/core/backends` with the name of the backend type.
103
-
104
-
##### 2.4.3. Create the backend class
105
-
106
-
Under the backend directory you've created, create the `backend.py` file and define the
107
-
backend class there (should extend `dstack._internal.core.backends.base.Backend`).
[azure](https://github.com/dstackai/dstack/blob/master/src/dstack/_internal/core/backends/azure/backend.py), etc.
102
+
```shell
103
+
python scripts/add_backend.py -n ExampleXYZ
104
+
```
114
105
115
-
##### 2.4.4. Create the backend compute class
106
+
It will create an `examplexyz`backend directory under `src/dstack/_internal/core/backends` with the following files:
116
107
117
-
Under the backend directory you've created, create the `compute.py` file and define the
118
-
backend compute class that extends the `dstack._internal.core.backends.base.compute.Compute` class.
119
-
It can also extend and implement `ComputeWith*` classes to support additional features such as fleets, volumes, gateways, placement groups, etc. For example, it should extend `ComputeWithCreateInstanceSupport` to support fleets.
108
+
*`backend.py` with the `Backend` class implementation. You typically don't need to modify it.
109
+
*`compute.py` with the `Compute` class implementation. This is the core of the backend that you need to implement.
110
+
*`configurator.py` with the `Configurator` class implementation. It deals with validating and storing backend config. You need to adjust it with custom backend config validation.
111
+
*`models.py` with all the backend config models used by `Backend`, `Compute`, `Configurator` and other parts of `dstack`.
[azure](https://github.com/dstackai/dstack/blob/master/src/dstack/_internal/core/backends/azure/compute.py), etc.
113
+
##### 2.6. Adjust and register the backend config models
126
114
127
-
##### 2.4.5. Create and register the backend config models
128
-
129
-
Under the backend directory, create the `models.py` file and define the backend config model classes there.
130
-
Every backend must define at least two models:
115
+
Go to `models.py`. It'll contain two config models required for all backends:
131
116
132
117
*`*BackendConfig` that contains all backend parameters available for user configuration except for creds.
133
118
*`*BackendConfigWithCreds` that contains all backends parameters available for user configuration and also creds.
134
119
135
-
These models are used in server/config.yaml, the API, and for backend configuration.
120
+
Adjust generated config models by adding additional config parameters.
121
+
Typically you'd need to only modify the `*BackendConfig` model since other models extend it.
136
122
137
-
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).
123
+
Then add these models 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).
138
124
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.
125
+
The script also generates`*BackendStoredConfig` that extends `*BackendConfig` to be able to store extra parameters in the DB. By the same logic, it generates `*Config` that extends `*BackendStoredConfig` with creds and uses it as the main `Backend` and `Compute` config instead of using `*BackendConfigWithCreds` directly.
[azure](https://github.com/dstackai/dstack/blob/master/src/dstack/_internal/core/backends/models.py), etc.
146
132
147
-
##### 2.4.6. Create and register the configurator class
133
+
##### 2.7. Implement the backend compute class
134
+
135
+
Go to `compute.py` and implement `Compute` methods.
136
+
Optionally, extend and implement `ComputeWith*` classes to support additional features such as fleets, volumes, gateways, placement groups, etc. For example, extend `ComputeWithCreateInstanceSupport` to support fleets.
[azure](https://github.com/dstackai/dstack/blob/master/src/dstack/_internal/core/backends/azure/compute.py), etc.
143
+
144
+
##### 2.8. Implement and register the configurator class
148
145
149
-
Under the backend directory, create the `configurator.py` file and and define the backend configurator class (must extend `dstack._internal.core.backends.base.configurator.Configurator`).
146
+
Go to `configurator.py` and implement custom `Configurator` logic. At minimum, you should implement creds validation.
147
+
You may also need to validate other config parameters if there are any.
150
148
151
149
Refer to examples: [datacrunch](https://github.com/dstackai/dstack/blob/master/src/dstack/_internal/core/backends/datacrunch/configurator.py),
@@ -155,7 +153,7 @@ Refer to examples: [datacrunch](https://github.com/dstackai/dstack/blob/master/s
155
153
156
154
Register configurator by appending it to `_CONFIGURATOR_CLASSES` in [`src/dstack/_internal/core/backends/configurators.py`](https://github.com/dstackai/dstack/blob/master/src/dstack/_internal/core/backends/configurators.py).
0 commit comments