~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/juju/deploy.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
                return nil, fmt.Errorf("use of --networks is deprecated. Please use spaces")
71
71
        }
72
72
 
73
 
        effectiveBindings, err := getEffectiveBindingsForCharmMeta(args.Charm.Meta(), args.EndpointBindings)
74
 
        if err != nil {
75
 
                return nil, errors.Annotate(err, "cannot determine effective service endpoint bindings")
76
 
        }
 
73
        effectiveBindings := getEffectiveBindingsForCharmMeta(args.Charm.Meta(), args.EndpointBindings)
77
74
 
78
75
        asa := state.AddServiceArgs{
79
76
                Name:             args.ServiceName,
98
95
        return st.AddService(asa)
99
96
}
100
97
 
101
 
func getEffectiveBindingsForCharmMeta(charmMeta *charm.Meta, givenBindings map[string]string) (map[string]string, error) {
102
 
        combinedEndpoints, err := state.CombinedCharmRelations(charmMeta)
103
 
        if err != nil {
104
 
                return nil, errors.Trace(err)
105
 
        }
 
98
func getEffectiveBindingsForCharmMeta(charmMeta *charm.Meta, givenBindings map[string]string) map[string]string {
 
99
        // defaultBindings contains all bindable endpoints for charmMeta as keys and
 
100
        // empty space names as values, so we use defaultBindings as fallback.
 
101
        defaultBindings := state.DefaultEndpointBindingsForCharm(charmMeta)
106
102
        if givenBindings == nil {
107
 
                givenBindings = make(map[string]string, len(combinedEndpoints))
 
103
                givenBindings = make(map[string]string, len(defaultBindings))
108
104
        }
109
105
 
110
106
        // Get the service-level default binding for all unspecified endpoint, if
111
107
        // set, otherwise use the empty default.
112
108
        serviceDefaultSpace, _ := givenBindings[""]
113
109
 
114
 
        effectiveBindings := make(map[string]string, len(combinedEndpoints))
115
 
        for endpoint, _ := range combinedEndpoints {
 
110
        effectiveBindings := make(map[string]string, len(defaultBindings))
 
111
        for endpoint, _ := range defaultBindings {
116
112
                if givenSpace, isGiven := givenBindings[endpoint]; isGiven {
117
113
                        effectiveBindings[endpoint] = givenSpace
118
114
                } else {
119
115
                        effectiveBindings[endpoint] = serviceDefaultSpace
120
116
                }
121
117
        }
122
 
        return effectiveBindings, nil
 
118
        return effectiveBindings
123
119
}
124
120
 
125
121
// AddUnits starts n units of the given service using the specified placement