LEFT | RIGHT |
1 package mstate | 1 package mstate |
2 | 2 |
3 import ( | 3 import ( |
4 "fmt" | 4 "fmt" |
5 "launchpad.net/mgo/bson" | 5 "launchpad.net/mgo/bson" |
6 "strconv" | 6 "strconv" |
7 ) | 7 ) |
8 | 8 |
9 // Machine represents the state of a machine. | 9 // Machine represents the state of a machine. |
10 type Machine struct { | 10 type Machine struct { |
(...skipping 17 matching lines...) Expand all Loading... |
28 mdoc := &machineDoc{} | 28 mdoc := &machineDoc{} |
29 err := m.st.machines.Find(bson.D{{"_id", m.id}}).One(mdoc) | 29 err := m.st.machines.Find(bson.D{{"_id", m.id}}).One(mdoc) |
30 if err != nil { | 30 if err != nil { |
31 return "", fmt.Errorf("can't get instance id of machine %s: %v",
m, err) | 31 return "", fmt.Errorf("can't get instance id of machine %s: %v",
m, err) |
32 } | 32 } |
33 return mdoc.InstanceId, nil | 33 return mdoc.InstanceId, nil |
34 } | 34 } |
35 | 35 |
36 // SetInstanceId sets the provider specific machine id for this machine. | 36 // SetInstanceId sets the provider specific machine id for this machine. |
37 func (m *Machine) SetInstanceId(id string) error { | 37 func (m *Machine) SetInstanceId(id string) error { |
38 » err := m.st.machines.Update(bson.D{{"_id", m.id}}, bson.D{{"instanceid",
id}}) | 38 » change := bson.D{{"$set", bson.D{{"instanceid", id}}}} |
| 39 » err := m.st.machines.Update(bson.D{{"_id", m.id}}, change) |
39 if err != nil { | 40 if err != nil { |
40 return fmt.Errorf("can't set instance id of machine %s: %v", m,
err) | 41 return fmt.Errorf("can't set instance id of machine %s: %v", m,
err) |
41 } | 42 } |
42 return nil | 43 return nil |
43 } | 44 } |
44 | 45 |
45 // String returns a unique description of this machine | 46 // String returns a unique description of this machine. |
46 func (m *Machine) String() string { | 47 func (m *Machine) String() string { |
47 return strconv.Itoa(m.Id()) | 48 return strconv.Itoa(m.Id()) |
48 } | 49 } |
LEFT | RIGHT |