Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright 2013 Canonical Ltd. | 1 // Copyright 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package client | 4 package client |
5 | 5 |
6 import ( | 6 import ( |
7 "errors" | 7 "errors" |
8 "fmt" | 8 "fmt" |
9 | 9 |
10 "launchpad.net/juju-core/charm" | 10 "launchpad.net/juju-core/charm" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 return err | 140 return err |
141 } | 141 } |
142 ch, err := conn.PutCharm(curl, CharmStore, false) | 142 ch, err := conn.PutCharm(curl, CharmStore, false) |
143 if err != nil { | 143 if err != nil { |
144 return err | 144 return err |
145 } | 145 } |
146 var settings charm.Settings | 146 var settings charm.Settings |
147 if len(args.ConfigYAML) > 0 { | 147 if len(args.ConfigYAML) > 0 { |
148 settings, err = ch.Config().ParseSettingsYAML([]byte(args.Config YAML), args.ServiceName) | 148 settings, err = ch.Config().ParseSettingsYAML([]byte(args.Config YAML), args.ServiceName) |
149 } else if len(args.Config) > 0 { | 149 } else if len(args.Config) > 0 { |
150 » » settings, err = ch.Config().ParseSettingsStrings(args.Config) | 150 » » // Parse config in a compatile way (see function comment). |
151 » » settings, err = parseSettingsCompatible(ch, args.Config) | |
151 } | 152 } |
152 if err != nil { | 153 if err != nil { |
153 return err | 154 return err |
154 } | 155 } |
155 _, err = conn.DeployService(juju.DeployServiceParams{ | 156 _, err = conn.DeployService(juju.DeployServiceParams{ |
156 ServiceName: args.ServiceName, | 157 ServiceName: args.ServiceName, |
157 Charm: ch, | 158 Charm: ch, |
158 NumUnits: args.NumUnits, | 159 NumUnits: args.NumUnits, |
159 ConfigSettings: settings, | 160 ConfigSettings: settings, |
160 Constraints: args.Constraints, | 161 Constraints: args.Constraints, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 return service.UpdateConfigSettings(changes) | 238 return service.UpdateConfigSettings(changes) |
238 } | 239 } |
239 | 240 |
240 // serviceSetSettingsStrings updates the settings for the given service, | 241 // serviceSetSettingsStrings updates the settings for the given service, |
241 // taking the configuration from a map of strings. | 242 // taking the configuration from a map of strings. |
242 func serviceSetSettingsStrings(service *state.Service, settings map[string]strin g) error { | 243 func serviceSetSettingsStrings(service *state.Service, settings map[string]strin g) error { |
243 ch, _, err := service.Charm() | 244 ch, _, err := service.Charm() |
244 if err != nil { | 245 if err != nil { |
245 return err | 246 return err |
246 } | 247 } |
247 » changes, err := ch.Config().ParseSettingsStrings(settings) | 248 » // Parse config in a compatile way (see function comment). |
axw1
2013/09/11 08:37:42
typo - s/compatile/compatible/
mue
2013/09/11 16:29:09
Done.
| |
249 » changes, err := parseSettingsCompatible(ch, settings) | |
248 if err != nil { | 250 if err != nil { |
249 return err | 251 return err |
250 } | 252 } |
251 return service.UpdateConfigSettings(changes) | 253 return service.UpdateConfigSettings(changes) |
252 } | 254 } |
253 | 255 |
254 // ServiceSetCharm sets the charm for a given service. | 256 // ServiceSetCharm sets the charm for a given service. |
255 func (c *Client) ServiceSetCharm(args params.ServiceSetCharm) error { | 257 func (c *Client) ServiceSetCharm(args params.ServiceSetCharm) error { |
256 service, err := c.api.state.Service(args.ServiceName) | 258 service, err := c.api.state.Service(args.ServiceName) |
257 if err != nil { | 259 if err != nil { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 } | 396 } |
395 | 397 |
396 // SetAnnotations stores annotations about a given entity. | 398 // SetAnnotations stores annotations about a given entity. |
397 func (c *Client) SetAnnotations(args params.SetAnnotations) error { | 399 func (c *Client) SetAnnotations(args params.SetAnnotations) error { |
398 entity, err := c.findEntity(args.Tag) | 400 entity, err := c.findEntity(args.Tag) |
399 if err != nil { | 401 if err != nil { |
400 return err | 402 return err |
401 } | 403 } |
402 return entity.SetAnnotations(args.Pairs) | 404 return entity.SetAnnotations(args.Pairs) |
403 } | 405 } |
406 | |
407 // parseSettingsCompatible parses setting strings in a way that is | |
408 // campatible with the behavior before this CL based on the issue | |
axw1
2013/09/11 08:37:42
s/campatible/compatible/
mue
2013/09/11 16:29:09
Done.
| |
409 // http://pad.lv/1194945. Until then setting an option to an empty | |
410 // string caused it to reset to the default value. We now allow | |
411 // empty strings as actual values, but we want to preserve the API | |
412 // behavior. | |
413 func parseSettingsCompatible(ch *state.Charm, settings map[string]string) (charm .Settings, error) { | |
414 setSettings := map[string]string{} | |
415 unsetSettings := charm.Settings{} | |
416 // Split settings into those which set and those which unset a value. | |
417 for name, value := range settings { | |
418 if value == "" { | |
419 unsetSettings[name] = nil | |
420 continue | |
421 } | |
422 setSettings[name] = value | |
423 } | |
424 // Validate the settings. | |
425 changes, err := ch.Config().ParseSettingsStrings(setSettings) | |
426 if err != nil { | |
427 return nil, err | |
428 } | |
429 // Validate the unsettings and merge them into the changes. | |
430 unsetSettings, err = ch.Config().ValidateSettings(unsetSettings) | |
431 if err != nil { | |
432 return nil, err | |
433 } | |
434 for name := range unsetSettings { | |
435 changes[name] = nil | |
436 } | |
437 return changes, nil | |
438 } | |
OLD | NEW |