~themue/juju-core/go-worker-firewaller-machineunits

« back to all changes in this revision

Viewing changes to mstate/state.go

  • Committer: Aram Hăvărneanu
  • Date: 2012-06-25 19:13:42 UTC
  • mto: (262.2.2 mstate-machine-tests1)
  • mto: This revision was merged to the branch mainline in revision 263.
  • Revision ID: aram@canonical.com-20120625191342-ubd6t74engy3qcrf
mstate: basic charms.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
        "fmt"
8
8
        "labix.org/v2/mgo"
9
9
        "labix.org/v2/mgo/bson"
 
10
        "launchpad.net/juju-core/charm"
 
11
        "net/url"
10
12
)
11
13
 
12
14
// State represents the state of an environment
14
16
type State struct {
15
17
        db       *mgo.Database
16
18
        machines *mgo.Collection
 
19
        charms   *mgo.Collection
17
20
}
18
21
 
19
22
// AddMachine creates a new machine state.
61
64
        }
62
65
        return &Machine{st: s, id: mdoc.Id}, nil
63
66
}
 
67
 
 
68
// AddCharm adds the ch charm with curl to the state.  bundleUrl must be
 
69
// set to a URL where the bundle for ch may be downloaded from.
 
70
// On success the newly added charm state is returned.
 
71
func (s *State) AddCharm(ch charm.Charm, curl *charm.URL, bundleURL *url.URL, bundleSha256 string) (stch *Charm, err error) {
 
72
        defer errorContextf(&err, "can't add charm %q", curl)
 
73
        cdoc := &charmDoc{
 
74
                Url:          curl,
 
75
                Meta:         ch.Meta(),
 
76
                Config:       ch.Config(),
 
77
                BundleURL:    bundleURL.String(),
 
78
                BundleSha256: bundleSha256,
 
79
        }
 
80
        err = s.charms.Insert(cdoc)
 
81
        if err != nil {
 
82
                return nil, err
 
83
        }
 
84
        return newCharm(s, cdoc)
 
85
}