// AddConstraint adds a new constraint
//		constraints:	the constraint definition, one constraint per array element
979936
func (p *PodPlacement) AddConstraint(constraint Constraint) *PodPlacement {
	c := *p.Constraints
	c = append(c, constraint)
	p.Constraints = &c

	return p
}
532811
func (s *AutoScalingPolicy) SetConstraints(v *ScalingConstraints) *AutoScalingPolicy {
	s.Constraints = v
	return s
}
733819
func (b Box) Constrain(other Box) Box {
	newBox := b.Clone()

	newBox.Top = util.Math.MaxInt(newBox.Top, other.Top)
	newBox.Left = util.Math.MaxInt(newBox.Left, other.Left)
	newBox.Right = util.Math.MinInt(newBox.Right, other.Right)
	newBox.Bottom = util.Math.MinInt(newBox.Bottom, other.Bottom)

	return newBox
}
299461
func SumConstraint(attr ...IntegerAttribute) ArithmeticConstraint {
	attribute := make([]Attribute, len(attr))
	for i, a := range attr {
		attribute[i] = Attribute(a)
	}
	return NewArithmeticConstraint(ADD_OP, attribute, nil)
}
606048
func (c *Client) SetModelConstraints(args params.SetConstraints) error {
	if err := c.checkCanWrite(); err != nil {
		return err
	}

	if err := c.check.ChangeAllowed(); err != nil {
		return errors.Trace(err)
	}
	return c.api.stateAccessor.SetModelConstraints(args.Constraints)
}
215557
func NewSemverConstraint(body string) (Constraint, error) {
	c, err := semver.NewConstraint(body)
	if err != nil {
		return nil, err
	}
	// If we got a simple semver.Version, simplify by returning our
	// corresponding type
	if sv, ok := c.(*semver.Version); ok {
		return semVersion{sv: sv}, nil
	}
	return semverConstraint{c: c}, nil
}
116086
func (a *Application) SetConstraints(cons constraints.Value) (err error) {
	unsupported, err := a.st.validateConstraints(cons)
	if len(unsupported) > 0 {
		logger.Warningf(
			"setting constraints on application %q: unsupported constraints: %v", a.Name(), strings.Join(unsupported, ","))
	} else if err != nil {
		return err
	}
	if a.doc.Subordinate {
		return ErrSubordinateConstraints
	}
	defer errors.DeferredAnnotatef(&err, "cannot set constraints")
	if a.doc.Life != Alive {
		return applicationNotAliveErr
	}
	ops := []txn.Op{{
		C:      applicationsC,
		Id:     a.doc.DocID,
		Assert: isAliveDoc,
	}}
	ops = append(ops, setConstraintsOp(a.globalKey(), cons))
	return onAbort(a.st.db().RunTransaction(ops), applicationNotAliveErr)
}
901340
func NewConstraint() *constraint {
	return &constraint{
		Handler: admission.NewHandler(admission.Create, admission.Update),
	}
}
1229062
func minConstraint(limitType string, resourceName string, enforced resource.Quantity, request api.ResourceList, limit api.ResourceList) error {
	req, reqExists := request[api.ResourceName(resourceName)]
	lim, limExists := limit[api.ResourceName(resourceName)]
	observedReqValue, observedLimValue, enforcedValue := requestLimitEnforcedValues(req, lim, enforced)

	if !reqExists {
		return fmt.Errorf("minimum %s usage per %s is %s.  No request is specified.", resourceName, limitType, enforced.String())
	}
	if observedReqValue < enforcedValue {
		return fmt.Errorf("minimum %s usage per %s is %s, but request is %s.", resourceName, limitType, enforced.String(), req.String())
	}
	if limExists && (observedLimValue < enforcedValue) {
		return fmt.Errorf("minimum %s usage per %s is %s, but limit is %s.", resourceName, limitType, enforced.String(), lim.String())
	}
	return nil
}
374447
func NewConstraint(exp string) (*Constraint, error) {
	sep := ""
	constraint := &Constraint{}

	switch {
	case strings.Contains(exp, "=="):
		sep = "=="
		constraint.MustMatch = true
	case strings.Contains(exp, "!="):
		sep = "!="
		constraint.MustMatch = false
	default:
		return nil, errors.New("constraint expression missing valid operator: '==' or '!='")
	}

	kv := strings.SplitN(exp, sep, 2)
	if len(kv) == 2 {
		// At the moment, it only supports tags
		if kv[0] != "tag" {
			return nil, errors.New("constraint must be tag-based. Syntax: tag==us-*")
		}

		constraint.Key = kv[0]
		constraint.Regex = kv[1]
		return constraint, nil
	}

	return nil, fmt.Errorf("incorrect constraint expression: %s", exp)
}
1050601
func (u *Unit) Constraints() (*constraints.Value, error) {
	cons, err := readConstraints(u.st, u.globalAgentKey())
	if errors.IsNotFound(err) {
		// Lack of constraints indicates lack of unit.
		return nil, errors.NotFoundf("unit")
	} else if err != nil {
		return nil, err
	}
	return &cons, nil
}
521523
func (db *deviceBackend) DeviceConstraints(id string) (map[string]DeviceConstraints, error) {
	devices, err := readDeviceConstraints(db.mb, id)
	if err == nil {
		return devices, nil
	} else if errors.IsNotFound(err) {
		return map[string]DeviceConstraints{}, nil
	}
	return nil, err
}
689450
func (c *Client) SetConstraints(application string, constraints constraints.Value) error {
	args := params.SetConstraints{
		ApplicationName: application,
		Constraints:     constraints,
	}
	return c.facade.FacadeCall("SetConstraints", args, nil)
}
1370073
func (b Box) OuterConstrain(bounds, other Box) Box {
	newBox := b.Clone()
	if other.Top < bounds.Top {
		delta := bounds.Top - other.Top
		newBox.Top = b.Top + delta
	}

	if other.Left < bounds.Left {
		delta := bounds.Left - other.Left
		newBox.Left = b.Left + delta
	}

	if other.Right > bounds.Right {
		delta := other.Right - bounds.Right
		newBox.Right = b.Right - delta
	}

	if other.Bottom > bounds.Bottom {
		delta := other.Bottom - bounds.Bottom
		newBox.Bottom = b.Bottom - delta
	}
	return newBox
}
240560
func PgConstraintByOid(db XODB, oid pgtypes.Oid) (*PgConstraint, error) {
	var err error

	// sql query
	const sqlstr = `SELECT ` +
		`tableoid, cmax, xmax, cmin, xmin, oid, ctid, conname, connamespace, contype, condeferrable, condeferred, convalidated, conrelid, contypid, conindid, confrelid, confupdtype, confdeltype, confmatchtype, conislocal, coninhcount, connoinherit, conkey, confkey, conpfeqop, conppeqop, conffeqop, conexclop, conbin, consrc ` +
		`FROM pg_catalog.pg_constraint ` +
		`WHERE oid = $1`

	// run query
	XOLog(sqlstr, oid)
	pc := PgConstraint{}

	err = db.QueryRow(sqlstr, oid).Scan(&pc.Tableoid, &pc.Cmax, &pc.Xmax, &pc.Cmin, &pc.Xmin, &pc.Oid, &pc.Ctid, &pc.Conname, &pc.Connamespace, &pc.Contype, &pc.Condeferrable, &pc.Condeferred, &pc.Convalidated, &pc.Conrelid, &pc.Contypid, &pc.Conindid, &pc.Confrelid, &pc.Confupdtype, &pc.Confdeltype, &pc.Confmatchtype, &pc.Conislocal, &pc.Coninhcount, &pc.Connoinherit, &pc.Conkey, &pc.Confkey, &pc.Conpfeqop, &pc.Conppeqop, &pc.Conffeqop, &pc.Conexclop, &pc.Conbin, &pc.Consrc)
	if err != nil {
		return nil, err
	}

	return &pc, nil
}
1011989
func (s *S3CopyObjectOperation) SetModifiedSinceConstraint(v time.Time) *S3CopyObjectOperation {
	s.ModifiedSinceConstraint = &v
	return s
}
1294651
func EscapedConstraints(constraints []*Constraint) []*Constraint {
	var escaped []*Constraint
	for _, c := range constraints {
		if constraintTargetEscapes(c.LTarget) || constraintTargetEscapes(c.RTarget) {
			escaped = append(escaped, c)
		}
	}

	return escaped
}