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 <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/cmd/gomote/create.go b/cmd/gomote/create.go
index 58bd50f..4d5e87a 100644
--- a/cmd/gomote/create.go
+++ b/cmd/gomote/create.go
@@ -78,6 +78,16 @@
return
}
+func swarmingBuilders() ([]string, error) {
+ ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+ client := gomoteServerClient(ctx)
+ resp, err := client.ListSwarmingBuilders(ctx, &protos.ListSwarmingBuildersRequest{})
+ if err != nil {
+ return nil, fmt.Errorf("unable to retrieve swarming builders: %s", err)
+ }
+ return resp.Builders, nil
+}
+
func create(args []string) error {
fs := flag.NewFlagSet("create", flag.ContinueOnError)
@@ -91,18 +101,30 @@
fmt.Fprintln(os.Stderr, "added to that group.")
fs.PrintDefaults()
fmt.Fprintln(os.Stderr, "\nValid types:")
- for _, bt := range builders() {
- var warn string
- if bt.IsReverse {
- if bt.ExpectNum > 0 {
- warn = fmt.Sprintf(" [limited capacity: %d machines]", bt.ExpectNum)
- } else {
- warn = " [limited capacity]"
+ if luciEnabled() {
+ swarmingBuilders, err := swarmingBuilders()
+ if err != nil {
+ fmt.Fprintf(os.Stderr, " %s\n", err)
+ } else {
+ for _, builder := range swarmingBuilders {
+ fmt.Fprintf(os.Stderr, " * %s\n", builder)
}
}
- fmt.Fprintf(os.Stderr, " * %s%s\n", bt.Name, warn)
+ os.Exit(1)
+ } else {
+ for _, bt := range builders() {
+ var warn string
+ if bt.IsReverse {
+ if bt.ExpectNum > 0 {
+ warn = fmt.Sprintf(" [limited capacity: %d machines]", bt.ExpectNum)
+ } else {
+ warn = " [limited capacity]"
+ }
+ }
+ fmt.Fprintf(os.Stderr, " * %s%s\n", bt.Name, warn)
+ }
+ os.Exit(1)
}
- os.Exit(1)
}
var status bool
fs.BoolVar(&status, "status", true, "print regular status updates while waiting")
diff --git a/cmd/gomote/gomote.go b/cmd/gomote/gomote.go
index 0004eb7..eb626c4 100644
--- a/cmd/gomote/gomote.go
+++ b/cmd/gomote/gomote.go
@@ -148,6 +148,7 @@
"fmt"
"os"
"sort"
+ "strconv"
"golang.org/x/build/buildenv"
"golang.org/x/build/buildlet"
@@ -296,3 +297,8 @@
}
return false
}
+
+func luciEnabled() bool {
+ on, _ := strconv.ParseBool(os.Getenv("GOMOTELUCI"))
+ return on
+}