當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Store.ListHosts方法代碼示例

本文整理匯總了Golang中github.com/litl/galaxy/config.Store.ListHosts方法的典型用法代碼示例。如果您正苦於以下問題:Golang Store.ListHosts方法的具體用法?Golang Store.ListHosts怎麽用?Golang Store.ListHosts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/litl/galaxy/config.Store的用法示例。


在下文中一共展示了Store.ListHosts方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: HostsList

func HostsList(configStore *config.Store, env, pool string) error {

	envs := []string{env}

	if env == "" {
		var err error
		envs, err = configStore.ListEnvs()
		if err != nil {
			return err
		}
	}

	columns := []string{"ENV | POOL | HOST IP "}

	for _, env := range envs {

		var err error
		pools := []string{pool}
		if pool == "" {
			pools, err = configStore.ListPools(env)
			if err != nil {
				return err
			}
		}

		for _, pool := range pools {

			hosts, err := configStore.ListHosts(env, pool)
			if err != nil {
				return err
			}

			if len(hosts) == 0 {
				columns = append(columns, strings.Join([]string{
					env,
					pool,
					"",
				}, " | "))
				continue
			}
			for _, p := range hosts {
				columns = append(columns, strings.Join([]string{
					env,
					pool,
					p.HostIP,
				}, " | "))
			}
		}
	}
	output, _ := columnize.SimpleFormat(columns)
	log.Println(output)
	return nil

}
開發者ID:zombor,項目名稱:galaxy,代碼行數:54,代碼來源:hosts.go

示例2: Balanced

// Balanced returns the number of instances that should be run on the host
// according to the desired state for the app in the given env and pool. The
// number returned for the host represent an approximately equal distribution
// across all hosts.
func Balanced(configStore *config.Store, hostId, app, env, pool string) (int, error) {
	hosts, err := configStore.ListHosts(env, pool)
	if err != nil {
		return 0, err
	}

	cfg, err := configStore.GetApp(app, env)
	if err != nil {
		return 0, err
	}

	desired := cfg.GetProcesses(pool)
	if desired == 0 {
		return 0, nil
	}

	if desired == -1 {
		return 1, nil
	}

	hostIds := []string{}
	for _, h := range hosts {
		hostIds = append(hostIds, h.HostIP)
	}
	sort.Strings(hostIds)

	hostIdx := -1
	for i, v := range hostIds {
		if v == hostId {
			hostIdx = i
			break
		}
	}

	if hostIdx < 0 {
		return 0, nil
	}

	count := 0
	for i := 0; i < desired; i++ {
		if i%len(hosts) == hostIdx {
			count = count + 1
		}
	}

	return count, nil
}
開發者ID:sguzwf,項目名稱:galaxy,代碼行數:51,代碼來源:scheduler.go


注:本文中的github.com/litl/galaxy/config.Store.ListHosts方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。