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


Golang ContainerConfig.Constraints方法代碼示例

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


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

示例1: Filter

// Filter is exported
func (f *ConstraintFilter) Filter(config *cluster.ContainerConfig, nodes []*node.Node) ([]*node.Node, error) {
	constraints, err := parseExprs(config.Constraints())
	if err != nil {
		return nil, err
	}

	for _, constraint := range constraints {
		log.Debugf("matching constraint: %s %s %s", constraint.key, OPERATORS[constraint.operator], constraint.value)

		candidates := []*node.Node{}
		for _, node := range nodes {
			switch constraint.key {
			case "node":
				// "node" label is a special case pinning a container to a specific node.
				if constraint.Match(node.ID, node.Name) {
					candidates = append(candidates, node)
				}
			default:
				if constraint.Match(node.Labels[constraint.key]) {
					candidates = append(candidates, node)
				}
			}
		}
		if len(candidates) == 0 {
			if constraint.isSoft {
				return nodes, nil
			}
			return nil, fmt.Errorf("unable to find a node that satisfies %s%s%s", constraint.key, OPERATORS[constraint.operator], constraint.value)
		}
		nodes = candidates
	}
	return nodes, nil
}
開發者ID:waterytowers,項目名稱:global-hack-day-3,代碼行數:34,代碼來源:constraint.go

示例2: GetFilters

// GetFilters returns a list of the constraints found in the container config.
func (f *ConstraintFilter) GetFilters(config *cluster.ContainerConfig) ([]string, error) {
	allConstraints := []string{}
	constraints, err := parseExprs(config.Constraints())
	if err != nil {
		return nil, err
	}
	for _, constraint := range constraints {
		allConstraints = append(allConstraints, fmt.Sprintf("%s%s%s", constraint.key, OPERATORS[constraint.operator], constraint.value))
	}
	return allConstraints, nil
}
開發者ID:cbbs,項目名稱:swarm,代碼行數:12,代碼來源:constraint.go


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