Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7)

Delta Between Two Patch Sets: mstate/machine.go

Issue 6304099: mstate: state package replacement using mgo.
Left Patch Set: mstate: state package replacement using mgo. Created 12 years, 9 months ago
Right Patch Set: mstate: state package replacement using mgo. Created 12 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « mstate/error.go ('k') | mstate/mgo_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b