本文整理匯總了Golang中github.com/flynn/flynn/pkg/cluster.Client.ListHosts方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.ListHosts方法的具體用法?Golang Client.ListHosts怎麽用?Golang Client.ListHosts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/flynn/flynn/pkg/cluster.Client
的用法示例。
在下文中一共展示了Client.ListHosts方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}
示例3: 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
}