@@ -11,37 +11,37 @@ import (
1111
1212// Create schedules a new unit for the given component
1313// and blocks until the unit is loaded
14- func (c * FleetClient ) Create (target string ) (err error ) {
15- var (
16- unitName string
17- unitFile * unit.UnitFile
18- )
19- // create unit file
20- unitName , unitFile , err = c .createUnitFile (target )
21- if err != nil {
22- return err
23- }
24- // define unit
25- u := & schema.Unit {
26- Name : unitName ,
27- Options : schema .MapUnitFileToSchemaUnitOptions (unitFile ),
28- }
29- // schedule unit
30- if err := c .Fleet .CreateUnit (u ); err != nil {
31- // ignore units that already exist
32- if err .Error () != "job already exists" {
33- return fmt .Errorf ("failed creating job %s: %v" , unitName , err )
14+ func (c * FleetClient ) Create (targets []string ) error {
15+ units := make ([]* schema.Unit , len (targets ))
16+ for i , target := range targets {
17+ unitName , unitFile , err := c .createUnitFile (target )
18+ if err != nil {
19+ return err
20+ }
21+ units [i ] = & schema.Unit {
22+ Name : unitName ,
23+ Options : schema .MapUnitFileToSchemaUnitOptions (unitFile ),
3424 }
3525 }
36- desiredState := string (job .JobStateLoaded )
37- err = c .Fleet .SetUnitTargetState (unitName , desiredState )
38- if err != nil {
39- return err
26+ for _ , unit := range units {
27+ // schedule unit
28+ if err := c .Fleet .CreateUnit (unit ); err != nil {
29+ // ignore units that already exist
30+ if err .Error () != "job already exists" {
31+ return fmt .Errorf ("failed creating job %s: %v" , unit .Name , err )
32+ }
33+ }
34+ desiredState := string (job .JobStateLoaded )
35+ if err := c .Fleet .SetUnitTargetState (unit .Name , desiredState ); err != nil {
36+ return err
37+ }
4038 }
41- outchan , errchan := waitForUnitStates ([]string {unitName }, desiredState )
42- err = printUnitState (unitName , outchan , errchan )
43- if err != nil {
44- return err
39+ for _ , unit := range units {
40+ desiredState := string (job .JobStateLoaded )
41+ outchan , errchan := waitForUnitStates ([]string {unit .Name }, desiredState )
42+ if err := printUnitState (unit .Name , outchan , errchan ); err != nil {
43+ return err
44+ }
4545 }
4646 return nil
4747}
0 commit comments