本文整理匯總了Golang中github.com/flynn/flynn/pkg/cluster.Client類的典型用法代碼示例。如果您正苦於以下問題:Golang Client類的具體用法?Golang Client怎麽用?Golang Client使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Client類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: jobList
func jobList(client *cluster.Client, all bool) (sortJobs, error) {
hosts, err := client.Hosts()
if err != nil {
return nil, fmt.Errorf("could not list hosts: %s", err)
}
if len(hosts) == 0 {
return nil, errors.New("no hosts found")
}
var jobs []host.ActiveJob
for _, h := range hosts {
hostJobs, err := h.ListJobs()
if err != nil {
return nil, fmt.Errorf("could not get jobs for host %s: %s", h.ID(), err)
}
for _, job := range hostJobs {
jobs = append(jobs, job)
}
}
sorted := make(sortJobs, 0, len(jobs))
for _, job := range jobs {
if !all && job.Status != host.StatusStarting && job.Status != host.StatusRunning {
continue
}
sorted = append(sorted, job)
}
sort.Sort(sort.Reverse(sorted))
return sorted, nil
}
示例2: getLog
func getLog(hostID, jobID string, client *cluster.Client, follow, init bool, stdout, stderr io.Writer) error {
hostClient, err := client.Host(hostID)
if err != nil {
return fmt.Errorf("could not connect to host %s: %s", hostID, err)
}
attachReq := &host.AttachReq{
JobID: jobID,
Flags: host.AttachFlagStdout | host.AttachFlagStderr | host.AttachFlagLogs,
}
if follow {
attachReq.Flags |= host.AttachFlagStream
}
if init {
attachReq.Flags |= host.AttachFlagInitLog
}
attachClient, err := hostClient.Attach(attachReq, false)
if err != nil {
switch err {
case host.ErrJobNotRunning:
return nil
case cluster.ErrWouldWait:
return errors.New("no such job")
}
return err
}
defer attachClient.Close()
_, err = attachClient.Receive(stdout, stderr)
return err
}
示例3: jobList
func jobList(client *cluster.Client, all bool) (sortJobs, error) {
hosts, err := client.ListHosts()
if err != nil {
return nil, fmt.Errorf("could not list hosts: %s", err)
}
var jobs []host.ActiveJob
for id := range hosts {
h, err := client.DialHost(id)
if err != nil {
return nil, fmt.Errorf("could not dial host %s: %s", id, err)
}
hostJobs, err := h.ListJobs()
if err != nil {
return nil, fmt.Errorf("could not get jobs for host %s: %s", id, err)
}
for _, job := range hostJobs {
jobs = append(jobs, job)
}
}
sorted := make(sortJobs, 0, len(jobs))
for _, job := range jobs {
if !all && job.Status != host.StatusStarting && job.Status != host.StatusRunning {
continue
}
sorted = append(sorted, job)
}
sort.Sort(sort.Reverse(sorted))
return sorted, nil
}
示例4: runVolumeList
func runVolumeList(args *docopt.Args, client *cluster.Client) error {
hosts, err := client.Hosts()
if err != nil {
return fmt.Errorf("could not list hosts: %s", err)
}
if len(hosts) == 0 {
return errors.New("no hosts found")
}
volumes, err := clusterVolumes(hosts)
if err != nil {
return err
}
w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
defer w.Flush()
listRec(w,
"ID",
"HOST",
)
for _, volume := range volumes {
listRec(w,
volume.Volume.ID,
volume.Host.ID(),
)
}
return nil
}
示例5: runStop
func runStop(args *docopt.Args, client *cluster.Client) error {
success := true
clients := make(map[string]cluster.Host)
for _, id := range args.All["ID"].([]string) {
hostID, jobID, err := cluster.ParseJobID(id)
if err != nil {
fmt.Printf("could not parse %s: %s", id, err)
success = false
continue
}
hostClient, ok := clients[hostID]
if !ok {
var err error
hostClient, err = client.DialHost(hostID)
if err != nil {
fmt.Printf("could not connect to host %s: %s\n", hostID, err)
success = false
continue
}
clients[hostID] = hostClient
}
if err := hostClient.StopJob(jobID); err != nil {
fmt.Printf("could not stop job %s: %s\n", jobID, err)
success = false
continue
}
fmt.Println(jobID, "stopped")
}
if !success {
return errors.New("could not stop all jobs")
}
return nil
}
示例6: randomHost
func randomHost(cc *cluster.Client) (string, error) {
hosts, err := cc.ListHosts()
if err != nil {
return "", err
}
if len(hosts) == 0 {
return "", cluster.ErrNoServers
}
return schedutil.PickHost(hosts).ID, nil
}
示例7: randomHost
func randomHost(cc *cluster.Client) (string, error) {
hosts, err := cc.ListHosts()
if err != nil {
return "", err
}
for _, host := range hosts {
return host.ID, nil
}
return "", cluster.ErrNoServers
}
示例8: runTagsDel
func runTagsDel(args *docopt.Args, client *cluster.Client) error {
host, err := client.Host(args.String["<hostid>"])
if err != nil {
return err
}
vars := args.All["<var>"].([]string)
tags := make(map[string]string, len(vars))
for _, v := range vars {
// empty tags get deleted on the host
tags[v] = ""
}
return host.UpdateTags(tags)
}
示例9: runVolumeGarbageCollection
func runVolumeGarbageCollection(args *docopt.Args, client *cluster.Client) error {
// collect list of all volume ids currently attached to jobs
hosts, err := client.Hosts()
if err != nil {
return fmt.Errorf("could not list hosts: %s", err)
}
if len(hosts) == 0 {
return errors.New("no hosts found")
}
attached := make(map[string]struct{})
for _, h := range hosts {
jobs, err := h.ListJobs()
if err != nil {
fmt.Printf("error listing jobs on host %s: %s\n", h.ID(), err)
continue
}
for _, j := range jobs {
for _, vb := range j.Job.Config.Volumes {
attached[vb.VolumeID] = struct{}{}
}
}
}
volumes, err := clusterVolumes(hosts)
if err != nil {
return err
}
// iterate over list of all volumes, deleting any not found in the attached list
success := true
outer:
for _, v := range volumes {
if _, ok := attached[v.Volume.ID]; ok {
// volume is attached, continue to next volume
continue outer
}
if err := v.Host.DestroyVolume(v.Volume.ID); err != nil {
success = false
fmt.Printf("could not delete volume %s: %s\n", v.Volume.ID, err)
continue outer
}
fmt.Println(v.Volume.ID, "deleted")
}
if !success {
return errors.New("could not garbage collect all volumes")
}
return nil
}
示例10: runTagsSet
func runTagsSet(args *docopt.Args, client *cluster.Client) error {
host, err := client.Host(args.String["<hostid>"])
if err != nil {
return err
}
pairs := args.All["<var>=<val>"].([]string)
tags := make(map[string]string, len(pairs))
for _, s := range pairs {
keyVal := strings.SplitN(s, "=", 2)
if len(keyVal) == 1 && keyVal[0] != "" {
tags[keyVal[0]] = "true"
} else if len(keyVal) == 2 {
tags[keyVal[0]] = keyVal[1]
}
}
return host.UpdateTags(tags)
}
示例11: runInspect
func runInspect(args *docopt.Args, client *cluster.Client) error {
hostID, jobID, err := cluster.ParseJobID(args.String["ID"])
if err != nil {
return err
}
hostClient, err := client.Host(hostID)
if err != nil {
return fmt.Errorf("could not connect to host %s: %s", hostID, err)
}
job, err := hostClient.GetJob(jobID)
if err != nil {
return fmt.Errorf("no such job")
}
printJobDesc(job, os.Stdout, !args.Bool["--omit-env"])
return nil
}
示例12: runVolumeCreate
func runVolumeCreate(args *docopt.Args, client *cluster.Client) error {
hostId := args.String["<host>"]
hostClient, err := client.Host(hostId)
if err != nil {
fmt.Println("could not connect to host", hostId)
}
provider := "default"
if args.String["--provider"] != "" {
provider = args.String["--provider"]
}
v, err := hostClient.CreateVolume(provider)
if err != nil {
fmt.Printf("could not create volume: %s\n", err)
return err
}
fmt.Printf("created volume %s on %s\n", v.ID, hostId)
return nil
}
示例13: runVolumeList
func runVolumeList(args *docopt.Args, client *cluster.Client) error {
hosts, err := client.Hosts()
if err != nil {
return fmt.Errorf("could not list hosts: %s", err)
}
if len(hosts) == 0 {
return errors.New("no hosts found")
}
volumes, err := clusterVolumes(hosts)
if err != nil {
return err
}
w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
defer w.Flush()
listRec(w,
"ID",
"TYPE",
"HOST",
"CREATED",
"META",
)
for _, volume := range volumes {
meta := make([]string, 0, len(volume.Volume.Meta))
for k, v := range volume.Volume.Meta {
meta = append(meta, fmt.Sprintf("%s=%s", k, v))
}
listRec(w,
volume.Volume.ID,
volume.Volume.Type,
volume.Host.ID(),
units.HumanDuration(time.Now().UTC().Sub(volume.Volume.CreatedAt))+" ago",
strings.Join(meta, " "),
)
}
return nil
}
示例14: runTags
func runTags(args *docopt.Args, client *cluster.Client) error {
if args.Bool["set"] {
return runTagsSet(args, client)
} else if args.Bool["del"] {
return runTagsDel(args, client)
}
hosts, err := client.Hosts()
if err != nil {
return err
}
w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
defer w.Flush()
listRec(w, "HOST", "TAGS")
for _, host := range hosts {
tags := make([]string, 0, len(host.Tags()))
for k, v := range host.Tags() {
tags = append(tags, fmt.Sprintf("%s=%s", k, v))
}
listRec(w, host.ID(), strings.Join(tags, " "))
}
return nil
}
示例15: runVolumeDelete
func runVolumeDelete(args *docopt.Args, client *cluster.Client) error {
success := true
hosts, err := client.Hosts()
if err != nil {
return fmt.Errorf("could not list hosts: %s", err)
}
if len(hosts) == 0 {
return errors.New("no hosts found")
}
volumes, err := clusterVolumes(hosts)
if err != nil {
return err
}
outer:
for _, id := range args.All["ID"].([]string) {
// find this volume in the list
for _, v := range volumes {
if v.Volume.ID == id {
if err := v.Host.DestroyVolume(id); err != nil {
success = false
fmt.Printf("could not delete volume %s: %s\n", id, err)
continue outer
}
// delete the volume
fmt.Println(id, "deleted")
continue outer
}
}
success = false
fmt.Printf("could not delete volume %s: volume not found\n", id)
}
if !success {
return errors.New("could not delete all volumes")
}
return nil
}