OLD | NEW |
1 // The statecmd package is a temporary package | 1 // The statecmd package is a temporary package |
2 // to put code that's used by both cmd/juju and state/api. | 2 // to put code that's used by both cmd/juju and state/api. |
3 // It is intended to wither away to nothing as functionality | 3 // It is intended to wither away to nothing as functionality |
4 // gets absorbed into state and state/api as appropriate | 4 // gets absorbed into state and state/api as appropriate |
5 // when the command-line commands can invoke the | 5 // when the command-line commands can invoke the |
6 // API directly. | 6 // API directly. |
7 package statecmd | 7 package statecmd |
8 | 8 |
9 import ( | 9 import ( |
10 "reflect" | 10 "reflect" |
11 | 11 |
12 "launchpad.net/juju-core/charm" | 12 "launchpad.net/juju-core/charm" |
13 "launchpad.net/juju-core/state" | 13 "launchpad.net/juju-core/state" |
| 14 "launchpad.net/juju-core/state/api/params" |
14 ) | 15 ) |
15 | 16 |
16 // Parameters for making the ServiceGet call. | |
17 type ServiceGetParams struct { | |
18 ServiceName string | |
19 } | |
20 | |
21 // Return struct for ServiceGet call. | |
22 type ServiceGetResults struct { | |
23 Service string | |
24 Charm string | |
25 Settings map[string]interface{} | |
26 } | |
27 | |
28 // ServiceGet returns the configuration for the named service. | 17 // ServiceGet returns the configuration for the named service. |
29 func ServiceGet(st *state.State, p ServiceGetParams) (ServiceGetResults, error)
{ | 18 func ServiceGet(st *state.State, p params.ServiceGet) (params.ServiceGetResults,
error) { |
30 svc, err := st.Service(p.ServiceName) | 19 svc, err := st.Service(p.ServiceName) |
31 if err != nil { | 20 if err != nil { |
32 » » return ServiceGetResults{}, err | 21 » » return params.ServiceGetResults{}, err |
33 } | 22 } |
34 svcfg, err := svc.Config() | 23 svcfg, err := svc.Config() |
35 if err != nil { | 24 if err != nil { |
36 » » return ServiceGetResults{}, err | 25 » » return params.ServiceGetResults{}, err |
37 } | 26 } |
38 charm, _, err := svc.Charm() | 27 charm, _, err := svc.Charm() |
39 if err != nil { | 28 if err != nil { |
40 » » return ServiceGetResults{}, err | 29 » » return params.ServiceGetResults{}, err |
41 } | 30 } |
42 chcfg := charm.Config().Options | 31 chcfg := charm.Config().Options |
43 | 32 |
44 » return ServiceGetResults{ | 33 » return params.ServiceGetResults{ |
45 Service: p.ServiceName, | 34 Service: p.ServiceName, |
46 Charm: charm.Meta().Name, | 35 Charm: charm.Meta().Name, |
47 Settings: merge(svcfg.Map(), chcfg), | 36 Settings: merge(svcfg.Map(), chcfg), |
48 }, nil | 37 }, nil |
49 } | 38 } |
50 | 39 |
51 // Merge service settings and charm schema. | 40 // Merge service settings and charm schema. |
52 func merge(serviceCfg map[string]interface{}, charmCfg map[string]charm.Option)
map[string]interface{} { | 41 func merge(serviceCfg map[string]interface{}, charmCfg map[string]charm.Option)
map[string]interface{} { |
53 results := make(map[string]interface{}) | 42 results := make(map[string]interface{}) |
54 for k, v := range charmCfg { | 43 for k, v := range charmCfg { |
(...skipping 10 matching lines...) Expand all Loading... |
65 } | 54 } |
66 if v.Default != nil { | 55 if v.Default != nil { |
67 if reflect.DeepEqual(v.Default, s) { | 56 if reflect.DeepEqual(v.Default, s) { |
68 m["default"] = true | 57 m["default"] = true |
69 } | 58 } |
70 } | 59 } |
71 results[k] = m | 60 results[k] = m |
72 } | 61 } |
73 return results | 62 return results |
74 } | 63 } |
OLD | NEW |