@@ -170,25 +170,22 @@ func StartFlags() (VMSpec, error) {
170
170
return customSpec , nil
171
171
}
172
172
173
- // Create sets up the VM
174
- func Create (ctx context.Context , workloadName string , debug bool , update bool , customSpec * VMSpec ) error {
175
- var err error
176
-
173
+ func prepareCreate (ctx context.Context , workloadName string , debug bool , update bool , customSpec * VMSpec ) (* workload , * workspace , error ) {
177
174
ws , err := prepareEnv (ctx )
178
175
if err != nil {
179
- return err
176
+ return nil , nil , err
180
177
}
181
178
182
179
wkld , err := createWorkload (ctx , ws , workloadName )
183
180
if err != nil {
184
- return err
181
+ return nil , nil , err
185
182
}
186
183
187
184
in := & wkld .spec .VM
188
185
189
186
err = in .mergeCustom (customSpec )
190
187
if err != nil {
191
- return err
188
+ return nil , nil , err
192
189
}
193
190
194
191
ws .Mounts = in .Mounts
@@ -198,13 +195,26 @@ func Create(ctx context.Context, workloadName string, debug bool, update bool, c
198
195
} else if ws .HTTPProxy != "" || ws .HTTPSProxy != "" {
199
196
ws .NoProxy = ws .Hostname
200
197
}
198
+
201
199
ws .PackageUpgrade = "false"
202
200
if update {
203
201
ws .PackageUpgrade = "true"
204
202
}
205
203
206
204
if wkld .spec .NeedsNestedVM && ! hostSupportsNestedKVM () {
207
- return fmt .Errorf ("nested KVM is not enabled. Please enable and try again" )
205
+ return nil , nil , fmt .Errorf ("nested KVM is not enabled. Please enable and try again" )
206
+ }
207
+
208
+ return wkld , ws , nil
209
+ }
210
+
211
+ // Create sets up the VM
212
+ func Create (ctx context.Context , workloadName string , debug bool , update bool , customSpec * VMSpec ) error {
213
+ var err error
214
+
215
+ wkld , ws , err := prepareCreate (ctx , workloadName , debug , update , customSpec )
216
+ if err != nil {
217
+ return err
208
218
}
209
219
210
220
_ , err = os .Stat (ws .instanceDir )
@@ -252,9 +262,10 @@ func Create(ctx context.Context, workloadName string, debug bool, update bool, c
252
262
return err
253
263
}
254
264
255
- fmt .Printf ("Booting VM with %d GB RAM and %d cpus\n " , in .MemGiB , in .CPUs )
265
+ spec := wkld .spec .VM
266
+ fmt .Printf ("Booting VM with %d GB RAM and %d cpus\n " , spec .MemGiB , spec .CPUs )
256
267
257
- err = bootVM (ctx , ws , in )
268
+ err = bootVM (ctx , ws , & spec )
258
269
if err != nil {
259
270
return err
260
271
}
0 commit comments