7
"launchpad.net/juju-core/constraints"
10
// constraintsDoc is the mongodb representation of a constraints.Value.
11
type constraintsDoc struct {
18
func newConstraintsDoc(cons constraints.Value) constraintsDoc {
19
return constraintsDoc{
21
CpuCores: cons.CpuCores,
22
CpuPower: cons.CpuPower,
27
func createConstraintsOp(st *State, id string, cons constraints.Value) txn.Op {
29
C: st.constraints.Name,
31
Assert: txn.DocMissing,
32
Insert: newConstraintsDoc(cons),
36
func readConstraints(st *State, id string) (constraints.Value, error) {
37
doc := constraintsDoc{}
38
if err := st.constraints.FindId(id).One(&doc); err == mgo.ErrNotFound {
39
return constraints.Value{}, NotFoundf("constraints")
40
} else if err != nil {
41
return constraints.Value{}, err
43
return constraints.Value{
45
CpuCores: doc.CpuCores,
46
CpuPower: doc.CpuPower,
51
func writeConstraints(st *State, id string, cons constraints.Value) error {
53
C: st.constraints.Name,
55
Assert: txn.DocExists,
56
Update: D{{"$set", newConstraintsDoc(cons)}},
58
if err := st.runner.Run(ops, "", nil); err != nil {
59
return fmt.Errorf("cannot set constraints: %v", err)