LEFT | RIGHT |
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 "launchpad.net/juju-core/charm" | 7 "launchpad.net/juju-core/charm" |
8 "launchpad.net/juju-core/constraints" | 8 "launchpad.net/juju-core/constraints" |
9 "launchpad.net/juju-core/state" | |
10 "launchpad.net/juju-core/state/api/params" | 9 "launchpad.net/juju-core/state/api/params" |
11 ) | 10 ) |
12 | 11 |
13 func serviceGet(st *state.State, p params.ServiceGet) (params.ServiceGetResults,
error) { | 12 // ServiceGet returns the configuration for a service. |
14 » service, err := st.Service(p.ServiceName) | 13 func (c *Client) ServiceGet(args params.ServiceGet) (params.ServiceGetResults, e
rror) { |
| 14 » service, err := c.api.state.Service(args.ServiceName) |
15 if err != nil { | 15 if err != nil { |
16 return params.ServiceGetResults{}, err | 16 return params.ServiceGetResults{}, err |
17 } | 17 } |
18 settings, err := service.ConfigSettings() | 18 settings, err := service.ConfigSettings() |
19 if err != nil { | 19 if err != nil { |
20 return params.ServiceGetResults{}, err | 20 return params.ServiceGetResults{}, err |
21 } | 21 } |
22 charm, _, err := service.Charm() | 22 charm, _, err := service.Charm() |
23 if err != nil { | 23 if err != nil { |
24 return params.ServiceGetResults{}, err | 24 return params.ServiceGetResults{}, err |
25 } | 25 } |
26 configInfo := describe(settings, charm.Config()) | 26 configInfo := describe(settings, charm.Config()) |
27 var constraints constraints.Value | 27 var constraints constraints.Value |
28 if service.IsPrincipal() { | 28 if service.IsPrincipal() { |
29 constraints, err = service.Constraints() | 29 constraints, err = service.Constraints() |
30 if err != nil { | 30 if err != nil { |
31 return params.ServiceGetResults{}, err | 31 return params.ServiceGetResults{}, err |
32 } | 32 } |
33 } | 33 } |
34 return params.ServiceGetResults{ | 34 return params.ServiceGetResults{ |
35 » » Service: p.ServiceName, | 35 » » Service: args.ServiceName, |
36 Charm: charm.Meta().Name, | 36 Charm: charm.Meta().Name, |
37 Config: configInfo, | 37 Config: configInfo, |
38 Constraints: constraints, | 38 Constraints: constraints, |
39 }, nil | 39 }, nil |
40 } | 40 } |
41 | 41 |
42 func describe(settings charm.Settings, config *charm.Config) map[string]interfac
e{} { | 42 func describe(settings charm.Settings, config *charm.Config) map[string]interfac
e{} { |
43 results := make(map[string]interface{}) | 43 results := make(map[string]interface{}) |
44 for name, option := range config.Options { | 44 for name, option := range config.Options { |
45 info := map[string]interface{}{ | 45 info := map[string]interface{}{ |
46 "description": option.Description, | 46 "description": option.Description, |
47 "type": option.Type, | 47 "type": option.Type, |
48 } | 48 } |
49 if value := settings[name]; value != nil { | 49 if value := settings[name]; value != nil { |
50 info["value"] = value | 50 info["value"] = value |
51 } else { | 51 } else { |
52 info["value"] = option.Default | 52 info["value"] = option.Default |
53 info["default"] = true | 53 info["default"] = true |
54 } | 54 } |
55 results[name] = info | 55 results[name] = info |
56 } | 56 } |
57 return results | 57 return results |
58 } | 58 } |
LEFT | RIGHT |