1 Star 0 Fork 0

powerpaas / machine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
active.go 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
Patrik Erdes 提交于 2016-02-18 08:51 . Fix #3015
package commands
import (
"errors"
"fmt"
"time"
"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/persist"
"github.com/docker/machine/libmachine/state"
)
const (
activeDefaultTimeout = 10
)
var (
errNoActiveHost = errors.New("No active host found")
errActiveTimeout = errors.New("Error getting active host: timeout")
)
func cmdActive(c CommandLine, api libmachine.API) error {
if len(c.Args()) > 0 {
return ErrTooManyArguments
}
hosts, hostsInError, err := persist.LoadAllHosts(api)
if err != nil {
return fmt.Errorf("Error getting active host: %s", err)
}
timeout := time.Duration(c.Int("timeout")) * time.Second
items := getHostListItems(hosts, hostsInError, timeout)
active, err := activeHost(items)
if err != nil {
return err
}
fmt.Println(active.Name)
return nil
}
func activeHost(items []HostListItem) (HostListItem, error) {
timeout := false
for _, item := range items {
if item.ActiveHost || item.ActiveSwarm {
return item, nil
}
if item.State == state.Timeout {
timeout = true
}
}
if timeout {
return HostListItem{}, errActiveTimeout
}
return HostListItem{}, errNoActiveHost
}
1
https://gitee.com/powerpaas/machine.git
git@gitee.com:powerpaas/machine.git
powerpaas
machine
machine
v0.13.0

搜索帮助

53164aa7 5694891 3bd8fe86 5694891