コード例 #1
0
ファイル: addrelation.go プロジェクト: rif/golang-stuff
// AddRelation adds a relation between the specified endpoint names, and
// returns a map from service names to relation endpoints.
func AddRelation(state *state.State, args params.AddRelation) (params.AddRelationResults, error) {
	inEps, err := state.InferEndpoints(args.Endpoints)
	if err != nil {
		return params.AddRelationResults{}, err
	}
	rel, err := state.AddRelation(inEps...)
	if err != nil {
		return params.AddRelationResults{}, err
	}
	outEps := make(map[string]charm.Relation)
	for _, inEp := range inEps {
		outEp, err := rel.Endpoint(inEp.ServiceName)
		if err != nil {
			return params.AddRelationResults{}, err
		}
		outEps[inEp.ServiceName] = outEp.Relation
	}
	return params.AddRelationResults{Endpoints: outEps}, nil
}