Skip to content

Commit 27b08b3

Browse files
committed
cmd/gomote: list swarming builders on create
If a create is issued without a gomote instance type, the gomote client will query the gomote server for all available instance types. This adds the ability to query for swarming builder types. Updates golang/go#61773 For golang/go#61772 Change-Id: If8d9a2d6b0aa509aafd199ec140659cb7d664308 Reviewed-on: https://go-review.googlesource.com/c/build/+/518799 Reviewed-by: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Run-TryBot: Carlos Amedee <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 8e06b07 commit 27b08b3

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

cmd/gomote/create.go

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ func builders() (bt []builderType) {
7878
return
7979
}
8080

81+
func swarmingBuilders() ([]string, error) {
82+
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
83+
client := gomoteServerClient(ctx)
84+
resp, err := client.ListSwarmingBuilders(ctx, &protos.ListSwarmingBuildersRequest{})
85+
if err != nil {
86+
return nil, fmt.Errorf("unable to retrieve swarming builders: %s", err)
87+
}
88+
return resp.Builders, nil
89+
}
90+
8191
func create(args []string) error {
8292
fs := flag.NewFlagSet("create", flag.ContinueOnError)
8393

@@ -91,18 +101,30 @@ func create(args []string) error {
91101
fmt.Fprintln(os.Stderr, "added to that group.")
92102
fs.PrintDefaults()
93103
fmt.Fprintln(os.Stderr, "\nValid types:")
94-
for _, bt := range builders() {
95-
var warn string
96-
if bt.IsReverse {
97-
if bt.ExpectNum > 0 {
98-
warn = fmt.Sprintf(" [limited capacity: %d machines]", bt.ExpectNum)
99-
} else {
100-
warn = " [limited capacity]"
104+
if luciEnabled() {
105+
swarmingBuilders, err := swarmingBuilders()
106+
if err != nil {
107+
fmt.Fprintf(os.Stderr, " %s\n", err)
108+
} else {
109+
for _, builder := range swarmingBuilders {
110+
fmt.Fprintf(os.Stderr, " * %s\n", builder)
111+
}
112+
}
113+
os.Exit(1)
114+
} else {
115+
for _, bt := range builders() {
116+
var warn string
117+
if bt.IsReverse {
118+
if bt.ExpectNum > 0 {
119+
warn = fmt.Sprintf(" [limited capacity: %d machines]", bt.ExpectNum)
120+
} else {
121+
warn = " [limited capacity]"
122+
}
101123
}
124+
fmt.Fprintf(os.Stderr, " * %s%s\n", bt.Name, warn)
102125
}
103-
fmt.Fprintf(os.Stderr, " * %s%s\n", bt.Name, warn)
126+
os.Exit(1)
104127
}
105-
os.Exit(1)
106128
}
107129
var status bool
108130
fs.BoolVar(&status, "status", true, "print regular status updates while waiting")

cmd/gomote/gomote.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ import (
148148
"fmt"
149149
"os"
150150
"sort"
151+
"strconv"
151152

152153
"golang.org/x/build/buildenv"
153154
"golang.org/x/build/buildlet"
@@ -296,3 +297,8 @@ func instanceDoesNotExist(err error) bool {
296297
}
297298
return false
298299
}
300+
301+
func luciEnabled() bool {
302+
on, _ := strconv.ParseBool(os.Getenv("GOMOTELUCI"))
303+
return on
304+
}

0 commit comments

Comments
 (0)