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

Side by Side Diff: cmd/juju/status.go

Issue 8561046: cmd/juju: status displays machine errors (Closed)
Patch Set: Created 10 years, 11 months 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:
View unified diff | Download patch
« no previous file with comments | « [revision details] ('k') | cmd/juju/status_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package main 1 package main
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "launchpad.net/gnuflag" 5 "launchpad.net/gnuflag"
6 "launchpad.net/juju-core/cmd" 6 "launchpad.net/juju-core/cmd"
7 "launchpad.net/juju-core/environs" 7 "launchpad.net/juju-core/environs"
8 "launchpad.net/juju-core/juju" 8 "launchpad.net/juju-core/juju"
9 "launchpad.net/juju-core/state" 9 "launchpad.net/juju-core/state"
10 "launchpad.net/juju-core/state/api/params" 10 "launchpad.net/juju-core/state/api/params"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 func processMachine(machine *state.Machine, instance environs.Instance) (map[str ing]interface{}, error) { 131 func processMachine(machine *state.Machine, instance environs.Instance) (map[str ing]interface{}, error) {
132 r := m() 132 r := m()
133 r["instance-id"] = instance.Id() 133 r["instance-id"] = instance.Id()
134 134
135 if dnsname, err := instance.DNSName(); err == nil { 135 if dnsname, err := instance.DNSName(); err == nil {
136 r["dns-name"] = dnsname 136 r["dns-name"] = dnsname
137 } 137 }
138 138
139 processVersion(r, machine) 139 processVersion(r, machine)
140 processAgentStatus(r, machine)
141 140
142 » // TODO(dfc) unit-status 141 » // The following logic is ported from Python juju status command.
142 » agentAlive, err := machine.AgentAlive()
143 » if err != nil {
144 » » return nil, err
145 » }
146 » machineDead := machine.Life() == state.Dead
147 » status, info, err := machine.Status()
148 » if err != nil {
149 » » return nil, err
150 » }
151 » r["agent-state"] = "running"
152 » if !agentAlive && !machineDead {
153 » » // Agent should be running but it's not.
154 » » r["agent-state"] = "down"
155 » } else if !agentAlive || status == params.MachineError {
156 » » // Either the provisioning failed, or the agent is still startin g.
157 » » r["agent-state"] = "not-started"
fwereade 2013/04/10 16:58:25 agent-state needs to hold status, and agent-status
158 » }
159
160 » r["instance-state"] = status
fwereade 2013/04/10 16:58:25 This should be the status reported by the instance
161 » if len(info) > 0 {
rog 2013/04/10 15:23:03 could we make this: if info != "" { so it's
dimitern 2013/04/10 16:29:17 Sure, done.
162 » » r["instance-state-info"] = info
163 » }
164
143 return r, nil 165 return r, nil
144 } 166 }
145 167
146 // processServices gathers information about services. 168 // processServices gathers information about services.
147 func processServices(services map[string]*state.Service) (map[string]interface{} , error) { 169 func processServices(services map[string]*state.Service) (map[string]interface{} , error) {
148 r := m() 170 r := m()
149 for _, s := range services { 171 for _, s := range services {
150 r[s.Name()] = checkError(processService(s)) 172 r[s.Name()] = checkError(processService(s))
151 } 173 }
152 return r, nil 174 return r, nil
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 type versioned interface { 246 type versioned interface {
225 AgentTools() (*state.Tools, error) 247 AgentTools() (*state.Tools, error)
226 } 248 }
227 249
228 func processVersion(r map[string]interface{}, v versioned) { 250 func processVersion(r map[string]interface{}, v versioned) {
229 if t, err := v.AgentTools(); err == nil { 251 if t, err := v.AgentTools(); err == nil {
230 r["agent-version"] = t.Binary.Number.String() 252 r["agent-version"] = t.Binary.Number.String()
231 } 253 }
232 } 254 }
233 255
234 type agentAliver interface {
235 AgentAlive() (bool, error)
236 }
237
238 func processAgentStatus(r map[string]interface{}, a agentAliver) {
239 if alive, err := a.AgentAlive(); err == nil && alive {
240 r["agent-state"] = "running"
241 }
242 }
243
244 func m() map[string]interface{} { return make(map[string]interface{}) } 256 func m() map[string]interface{} { return make(map[string]interface{}) }
245 257
246 func checkError(m map[string]interface{}, err error) map[string]interface{} { 258 func checkError(m map[string]interface{}, err error) map[string]interface{} {
247 if err != nil { 259 if err != nil {
248 return map[string]interface{}{"status-error": err.Error()} 260 return map[string]interface{}{"status-error": err.Error()}
249 } 261 }
250 return m 262 return m
251 } 263 }
OLDNEW
« no previous file with comments | « [revision details] ('k') | cmd/juju/status_test.go » ('j') | no next file with comments »

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