trySkipModifyCompute handles the compute step preset logic for modify.
()
| 161 | |
| 162 | // trySkipModifyCompute handles the compute step preset logic for modify. |
| 163 | func (m *modifyModel) trySkipModifyCompute() bool { |
| 164 | if m.presets == nil { |
| 165 | return false |
| 166 | } |
| 167 | |
| 168 | effectiveGPU := m.config.GPUType |
| 169 | if effectiveGPU == "" { |
| 170 | effectiveGPU = strings.ToLower(m.currentInstance.GPUType) |
| 171 | } |
| 172 | |
| 173 | needsCount := len(m.specs.GPUCounts(effectiveGPU)) > 1 |
| 174 | |
| 175 | if !needsCount { |
| 176 | gpuCounts := m.specs.GPUCounts(effectiveGPU) |
| 177 | if len(gpuCounts) > 0 { |
| 178 | m.config.NumGPUs = gpuCounts[0] |
| 179 | } else { |
| 180 | m.config.NumGPUs = 1 |
| 181 | } |
| 182 | if !m.specs.IsSpecAvailable(effectiveGPU, m.config.NumGPUs) { |
| 183 | return false |
| 184 | } |
| 185 | if m.presets.VCPUs == nil { |
| 186 | return false |
| 187 | } |
| 188 | if slices.Contains(m.specs.VCPUOptions(effectiveGPU, m.config.NumGPUs), *m.presets.VCPUs) { |
| 189 | m.config.VCPUs = *m.presets.VCPUs |
| 190 | currentVCPUs, _ := strconv.Atoi(m.currentInstance.CPUCores) |
| 191 | m.config.ComputeChanged = m.config.VCPUs != currentVCPUs |
| 192 | return true |
| 193 | } |
| 194 | return false |
| 195 | } |
| 196 | |
| 197 | // Multi-GPU: need both to fully skip |
| 198 | if m.presets.NumGPUs != nil && m.presets.VCPUs != nil { |
| 199 | if slices.Contains(m.specs.GPUCounts(effectiveGPU), *m.presets.NumGPUs) && |
| 200 | m.specs.IsSpecAvailable(effectiveGPU, *m.presets.NumGPUs) { |
| 201 | vcpuOpts := m.specs.VCPUOptions(effectiveGPU, *m.presets.NumGPUs) |
| 202 | if len(vcpuOpts) == 1 { |
| 203 | m.config.NumGPUs = *m.presets.NumGPUs |
| 204 | m.config.VCPUs = vcpuOpts[0] |
| 205 | currentVCPUs, _ := strconv.Atoi(m.currentInstance.CPUCores) |
| 206 | currentNumGPUs, _ := strconv.Atoi(m.currentInstance.NumGPUs) |
| 207 | m.config.ComputeChanged = (m.config.VCPUs != currentVCPUs) || (m.config.NumGPUs != currentNumGPUs) |
| 208 | return true |
| 209 | } |
| 210 | if slices.Contains(vcpuOpts, *m.presets.VCPUs) { |
| 211 | m.config.NumGPUs = *m.presets.NumGPUs |
| 212 | m.config.VCPUs = *m.presets.VCPUs |
| 213 | currentVCPUs, _ := strconv.Atoi(m.currentInstance.CPUCores) |
| 214 | currentNumGPUs, _ := strconv.Atoi(m.currentInstance.NumGPUs) |
| 215 | m.config.ComputeChanged = (m.config.VCPUs != currentVCPUs) || (m.config.NumGPUs != currentNumGPUs) |
| 216 | return true |
| 217 | } |
| 218 | } |
| 219 | return false |
| 220 | } |
no test coverage detected