10
10
"launchpad.net/juju-core/charm"
11
"launchpad.net/juju-core/environs"
11
12
"launchpad.net/juju-core/juju"
12
13
"launchpad.net/juju-core/state"
13
14
"launchpad.net/juju-core/state/api"
83
// ServiceSet implements the server side of Client.ServiceSet.
84
// ServiceSet implements the server side of Client.ServiceSet. Values set to an
85
// empty string will be unset.
87
// (Deprecated) Use NewServiceSetForClientAPI instead, to preserve values set to
88
// an empty string, and use ServiceUnset to unset values.
84
89
func (c *Client) ServiceSet(p params.ServiceSet) error {
85
90
svc, err := c.api.state.Service(p.ServiceName)
89
94
return serviceSetSettingsStrings(svc, p.Options)
97
// NewServiceSetForClientAPI implements the server side of
98
// Client.NewServiceSetForClientAPI. This is exactly like ServiceSet except that
99
// it does not unset values that are set to an empty string. ServiceUnset
100
// should be used for that.
102
// TODO(Nate): rename this to ServiceSet (and remove the deprecated ServiceSet)
103
// when the GUI handles the new behavior.
104
func (c *Client) NewServiceSetForClientAPI(p params.ServiceSet) error {
105
svc, err := c.api.state.Service(p.ServiceName)
109
return newServiceSetSettingsStringsForClientAPI(svc, p.Options)
92
112
// ServiceUnset implements the server side of Client.ServiceUnset.
93
113
func (c *Client) ServiceUnset(p params.ServiceUnset) error {
94
114
svc, err := c.api.state.Service(p.ServiceName)
273
293
return service.UpdateConfigSettings(changes)
296
// newServiceSetSettingsStringsForClientAPI updates the settings for the given
297
// service, taking the configuration from a map of strings.
299
// TODO(Nate): replace serviceSetSettingsStrings with this onces the GUI no
300
// longer expects to be able to unset values by sending an empty string.
301
func newServiceSetSettingsStringsForClientAPI(service *state.Service, settings map[string]string) error {
302
ch, _, err := service.Charm()
307
// Validate the settings.
308
changes, err := ch.Config().ParseSettingsStrings(settings)
313
return service.UpdateConfigSettings(changes)
276
316
// ServiceSetCharm sets the charm for a given service.
277
317
func (c *Client) ServiceSetCharm(args params.ServiceSetCharm) error {
278
318
service, err := c.api.state.Service(args.ServiceName)
513
553
return changes, nil
556
// EnvironmentGet implements the server-side part of the
557
// get-environment CLI command.
558
func (c *Client) EnvironmentGet() (params.EnvironmentGetResults, error) {
559
result := params.EnvironmentGetResults{}
560
// Get the existing environment config from the state.
561
config, err := c.api.state.EnvironConfig()
565
result.Config = config.AllAttrs()
569
// EnvironmentSet implements the server-side part of the
570
// set-environment CLI command.
571
func (c *Client) EnvironmentSet(args params.EnvironmentSet) error {
572
// TODO(dimitern,thumper): 2013-11-06 bug #1167616
573
// SetEnvironConfig should take both new and old configs.
575
// Get the existing environment config from the state.
576
oldConfig, err := c.api.state.EnvironConfig()
580
// Make sure we don't allow changing agent-version.
581
if v, found := args.Config["agent-version"]; found {
582
oldVersion, _ := oldConfig.AgentVersion()
583
if v != oldVersion.String() {
584
return fmt.Errorf("agent-version cannot be changed")
587
// Apply the attributes specified for the command to the state config.
588
newConfig, err := oldConfig.Apply(args.Config)
592
env, err := environs.New(oldConfig)
596
// Now validate this new config against the existing config via the provider.
597
provider := env.Provider()
598
newProviderConfig, err := provider.Validate(newConfig, oldConfig)
602
// Now try to apply the new validated config.
603
return c.api.state.SetEnvironConfig(newProviderConfig)