@@ -162,43 +162,53 @@ func (c *cvdCreator) Create() ([]*hoapi.CVD, error) {
162162 return c .createCVDFromAndroidCI ()
163163}
164164
165- const uaEnvConfigTmplStr = `
166- {
167- "common": {
168- "host_package": "{{.HostPkg}}"
169- },
170- "instances": [
171- {
172- "vm": {
173- "memory_mb": 8192,
174- "setupwizard_mode": "OPTIONAL",
175- "cpus": 8
176- },
177- "disk": {
178- "default_build": "{{.Artifacts}}"
179- }
180- }
181- ]
182- }
183- `
184-
185165var uaEnvConfigTmpl * template.Template
186166
187167func init () {
188- var err error
189- if uaEnvConfigTmpl , err = template .New ("" ).Parse (uaEnvConfigTmplStr ); err != nil {
190- panic (err )
168+ const uaEnvConfigTmplStr = `
169+ {
170+ "common": {
171+ "host_package": "{{.HostPkg}}"
172+ },
173+ "instances": [
174+ {{range $idx, $_ := .Instances}}{{if gt $idx 0}}, {{end}}{{template "uaInstanceConfig" .}}{{end}}
175+ ]
176+ }
177+ `
178+ const uaInstanceConfigTmplStr = `
179+ {
180+ "vm": {
181+ "memory_mb": 8192,
182+ "setupwizard_mode": "OPTIONAL",
183+ "cpus": 8
184+ },
185+ "disk": {
186+ "default_build": "{{.Artifacts}}"
187+ }
191188 }
189+ `
190+ uaEnvConfigTmpl = template .Must (template .New ("" ).Parse (uaEnvConfigTmplStr ))
191+ template .Must (uaEnvConfigTmpl .New ("uaInstanceConfig" ).Parse (uaInstanceConfigTmplStr ))
192192}
193193
194- type uaEnvConfigTmplData struct {
194+ type uaInstanceConfigTmplData struct {
195195 Artifacts string
196+ }
197+
198+ type uaEnvConfigTmplData struct {
199+ Instances []* uaInstanceConfigTmplData
196200 HostPkg string
197201}
198202
199- func buildUAEnvConfig (artifacts []string , hostPkg string ) (map [string ]interface {}, error ) {
203+ func buildUAEnvConfig (artifacts []string , hostPkg string , numInstance int ) (map [string ]interface {}, error ) {
200204 var b bytes.Buffer
201- if err := uaEnvConfigTmpl .Execute (& b , uaEnvConfigTmplData {Artifacts : strings .Join (artifacts , "," ), HostPkg : hostPkg }); err != nil {
205+ instance := uaInstanceConfigTmplData {Artifacts : strings .Join (artifacts , "," )}
206+ instances := make ([]* uaInstanceConfigTmplData , numInstance )
207+ for idx := 0 ; idx < numInstance ; idx ++ {
208+ instances [idx ] = & instance
209+ }
210+ config := uaEnvConfigTmplData {Instances : instances , HostPkg : hostPkg }
211+ if err := uaEnvConfigTmpl .Execute (& b , config ); err != nil {
202212 return nil , fmt .Errorf ("failed to fulfill template: %w" , err )
203213 }
204214
@@ -239,7 +249,7 @@ func (c *cvdCreator) createCVDFromLocalBuild() ([]*hoapi.CVD, error) {
239249 if err := verifyCVDHostPackageTar (hostOut ); err != nil {
240250 return nil , err
241251 }
242- envConfig , err := buildUAEnvConfig (artifacts , filepath .Join (hostOut , CVDHostPackageName ))
252+ envConfig , err := buildUAEnvConfig (artifacts , filepath .Join (hostOut , CVDHostPackageName ), c . opts . NumInstances )
243253 if err != nil {
244254 return nil , err
245255 }
@@ -422,7 +432,7 @@ func (c *cvdCreator) createCVDFromLocalSrcs() ([]*hoapi.CVD, error) {
422432 if err := c .opts .CreateCVDLocalOpts .validate (); err != nil {
423433 return nil , fmt .Errorf ("invalid local source: %w" , err )
424434 }
425- envConfig , err := buildUAEnvConfig (c .opts .CreateCVDLocalOpts .artifacts (), c .opts .CreateCVDLocalOpts .LocalCVDHostPkgSrc )
435+ envConfig , err := buildUAEnvConfig (c .opts .CreateCVDLocalOpts .artifacts (), c .opts .CreateCVDLocalOpts .LocalCVDHostPkgSrc , c . opts . NumInstances )
426436 if err != nil {
427437 return nil , err
428438 }
0 commit comments