|
8 | 8 | from google.api_core.operation import Operation |
9 | 9 | from google.cloud import tpu_v2 |
10 | 10 |
|
11 | | -import dstack.version as version |
12 | 11 | from dstack._internal.core.errors import BackendError, ComputeError |
13 | 12 | from dstack._internal.core.models.instances import Gpu |
14 | 13 | from dstack._internal.utils.common import remove_prefix |
@@ -119,24 +118,14 @@ def create_instance_struct( |
119 | 118 | subnetwork: Optional[str] = None, |
120 | 119 | allocate_public_ip: bool = True, |
121 | 120 | ) -> compute_v1.Instance: |
122 | | - network_interface = compute_v1.NetworkInterface() |
123 | | - network_interface.network = network |
124 | | - if subnetwork is not None: |
125 | | - network_interface.subnetwork = subnetwork |
126 | | - |
127 | | - if allocate_public_ip: |
128 | | - access = compute_v1.AccessConfig() |
129 | | - access.type_ = compute_v1.AccessConfig.Type.ONE_TO_ONE_NAT.name |
130 | | - access.name = "External NAT" |
131 | | - access.network_tier = access.NetworkTier.PREMIUM.name |
132 | | - network_interface.access_configs = [access] |
133 | | - else: |
134 | | - network_interface.access_configs = [] |
135 | | - |
136 | 121 | instance = compute_v1.Instance() |
137 | | - instance.network_interfaces = [network_interface] |
138 | 122 | instance.name = instance_name |
139 | 123 | instance.machine_type = f"zones/{zone}/machineTypes/{machine_type}" |
| 124 | + instance.network_interfaces = _get_network_interfaces( |
| 125 | + network=network, |
| 126 | + subnetwork=subnetwork, |
| 127 | + allocate_public_ip=allocate_public_ip, |
| 128 | + ) |
140 | 129 |
|
141 | 130 | disk = compute_v1.AttachedDisk() |
142 | 131 | disk.auto_delete = True |
@@ -187,14 +176,45 @@ def create_instance_struct( |
187 | 176 | return instance |
188 | 177 |
|
189 | 178 |
|
190 | | -def get_image_id(cuda: bool) -> str: |
191 | | - if not cuda: |
192 | | - image_name = f"dstack-{version.base_image}" |
| 179 | +def _get_network_interfaces( |
| 180 | + network: str, |
| 181 | + subnetwork: Optional[str], |
| 182 | + allocate_public_ip: bool, |
| 183 | +) -> List[compute_v1.NetworkInterface]: |
| 184 | + network_interface = compute_v1.NetworkInterface() |
| 185 | + network_interface.network = network |
| 186 | + if subnetwork is not None: |
| 187 | + network_interface.subnetwork = subnetwork |
| 188 | + if allocate_public_ip: |
| 189 | + access = compute_v1.AccessConfig() |
| 190 | + access.type_ = compute_v1.AccessConfig.Type.ONE_TO_ONE_NAT.name |
| 191 | + access.name = "External NAT" |
| 192 | + access.network_tier = access.NetworkTier.PREMIUM.name |
| 193 | + network_interface.access_configs = [access] |
193 | 194 | else: |
194 | | - image_name = f"dstack-cuda-{version.base_image}" |
195 | | - image_name = image_name.replace(".", "-") |
| 195 | + network_interface.access_configs = [] |
| 196 | + |
| 197 | + network_interfaces = [network_interface] |
| 198 | + for i in range(1, 9): |
| 199 | + network_interfaces.append( |
| 200 | + compute_v1.NetworkInterface( |
| 201 | + network=f"projects/dstack/global/networks/dstack-test-data-net-{i}", |
| 202 | + subnetwork=f"projects/dstack/regions/europe-west4/subnetworks/dstack-test-data-sub-{i}", |
| 203 | + ) |
| 204 | + ) |
| 205 | + return network_interfaces |
196 | 206 |
|
197 | | - return f"projects/dstack/global/images/{image_name}" |
| 207 | + |
| 208 | +def get_image_id(cuda: bool) -> str: |
| 209 | + # if not cuda: |
| 210 | + # image_name = f"dstack-{version.base_image}" |
| 211 | + # else: |
| 212 | + # image_name = f"dstack-cuda-{version.base_image}" |
| 213 | + # image_name = image_name.replace(".", "-") |
| 214 | + |
| 215 | + # return f"projects/dstack/global/images/{image_name}" |
| 216 | + # return "projects/cos-cloud/global/images/cos-105-17412-535-78" # TCPX |
| 217 | + return "projects/dstack/global/images/slurm-a3mega-20250327t101736z-cloudinit" # TCPXO |
198 | 218 |
|
199 | 219 |
|
200 | 220 | def get_gateway_image_id() -> str: |
|
0 commit comments