70
70
return nil, fmt.Errorf("use of --networks is deprecated. Please use spaces")
73
effectiveBindings, err := getEffectiveBindingsForCharmMeta(args.Charm.Meta(), args.EndpointBindings)
75
return nil, errors.Annotate(err, "cannot determine effective service endpoint bindings")
73
effectiveBindings := getEffectiveBindingsForCharmMeta(args.Charm.Meta(), args.EndpointBindings)
78
75
asa := state.AddServiceArgs{
79
76
Name: args.ServiceName,
98
95
return st.AddService(asa)
101
func getEffectiveBindingsForCharmMeta(charmMeta *charm.Meta, givenBindings map[string]string) (map[string]string, error) {
102
combinedEndpoints, err := state.CombinedCharmRelations(charmMeta)
104
return nil, errors.Trace(err)
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))
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[""]
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
119
115
effectiveBindings[endpoint] = serviceDefaultSpace
122
return effectiveBindings, nil
118
return effectiveBindings
125
121
// AddUnits starts n units of the given service using the specified placement