@@ -291,10 +291,6 @@ func instanceServerCreateRun(ctx context.Context, argsI interface{}) (i interfac
291
291
return nil , err
292
292
}
293
293
294
- if serverType != nil {
295
- volumes = addDefaultVolumes (serverType , volumes )
296
- }
297
-
298
294
// Validate root volume type and size.
299
295
if getImageResponse != nil {
300
296
if err := validateRootVolume (getImageResponse .Image .RootVolume .Size , volumes ["0" ]); err != nil {
@@ -317,6 +313,11 @@ func instanceServerCreateRun(ctx context.Context, argsI interface{}) (i interfac
317
313
serverReq .Volumes = sanitizeVolumeMap (serverReq .Name , volumes )
318
314
}
319
315
316
+ // Add default volumes to server, ex: scratch storage for GPU servers
317
+ if serverType != nil {
318
+ serverReq .Volumes = addDefaultVolumes (serverType , serverReq .Volumes )
319
+ }
320
+
320
321
//
321
322
// BootType.
322
323
//
@@ -440,6 +441,7 @@ func instanceServerCreateRun(ctx context.Context, argsI interface{}) (i interfac
440
441
func addDefaultVolumes (serverType * instance.ServerType , volumes map [string ]* instance.VolumeServerTemplate ) map [string ]* instance.VolumeServerTemplate {
441
442
needScratch := false
442
443
hasScratch := false
444
+ defaultVolumes := []* instance.VolumeServerTemplate (nil )
443
445
if serverType .ScratchStorageMaxSize != nil && * serverType .ScratchStorageMaxSize > 0 {
444
446
needScratch = true
445
447
}
@@ -450,11 +452,26 @@ func addDefaultVolumes(serverType *instance.ServerType, volumes map[string]*inst
450
452
}
451
453
452
454
if needScratch && ! hasScratch {
453
- volumeKey := strconv .Itoa (len (volumes ))
454
- volumes [volumeKey ] = & instance.VolumeServerTemplate {
455
+ if volumes == nil {
456
+ volumes = make (map [string ]* instance.VolumeServerTemplate )
457
+ }
458
+ defaultVolumes = append (defaultVolumes , & instance.VolumeServerTemplate {
455
459
Name : scw .StringPtr ("default-cli-scratch-volume" ),
456
460
Size : serverType .ScratchStorageMaxSize ,
457
461
VolumeType : instance .VolumeVolumeTypeScratch ,
462
+ })
463
+ }
464
+
465
+ if defaultVolumes != nil {
466
+ maxKey := 1
467
+ for k , _ := range volumes {
468
+ key , err := strconv .Atoi (k )
469
+ if err == nil && key > maxKey {
470
+ maxKey = key
471
+ }
472
+ }
473
+ for i , vol := range defaultVolumes {
474
+ volumes [strconv .Itoa (maxKey + i )] = vol
458
475
}
459
476
}
460
477
0 commit comments