示例#1
0
func addCharm(c *C, st *State, series string, ch charm.Charm) *Charm {
	ident := fmt.Sprintf("%s-%s-%d", series, ch.Meta().Name, ch.Revision())
	curl := charm.MustParseURL("local:" + series + "/" + ident)
	bundleURL, err := url.Parse("http://bundles.testing.invalid/" + ident)
	c.Assert(err, IsNil)
	sch, err := st.AddCharm(ch, curl, bundleURL, ident+"-sha256")
	c.Assert(err, IsNil)
	return sch
}
示例#2
0
func checkDummy(c *C, f charm.Charm, path string) {
	c.Assert(f.Revision(), Equals, 1)
	c.Assert(f.Meta().Name, Equals, "dummy")
	c.Assert(f.Config().Options["title"].Default, Equals, "My Title")
	switch f := f.(type) {
	case *charm.Bundle:
		c.Assert(f.Path, Equals, path)
	case *charm.Dir:
		c.Assert(f.Path, Equals, path)
	}
}
示例#3
0
// AddCharm adds the ch charm with curl to the state.  bundleUrl must be
// set to a URL where the bundle for ch may be downloaded from.
// On success the newly added charm state is returned.
func (st *State) AddCharm(ch charm.Charm, curl *charm.URL, bundleURL *url.URL, bundleSha256 string) (stch *Charm, err error) {
	cdoc := &charmDoc{
		URL:          curl,
		Meta:         ch.Meta(),
		Config:       ch.Config(),
		BundleURL:    bundleURL,
		BundleSha256: bundleSha256,
	}
	err = st.charms.Insert(cdoc)
	if err != nil {
		return nil, fmt.Errorf("cannot add charm %q: %v", curl, err)
	}
	return newCharm(st, cdoc)
}
示例#4
0
// ImplementedBy returns whether the endpoint is implemented by the supplied charm.
func (ep Endpoint) ImplementedBy(ch charm.Charm) bool {
	if ep.IsImplicit() {
		return true
	}
	var m map[string]charm.Relation
	switch ep.Role {
	case charm.RoleProvider:
		m = ch.Meta().Provides
	case charm.RoleRequirer:
		m = ch.Meta().Requires
	case charm.RolePeer:
		m = ch.Meta().Peers
	default:
		panic(fmt.Errorf("unknown relation role %q", ep.Role))
	}
	rel, found := m[ep.Name]
	if !found {
		return false
	}
	if rel.Interface == ep.Interface {
		switch ep.Scope {
		case charm.ScopeGlobal:
			return rel.Scope != charm.ScopeContainer
		case charm.ScopeContainer:
			return true
		default:
			panic(fmt.Errorf("unknown relation scope %q", ep.Scope))
		}
	}
	return false
}