@@ -16,13 +16,13 @@ import (
1616 spot "github.com/redhat-developer/mapt/pkg/provider/api/spot"
1717 "github.com/redhat-developer/mapt/pkg/provider/azure"
1818 "github.com/redhat-developer/mapt/pkg/provider/azure/data"
19- "github.com/redhat-developer/mapt/pkg/provider/azure/module/network"
20- virtualmachine "github.com/redhat-developer/mapt/pkg/provider/azure/module/virtual-machine"
19+ "github.com/redhat-developer/mapt/pkg/provider/azure/modules/allocation"
20+ "github.com/redhat-developer/mapt/pkg/provider/azure/modules/network"
21+ virtualmachine "github.com/redhat-developer/mapt/pkg/provider/azure/modules/virtual-machine"
2122 securityGroup "github.com/redhat-developer/mapt/pkg/provider/azure/services/network/security-group"
2223 "github.com/redhat-developer/mapt/pkg/provider/util/command"
2324 "github.com/redhat-developer/mapt/pkg/provider/util/output"
2425 "github.com/redhat-developer/mapt/pkg/util"
25- "github.com/redhat-developer/mapt/pkg/util/logging"
2626 resourcesUtil "github.com/redhat-developer/mapt/pkg/util/resources"
2727)
2828
@@ -53,19 +53,15 @@ type LinuxArgs struct {
5353}
5454
5555type linuxRequest struct {
56- mCtx * mc.Context `validate:"required"`
57- prefix * string
58- location * string
59- vmSizes []string
60- arch * string
61- osType * data.OSType
62- version * string
63- username * string
64- spot * bool
65- spotTolerance * spot.Tolerance
66- spotExcludedRegions []string
67- getUserdata func () (string , error )
68- readinessCommand * string
56+ mCtx * mc.Context `validate:"required"`
57+ prefix * string
58+ arch * string
59+ osType * data.OSType
60+ version * string
61+ allocationData * allocation.AllocationResult
62+ username * string
63+ getUserdata func () (string , error )
64+ readinessCommand * string
6965}
7066
7167func (r * linuxRequest ) validate () error {
@@ -85,30 +81,32 @@ func Create(mCtxArgs *mc.ContextArgs, args *LinuxArgs) (err error) {
8581 }
8682 prefix := util .If (len (args .Prefix ) > 0 , args .Prefix , "main" )
8783 r := & linuxRequest {
88- mCtx : mCtx ,
89- prefix : & prefix ,
90- location : & args .Location ,
91- arch : & args .Arch ,
92- osType : & args .OSType ,
93- version : & args .Version ,
94- username : & args .Username ,
95- spot : & args .Spot ,
96- spotTolerance : & args .SpotTolerance ,
97- spotExcludedRegions : args .SpotExcludedRegions ,
98- getUserdata : args .GetUserdata ,
99- readinessCommand : & args .ReadinessCommand ,
84+ mCtx : mCtx ,
85+ prefix : & prefix ,
86+ arch : & args .Arch ,
87+ osType : & args .OSType ,
88+ version : & args .Version ,
89+ username : & args .Username ,
90+ getUserdata : args .GetUserdata ,
91+ readinessCommand : & args .ReadinessCommand ,
10092 }
101- if len (args .ComputeRequest .ComputeSizes ) > 0 {
102- r .vmSizes = args .ComputeRequest .ComputeSizes
103- } else {
104- vmSizes , err :=
105- data .NewComputeSelector ().Select (args .ComputeRequest )
106- if err != nil {
107- return err
108- }
109- r .vmSizes = vmSizes
93+ ir , err := data .GetImageRef (* r .osType , * r .arch , * r .version )
94+ if err != nil {
95+ return err
96+ }
97+ r .allocationData , err = allocation .Allocation (mCtx ,
98+ & allocation.AllocationArgs {
99+ ComputeRequest : args .ComputeRequest ,
100+ OSType : "linux" ,
101+ ImageRef : ir ,
102+ Location : & args .Location ,
103+ Spot : args .Spot ,
104+ SpotTolerance : & args .SpotTolerance ,
105+ SpotExcludedLocations : args .SpotExcludedRegions ,
106+ })
107+ if err != nil {
108+ return err
110109 }
111- logging .Debug ("Creating Linux Server" )
112110 cs := manager.Stack {
113111 StackName : mCtx .StackNameByProject (stackAzureLinux ),
114112 ProjectName : mCtx .ProjectName (),
@@ -135,14 +133,8 @@ func (r *linuxRequest) deployer(ctx *pulumi.Context) error {
135133 if err := r .validate (); err != nil {
136134 return err
137135 }
138- // Get values for spot machine
139- location , vmType , spotPrice , err := r .valuesCheckingSpot ()
140- if err != nil {
141- return err
142- }
143-
144136 // Get location for creating the Resource Group
145- rgLocation := azure .GetSuitableLocationForResourceGroup (* location )
137+ rgLocation := azure .GetSuitableLocationForResourceGroup (* r . allocationData . Location )
146138 rg , err := resources .NewResourceGroup (ctx ,
147139 resourcesUtil .GetResourceName (* r .prefix , azureLinuxID , "rg" ),
148140 & resources.ResourceGroupArgs {
@@ -154,7 +146,7 @@ func (r *linuxRequest) deployer(ctx *pulumi.Context) error {
154146 return err
155147 }
156148 // Networking
157- sg , err := securityGroups (ctx , r .mCtx , r .prefix , location , rg )
149+ sg , err := securityGroups (ctx , r .mCtx , r .prefix , r . allocationData . Location , rg )
158150 if err != nil {
159151 return err
160152 }
@@ -163,7 +155,7 @@ func (r *linuxRequest) deployer(ctx *pulumi.Context) error {
163155 Prefix : * r .prefix ,
164156 ComponentID : azureLinuxID ,
165157 ResourceGroup : rg ,
166- Location : location ,
158+ Location : r . allocationData . Location ,
167159 SecurityGroup : sg ,
168160 })
169161 if err != nil {
@@ -183,10 +175,6 @@ func (r *linuxRequest) deployer(ctx *pulumi.Context) error {
183175 }
184176 ctx .Export (fmt .Sprintf ("%s-%s" , * r .prefix , outputUserPrivateKey ), privateKey .PrivateKeyPem )
185177 // Image refence info
186- ir , err := data .GetImageRef (* r .osType , * r .arch , * r .version )
187- if err != nil {
188- return err
189- }
190178 var userDataB64 string
191179 if r .getUserdata != nil {
192180 var err error
@@ -202,15 +190,17 @@ func (r *linuxRequest) deployer(ctx *pulumi.Context) error {
202190 ComponentID : azureLinuxID ,
203191 ResourceGroup : rg ,
204192 NetworkInteface : n .NetworkInterface ,
205- VMSize : vmType ,
206- Publisher : ir .Publisher ,
207- Offer : ir .Offer ,
208- Sku : ir .Sku ,
209- ImageID : ir .ID ,
210- AdminUsername : * r .username ,
211- PrivateKey : privateKey ,
212- SpotPrice : spotPrice ,
213- Userdata : userDataB64 ,
193+ // Check this
194+ VMSize : r .allocationData .ComputeSizes [0 ],
195+ Publisher : r .allocationData .ImageRef .Publisher ,
196+ Offer : r .allocationData .ImageRef .Offer ,
197+ Sku : r .allocationData .ImageRef .Sku ,
198+ ImageID : r .allocationData .ImageRef .ID ,
199+ AdminUsername : * r .username ,
200+ PrivateKey : privateKey ,
201+ SpotPrice : r .allocationData .Price ,
202+ Userdata : userDataB64 ,
203+ Location : * r .allocationData .Location ,
214204 })
215205 if err != nil {
216206 return err
@@ -242,31 +232,6 @@ func (r *linuxRequest) deployer(ctx *pulumi.Context) error {
242232 return err
243233}
244234
245- func (r * linuxRequest ) valuesCheckingSpot () (* string , string , * float64 , error ) {
246- if * r .spot {
247- ir , err := data .GetImageRef (* r .osType , * r .arch , * r .version )
248- if err != nil {
249- return nil , "" , nil , err
250- }
251- bsc , err :=
252- data .SpotInfo (
253- r .mCtx ,
254- & data.SpotInfoArgs {
255- ComputeSizes : util .If (len (r .vmSizes ) > 0 , r .vmSizes , []string {defaultVMSize }),
256- OSType : "linux" ,
257- // EvictionRateTolerance: r.SpotTolerance,
258- ImageRef : * ir ,
259- ExcludedLocations : r .spotExcludedRegions ,
260- })
261- logging .Debugf ("Best spot price option found: %v" , bsc )
262- if err != nil {
263- return nil , "" , nil , err
264- }
265- return & bsc .HostingPlace , bsc .ComputeType , & bsc .Price , nil
266- }
267- return r .location , "" , nil , nil
268- }
269-
270235// security group for mac machine with ingress rules for ssh and vnc
271236func securityGroups (ctx * pulumi.Context , mCtx * mc.Context ,
272237 prefix , location * string ,
0 commit comments