@@ -24,11 +24,18 @@ func (s *API) CreateServer(req *CreateServerRequest, opts ...scw.RequestOption)
2424 // If image is not a UUID we try to fetch it from marketplace.
2525 if req .Image != nil && ! validation .IsUUID (* req .Image ) {
2626 apiMarketplace := marketplace .NewAPI (s .client )
27- image , err := apiMarketplace .GetLocalImageByLabel (& marketplace.GetLocalImageByLabelRequest {
27+
28+ getLocalImageByLabelRequest := & marketplace.GetLocalImageByLabelRequest {
2829 ImageLabel : * req .Image ,
2930 Zone : req .Zone ,
3031 CommercialType : req .CommercialType ,
31- })
32+ }
33+
34+ if bootVolumeType := getBootVolumeType (req .Volumes ); bootVolumeType != nil {
35+ getLocalImageByLabelRequest .Type = * bootVolumeType
36+ }
37+
38+ image , err := apiMarketplace .GetLocalImageByLabel (getLocalImageByLabelRequest )
3239 if err != nil {
3340 return nil , err
3441 }
@@ -38,6 +45,36 @@ func (s *API) CreateServer(req *CreateServerRequest, opts ...scw.RequestOption)
3845 return s .createServer (req , opts ... )
3946}
4047
48+ func getBootVolumeType (volumes map [string ]* VolumeServerTemplate ) * marketplace.LocalImageType {
49+ var bootVolumeType marketplace.LocalImageType
50+ foundBootVolume := false
51+
52+ for _ , volume := range volumes {
53+ if volume .Boot == nil {
54+ continue
55+ }
56+ if * volume .Boot {
57+ foundBootVolume = true
58+ switch volume .VolumeType {
59+ case VolumeVolumeTypeSbsVolume :
60+ bootVolumeType = marketplace .LocalImageTypeInstanceSbs
61+ case VolumeVolumeTypeLSSD :
62+ bootVolumeType = marketplace .LocalImageTypeInstanceLocal
63+ }
64+ }
65+ }
66+
67+ if ! foundBootVolume && len (volumes ) > 0 {
68+ switch volumes ["0" ].VolumeType {
69+ case VolumeVolumeTypeSbsVolume :
70+ bootVolumeType = marketplace .LocalImageTypeInstanceSbs
71+ case VolumeVolumeTypeLSSD :
72+ bootVolumeType = marketplace .LocalImageTypeInstanceLocal
73+ }
74+ }
75+ return & bootVolumeType
76+ }
77+
4178// UpdateServer updates a server.
4279//
4380// Note: Implementation is thread-safe.
0 commit comments