@@ -75,20 +75,6 @@ func (p *ports) Set(value string) error {
75
75
return nil
76
76
}
77
77
78
- type packageUpgrade string
79
-
80
- func (p * packageUpgrade ) String () string {
81
- return string (* p )
82
- }
83
-
84
- func (p * packageUpgrade ) Set (value string ) error {
85
- if value != "true" && value != "false" {
86
- return fmt .Errorf ("--package-update parameter should be true or false" )
87
- }
88
- * p = packageUpgrade (value )
89
- return nil
90
- }
91
-
92
78
type drives []drive
93
79
94
80
func (d * drives ) String () string {
@@ -142,9 +128,10 @@ func checkDirectory(dir string) error {
142
128
return nil
143
129
}
144
130
145
- func createFlags (ctx context.Context , ws * workspace ) (* workload , bool , error ) {
131
+ // CreateFlags parses the flags to the create command
132
+ func CreateFlags () (string , bool , bool , VMSpec , error ) {
146
133
var debug bool
147
- var update packageUpgrade
134
+ var update bool
148
135
var customSpec VMSpec
149
136
fs := flag .NewFlagSet ("create" , flag .ExitOnError )
150
137
fs .Usage = func () {
@@ -154,74 +141,72 @@ func createFlags(ctx context.Context, ws *workspace) (*workload, bool, error) {
154
141
}
155
142
vmFlags (fs , & customSpec )
156
143
fs .BoolVar (& debug , "debug" , false , "Enables debug mode" )
157
- fs .Var (& update , "package-upgrade" ,
144
+ fs .BoolVar (& update , "package-upgrade" , false ,
158
145
"Hint to enable or disable update of VM packages. Should be true or false" )
159
146
160
147
if err := fs .Parse (flag .Args ()[1 :]); err != nil {
161
- return nil , false , err
148
+ return "" , debug , update , customSpec , err
162
149
}
163
150
164
151
if fs .NArg () != 1 {
165
152
fs .Usage ()
166
- return nil , false , errors .New ("no workload specified" )
153
+ return "" , debug , update , customSpec , errors .New ("no workload specified" )
167
154
}
168
155
workloadName := fs .Arg (0 )
169
156
170
- wkl , err := createWorkload (ctx , ws , workloadName )
171
- if err != nil {
172
- return nil , false , err
173
- }
174
-
175
- in := & wkl .spec .VM
176
-
177
- err = in .mergeCustom (& customSpec )
178
- if err != nil {
179
- return nil , false , err
180
- }
181
-
182
- ws .Mounts = in .Mounts
183
- ws .Hostname = wkl .spec .Hostname
184
- if ws .NoProxy != "" {
185
- ws .NoProxy = fmt .Sprintf ("%s,%s" , ws .Hostname , ws .NoProxy )
186
- } else if ws .HTTPProxy != "" || ws .HTTPSProxy != "" {
187
- ws .NoProxy = ws .Hostname
188
- }
189
- ws .PackageUpgrade = string (update )
190
-
191
- return wkl , debug , nil
157
+ return workloadName , debug , update , customSpec , nil
192
158
}
193
159
194
- func startFlags (in * VMSpec ) error {
195
- customSpec := * in
160
+ // StartFlags parsed the flags for the start command
161
+ func StartFlags () (VMSpec , error ) {
162
+ var customSpec VMSpec
196
163
197
164
fs := flag .NewFlagSet ("start" , flag .ExitOnError )
198
165
vmFlags (fs , & customSpec )
199
166
if err := fs .Parse (flag .Args ()[1 :]); err != nil {
200
- return err
167
+ return customSpec , err
201
168
}
202
169
203
- return in . mergeCustom ( & customSpec )
170
+ return customSpec , nil
204
171
}
205
172
206
173
// Create sets up the VM
207
- func Create (ctx context.Context ) error {
174
+ func Create (ctx context.Context , workloadName string , debug bool , update bool , customSpec * VMSpec ) error {
208
175
var err error
209
176
210
177
ws , err := prepareEnv (ctx )
211
178
if err != nil {
212
179
return err
213
180
}
214
181
215
- wkld , debug , err := createFlags (ctx , ws )
182
+ wkld , err := createWorkload (ctx , ws , workloadName )
216
183
if err != nil {
217
184
return err
218
185
}
219
186
187
+ in := & wkld .spec .VM
188
+
189
+ err = in .mergeCustom (customSpec )
190
+ if err != nil {
191
+ return err
192
+ }
193
+
194
+ ws .Mounts = in .Mounts
195
+ ws .Hostname = wkld .spec .Hostname
196
+ if ws .NoProxy != "" {
197
+ ws .NoProxy = fmt .Sprintf ("%s,%s" , ws .Hostname , ws .NoProxy )
198
+ } else if ws .HTTPProxy != "" || ws .HTTPSProxy != "" {
199
+ ws .NoProxy = ws .Hostname
200
+ }
201
+ ws .PackageUpgrade = "false"
202
+ if update {
203
+ ws .PackageUpgrade = "true"
204
+ }
205
+
220
206
if wkld .spec .NeedsNestedVM && ! hostSupportsNestedKVM () {
221
207
return fmt .Errorf ("nested KVM is not enabled. Please enable and try again" )
222
208
}
223
209
224
- in := & wkld .spec .VM
225
210
_ , err = os .Stat (ws .instanceDir )
226
211
if err == nil {
227
212
return fmt .Errorf ("instance already exists" )
@@ -286,7 +271,7 @@ func Create(ctx context.Context) error {
286
271
}
287
272
288
273
// Start launches the VM
289
- func Start (ctx context.Context ) error {
274
+ func Start (ctx context.Context , customSpec * VMSpec ) error {
290
275
ws , err := prepareEnv (ctx )
291
276
if err != nil {
292
277
return err
@@ -298,6 +283,11 @@ func Start(ctx context.Context) error {
298
283
}
299
284
in := & wkld .spec .VM
300
285
286
+ err = in .mergeCustom (customSpec )
287
+ if err != nil {
288
+ return err
289
+ }
290
+
301
291
memGiB , CPUs := getMemAndCpus ()
302
292
if in .MemGiB == 0 {
303
293
in .MemGiB = memGiB
@@ -306,11 +296,6 @@ func Start(ctx context.Context) error {
306
296
in .CPUs = CPUs
307
297
}
308
298
309
- err = startFlags (in )
310
- if err != nil {
311
- return err
312
- }
313
-
314
299
if wkld .spec .NeedsNestedVM && ! hostSupportsNestedKVM () {
315
300
return fmt .Errorf ("nested KVM is not enabled. Please enable and try again" )
316
301
}
0 commit comments