~themue/juju-core/021-deployer-lxc-context

« back to all changes in this revision

Viewing changes to state/statecmd/addrelation.go

  • Committer: Frank Mueller
  • Date: 2013-05-09 22:35:21 UTC
  • mfrom: (964.1.245 juju-core)
  • Revision ID: themue@gmail.com-20130509223521-12m9j2dtdx65tvr2
lxc: refactored into own package; first network code

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Code shared by the CLI and API for the AddRelation function.
 
2
 
 
3
package statecmd
 
4
 
 
5
import (
 
6
        "launchpad.net/juju-core/charm"
 
7
        "launchpad.net/juju-core/state"
 
8
        "launchpad.net/juju-core/state/api/params"
 
9
)
 
10
 
 
11
// AddRelation adds a relation between the specified endpoint names, and
 
12
// returns a map from service names to relation endpoints.
 
13
func AddRelation(state *state.State, args params.AddRelation) (params.AddRelationResults, error) {
 
14
        inEps, err := state.InferEndpoints(args.Endpoints)
 
15
        if err != nil {
 
16
                return params.AddRelationResults{}, err
 
17
        }
 
18
        rel, err := state.AddRelation(inEps...)
 
19
        if err != nil {
 
20
                return params.AddRelationResults{}, err
 
21
        }
 
22
        outEps := make(map[string]charm.Relation)
 
23
        for _, inEp := range inEps {
 
24
                outEp, err := rel.Endpoint(inEp.ServiceName)
 
25
                if err != nil {
 
26
                        return params.AddRelationResults{}, err
 
27
                }
 
28
                outEps[inEp.ServiceName] = outEp.Relation
 
29
        }
 
30
        return params.AddRelationResults{Endpoints: outEps}, nil
 
31
}