| // Copyright 2015 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| package main |
| |
| import ( |
| "flag" |
| "fmt" |
| "log" |
| "os" |
| "strings" |
| "time" |
| |
| "golang.org/x/build/buildlet" |
| "golang.org/x/build/dashboard" |
| ) |
| |
| func list(args []string) error { |
| fs := flag.NewFlagSet("list", flag.ContinueOnError) |
| fs.Usage = func() { |
| fmt.Fprintln(os.Stderr, "list usage: gomote list") |
| fs.PrintDefaults() |
| os.Exit(1) |
| } |
| fs.Parse(args) |
| if fs.NArg() != 0 { |
| fs.Usage() |
| } |
| |
| cc, err := buildlet.NewCoordinatorClientFromFlags() |
| if err != nil { |
| log.Fatal(err) |
| } |
| rbs, err := cc.RemoteBuildlets() |
| if err != nil { |
| log.Fatal(err) |
| } |
| for _, rb := range rbs { |
| fmt.Printf("%s\t%s\t%s\texpires in %v\n", rb.Name, rb.BuilderType, rb.HostType, rb.Expires.Sub(time.Now())) |
| } |
| |
| return nil |
| } |
| |
| // clientAndConfig returns a buildlet.Client and its build config for |
| // a named remote buildlet (a buildlet connection owned by the build |
| // coordinator). |
| // |
| // As a special case, if name contains '@', the name is expected to be |
| // of the form <build-config-name>@ip[:port]. For example, |
| // "windows-amd64-race@10.0.0.1". |
| func clientAndConf(name string) (bc *buildlet.Client, conf dashboard.BuildConfig, err error) { |
| var ok bool |
| |
| if strings.Contains(name, "@") { |
| f := strings.SplitN(name, "@", 2) |
| if len(f) != 2 { |
| err = fmt.Errorf("unsupported name %q; for @ form expect <build-config-name>@host[:port]", name) |
| return |
| } |
| builderType := f[0] |
| conf, ok = dashboard.Builders[builderType] |
| if !ok { |
| err = fmt.Errorf("unknown builder type %q (name %q)", builderType, name) |
| return |
| } |
| ipPort := f[1] |
| if !strings.Contains(ipPort, ":") { |
| ipPort += ":80" |
| } |
| bc = buildlet.NewClient(ipPort, buildlet.NoKeyPair) |
| return |
| } |
| |
| cc, err := buildlet.NewCoordinatorClientFromFlags() |
| if err != nil { |
| return |
| } |
| |
| rbs, err := cc.RemoteBuildlets() |
| if err != nil { |
| return |
| } |
| for _, rb := range rbs { |
| if rb.Name == name { |
| conf, ok = dashboard.Builders[rb.BuilderType] |
| if !ok { |
| err = fmt.Errorf("builder %q exists, but unknown builder type %q", name, rb.BuilderType) |
| return |
| } |
| break |
| } |
| } |
| if !ok { |
| err = fmt.Errorf("unknown builder %q", name) |
| return |
| } |
| |
| bc, err = cc.NamedBuildlet(name) |
| if err != nil { |
| return |
| } |
| return bc, conf, nil |
| } |