Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(682)

Delta Between Two Patch Sets: state/api/apiclient.go

Issue 7444052: Add a CharmInfo API command.
Left Patch Set: Created 12 years, 1 month ago
Right Patch Set: Add a CharmInfo API command. Created 12 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « [revision details] ('k') | state/api/params/params.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 package api 1 package api
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "launchpad.net/juju-core/charm" 5 "launchpad.net/juju-core/charm"
6 "launchpad.net/juju-core/log" 6 "launchpad.net/juju-core/log"
7 » "launchpad.net/juju-core/state/statecmd" 7 » "launchpad.net/juju-core/state/api/params"
8 "launchpad.net/tomb" 8 "launchpad.net/tomb"
9 "strings" 9 "strings"
10 "sync" 10 "sync"
11 ) 11 )
12 12
13 // Machine represents the state of a machine. 13 // Machine represents the state of a machine.
14 type Machine struct { 14 type Machine struct {
15 st *State 15 st *State
16 id string 16 id string
17 » doc rpcMachine 17 » doc params.Machine
18 } 18 }
19 19
20 // Client represents the client-accessible part of the state. 20 // Client represents the client-accessible part of the state.
21 type Client struct { 21 type Client struct {
22 st *State 22 st *State
23 } 23 }
24 24
25 // Client returns an object that can be used 25 // Client returns an object that can be used
26 // to access client-specific functionality. 26 // to access client-specific functionality.
27 func (st *State) Client() *Client { 27 func (st *State) Client() *Client {
(...skipping 15 matching lines...) Expand all
43 func (c *Client) Status() (*Status, error) { 43 func (c *Client) Status() (*Status, error) {
44 var s Status 44 var s Status
45 if err := c.st.call("Client", "", "Status", nil, &s); err != nil { 45 if err := c.st.call("Client", "", "Status", nil, &s); err != nil {
46 return nil, err 46 return nil, err
47 } 47 }
48 return &s, nil 48 return &s, nil
49 } 49 }
50 50
51 // ServiceSet sets configuration options on a service. 51 // ServiceSet sets configuration options on a service.
52 func (c *Client) ServiceSet(service string, options map[string]string) error { 52 func (c *Client) ServiceSet(service string, options map[string]string) error {
53 » p := statecmd.ServiceSetParams{ 53 » p := params.ServiceSet{
54 ServiceName: service, 54 ServiceName: service,
55 Options: options, 55 Options: options,
56 } 56 }
57 err := c.st.client.Call("Client", "", "ServiceSet", p, nil) 57 err := c.st.client.Call("Client", "", "ServiceSet", p, nil)
58 return clientError(err) 58 return clientError(err)
59 } 59 }
60 60
61 // ServiceSetYAML sets configuration options on a service 61 // ServiceSetYAML sets configuration options on a service
62 // given options in YAML format. 62 // given options in YAML format.
63 func (c *Client) ServiceSetYAML(service string, yaml string) error { 63 func (c *Client) ServiceSetYAML(service string, yaml string) error {
64 » p := statecmd.ServiceSetYAMLParams{ 64 » p := params.ServiceSetYAML{
65 ServiceName: service, 65 ServiceName: service,
66 Config: yaml, 66 Config: yaml,
67 } 67 }
68 err := c.st.client.Call("Client", "", "ServiceSetYAML", p, nil) 68 err := c.st.client.Call("Client", "", "ServiceSetYAML", p, nil)
69 return clientError(err) 69 return clientError(err)
70 } 70 }
71 71
72 // ServiceGet returns the configuration for the named service. 72 // ServiceGet returns the configuration for the named service.
73 func (c *Client) ServiceGet(service string) (*statecmd.ServiceGetResults, error) { 73 func (c *Client) ServiceGet(service string) (*params.ServiceGetResults, error) {
74 » var results statecmd.ServiceGetResults 74 » var results params.ServiceGetResults
75 » params := statecmd.ServiceGetParams{ServiceName: service} 75 » params := params.ServiceGet{ServiceName: service}
76 err := c.st.client.Call("Client", "", "ServiceGet", params, &results) 76 err := c.st.client.Call("Client", "", "ServiceGet", params, &results)
77 if err != nil { 77 if err != nil {
78 return nil, clientError(err) 78 return nil, clientError(err)
79 } 79 }
80 return &results, nil 80 return &results, nil
81 } 81 }
82 82
83 // ServiceExpose changes the juju-managed firewall to expose any ports that 83 // ServiceExpose changes the juju-managed firewall to expose any ports that
84 // were also explicitly marked by units as open. 84 // were also explicitly marked by units as open.
85 func (c *Client) ServiceExpose(service string) error { 85 func (c *Client) ServiceExpose(service string) error {
86 » params := statecmd.ServiceExposeParams{ServiceName: service} 86 » params := params.ServiceExpose{ServiceName: service}
87 err := c.st.client.Call("Client", "", "ServiceExpose", params, nil) 87 err := c.st.client.Call("Client", "", "ServiceExpose", params, nil)
88 if err != nil { 88 if err != nil {
89 return clientError(err) 89 return clientError(err)
90 } 90 }
91 return nil 91 return nil
92 } 92 }
93 93
94 // ServiceUnexpose changes the juju-managed firewall to unexpose any ports that 94 // ServiceUnexpose changes the juju-managed firewall to unexpose any ports that
95 // were also explicitly marked by units as open. 95 // were also explicitly marked by units as open.
96 func (c *Client) ServiceUnexpose(service string) error { 96 func (c *Client) ServiceUnexpose(service string) error {
97 » params := statecmd.ServiceUnexposeParams{ServiceName: service} 97 » params := params.ServiceUnexpose{ServiceName: service}
98 err := c.st.client.Call("Client", "", "ServiceUnexpose", params, nil) 98 err := c.st.client.Call("Client", "", "ServiceUnexpose", params, nil)
99 if err != nil { 99 if err != nil {
100 return clientError(err) 100 return clientError(err)
101 } 101 }
102 return nil 102 return nil
103 } 103 }
104 104
105 // CharmInfo holds information about a charm. 105 // CharmInfo holds information about a charm.
106 type CharmInfo struct { 106 type CharmInfo struct {
107 » Name string 107 » Revision int
108 » Revision int 108 » URL string
109 » Subordinate bool 109 » Config *charm.Config
110 » URL string 110 » Meta *charm.Meta
111 » Config *charm.Config
112 » Peers map[string]charm.Relation
113 » Provides map[string]charm.Relation
114 » Requires map[string]charm.Relation
115 }
116
117 // CharmInfoParams stores parameters for making the CharmInfo call.
118 type CharmInfoParams struct {
119 » CharmURL string
120 } 111 }
121 112
122 // CharmInfo returns information about the requested charm. 113 // CharmInfo returns information about the requested charm.
123 func (c *Client) CharmInfo(charmURL string) (*CharmInfo, error) { 114 func (c *Client) CharmInfo(charmURL string) (*CharmInfo, error) {
124 » params := CharmInfoParams{CharmURL: charmURL} 115 » args := params.CharmInfo{CharmURL: charmURL}
125 info := new(CharmInfo) 116 info := new(CharmInfo)
126 » err := c.st.client.Call("Client", "", "CharmInfo", params, info) 117 » err := c.st.client.Call("Client", "", "CharmInfo", args, info)
127 if err != nil { 118 if err != nil {
128 return nil, clientError(err) 119 return nil, clientError(err)
129 } 120 }
130 return info, nil 121 return info, nil
131 } 122 }
132 123
133 // EnvironmentInfo holds information about the Juju environment. 124 // EnvironmentInfo holds information about the Juju environment.
134 type EnvironmentInfo struct { 125 type EnvironmentInfo struct {
135 DefaultSeries string 126 DefaultSeries string
136 ProviderType string 127 ProviderType string
(...skipping 18 matching lines...) Expand all
155 if err := m.Refresh(); err != nil { 146 if err := m.Refresh(); err != nil {
156 return nil, err 147 return nil, err
157 } 148 }
158 return m, nil 149 return m, nil
159 } 150 }
160 151
161 // Unit represents the state of a service unit. 152 // Unit represents the state of a service unit.
162 type Unit struct { 153 type Unit struct {
163 st *State 154 st *State
164 name string 155 name string
165 » doc rpcUnit 156 » doc params.Unit
166 } 157 }
167 158
168 // Unit returns a unit by name. 159 // Unit returns a unit by name.
169 func (st *State) Unit(name string) (*Unit, error) { 160 func (st *State) Unit(name string) (*Unit, error) {
170 u := &Unit{ 161 u := &Unit{
171 st: st, 162 st: st,
172 name: name, 163 name: name,
173 } 164 }
174 if err := u.Refresh(); err != nil { 165 if err := u.Refresh(); err != nil {
175 return nil, err 166 return nil, err
176 } 167 }
177 return u, nil 168 return u, nil
178 } 169 }
179 170
180 // Login authenticates as the entity with the given name and password. 171 // Login authenticates as the entity with the given name and password.
181 // Subsequent requests on the state will act as that entity. 172 // Subsequent requests on the state will act as that entity.
182 // This method is usually called automatically by Open. 173 // This method is usually called automatically by Open.
183 func (st *State) Login(entityName, password string) error { 174 func (st *State) Login(entityName, password string) error {
184 » return st.call("Admin", "", "Login", &rpcCreds{ 175 » return st.call("Admin", "", "Login", &params.Creds{
185 EntityName: entityName, 176 EntityName: entityName,
186 Password: password, 177 Password: password,
187 }, nil) 178 }, nil)
188 } 179 }
189 180
190 // Id returns the machine id. 181 // Id returns the machine id.
191 func (m *Machine) Id() string { 182 func (m *Machine) Id() string {
192 return m.id 183 return m.id
193 } 184 }
194 185
(...skipping 22 matching lines...) Expand all
217 } 208 }
218 209
219 // InstanceId returns the provider specific instance id for this machine 210 // InstanceId returns the provider specific instance id for this machine
220 // and whether it has been set. 211 // and whether it has been set.
221 func (m *Machine) InstanceId() (string, bool) { 212 func (m *Machine) InstanceId() (string, bool) {
222 return m.doc.InstanceId, m.doc.InstanceId != "" 213 return m.doc.InstanceId, m.doc.InstanceId != ""
223 } 214 }
224 215
225 // SetPassword sets the password for the machine's agent. 216 // SetPassword sets the password for the machine's agent.
226 func (m *Machine) SetPassword(password string) error { 217 func (m *Machine) SetPassword(password string) error {
227 » return m.st.call("Machine", m.id, "SetPassword", &rpcPassword{ 218 » return m.st.call("Machine", m.id, "SetPassword", &params.Password{
228 Password: password, 219 Password: password,
229 }, nil) 220 }, nil)
230 } 221 }
231 222
232 func (m *Machine) Watch() *EntityWatcher { 223 func (m *Machine) Watch() *EntityWatcher {
233 return newEntityWatcher(m.st, "Machine", m.id) 224 return newEntityWatcher(m.st, "Machine", m.id)
234 } 225 }
235 226
236 type EntityWatcher struct { 227 type EntityWatcher struct {
237 tomb tomb.Tomb 228 tomb tomb.Tomb
(...skipping 14 matching lines...) Expand all
252 go func() { 243 go func() {
253 defer w.tomb.Done() 244 defer w.tomb.Done()
254 defer close(w.out) 245 defer close(w.out)
255 defer w.wg.Wait() // Wait for watcher to be stopped. 246 defer w.wg.Wait() // Wait for watcher to be stopped.
256 w.tomb.Kill(w.loop()) 247 w.tomb.Kill(w.loop())
257 }() 248 }()
258 return w 249 return w
259 } 250 }
260 251
261 func (w *EntityWatcher) loop() error { 252 func (w *EntityWatcher) loop() error {
262 » var id rpcEntityWatcherId 253 » var id params.EntityWatcherId
263 if err := w.st.call(w.etype, w.eid, "Watch", nil, &id); err != nil { 254 if err := w.st.call(w.etype, w.eid, "Watch", nil, &id); err != nil {
264 return err 255 return err
265 } 256 }
266 callWatch := func(request string) error { 257 callWatch := func(request string) error {
267 return w.st.call("EntityWatcher", id.EntityWatcherId, request, n il, nil) 258 return w.st.call("EntityWatcher", id.EntityWatcherId, request, n il, nil)
268 } 259 }
269 w.wg.Add(1) 260 w.wg.Add(1)
270 go func() { 261 go func() {
271 // When the EntityWatcher has been stopped, we send a 262 // When the EntityWatcher has been stopped, we send a
272 // Stop request to the server, which will remove the 263 // Stop request to the server, which will remove the
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 } 314 }
324 315
325 // Refresh refreshes the contents of the Unit from the underlying 316 // Refresh refreshes the contents of the Unit from the underlying
326 // state. TODO(rog) It returns a NotFoundError if the unit has been removed. 317 // state. TODO(rog) It returns a NotFoundError if the unit has been removed.
327 func (u *Unit) Refresh() error { 318 func (u *Unit) Refresh() error {
328 return u.st.call("Unit", u.name, "Get", nil, &u.doc) 319 return u.st.call("Unit", u.name, "Get", nil, &u.doc)
329 } 320 }
330 321
331 // SetPassword sets the password for the unit's agent. 322 // SetPassword sets the password for the unit's agent.
332 func (u *Unit) SetPassword(password string) error { 323 func (u *Unit) SetPassword(password string) error {
333 » return u.st.call("Unit", u.name, "SetPassword", &rpcPassword{ 324 » return u.st.call("Unit", u.name, "SetPassword", &params.Password{
334 Password: password, 325 Password: password,
335 }, nil) 326 }, nil)
336 } 327 }
337 328
338 // UnitEntityName returns the entity name for the 329 // UnitEntityName returns the entity name for the
339 // unit with the given name. 330 // unit with the given name.
340 func UnitEntityName(unitName string) string { 331 func UnitEntityName(unitName string) string {
341 return "unit-" + strings.Replace(unitName, "/", "-", -1) 332 return "unit-" + strings.Replace(unitName, "/", "-", -1)
342 } 333 }
343 334
344 // EntityName returns a name identifying the unit that is safe to use 335 // EntityName returns a name identifying the unit that is safe to use
345 // as a file name. The returned name will be different from other 336 // as a file name. The returned name will be different from other
346 // EntityName values returned by any other entities from the same state. 337 // EntityName values returned by any other entities from the same state.
347 func (u *Unit) EntityName() string { 338 func (u *Unit) EntityName() string {
348 return UnitEntityName(u.name) 339 return UnitEntityName(u.name)
349 } 340 }
350 341
351 // DeployerName returns the entity name of the agent responsible for deploying 342 // DeployerName returns the entity name of the agent responsible for deploying
352 // the unit. If no such entity can be determined, false is returned. 343 // the unit. If no such entity can be determined, false is returned.
353 func (u *Unit) DeployerName() (string, bool) { 344 func (u *Unit) DeployerName() (string, bool) {
354 return u.doc.DeployerName, u.doc.DeployerName != "" 345 return u.doc.DeployerName, u.doc.DeployerName != ""
355 } 346 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b