本文整理匯總了Golang中github.com/flynn/flynn/pkg/cluster.Client.DialHost方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.DialHost方法的具體用法?Golang Client.DialHost怎麽用?Golang Client.DialHost使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/flynn/flynn/pkg/cluster.Client
的用法示例。
在下文中一共展示了Client.DialHost方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}
示例3: 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.DialHost(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
}
示例4: getLog
func getLog(hostID, jobID string, client *cluster.Client, follow bool, stdout, stderr io.Writer) error {
hostClient, err := client.DialHost(hostID)
if err != nil {
return fmt.Errorf("could not connect to host %s: %s", hostID, err)
}
defer hostClient.Close()
attachReq := &host.AttachReq{
JobID: jobID,
Flags: host.AttachFlagStdout | host.AttachFlagStderr | host.AttachFlagLogs,
}
if follow {
attachReq.Flags |= host.AttachFlagStream
}
attachClient, err := hostClient.Attach(attachReq, false)
if err != nil {
if err == cluster.ErrWouldWait {
return errors.New("no such job")
}
return err
}
defer attachClient.Close()
attachClient.Receive(stdout, stderr)
return nil
}