~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/juju/status/output_tabular.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
        "github.com/juju/utils/set"
16
16
        "gopkg.in/juju/charm.v6-unstable/hooks"
17
17
 
18
 
        "github.com/juju/juju/apiserver/params"
19
18
        "github.com/juju/juju/cmd/juju/common"
20
19
        "github.com/juju/juju/instance"
 
20
        "github.com/juju/juju/status"
21
21
)
22
22
 
23
23
type statusRelation struct {
37
37
}
38
38
 
39
39
type relationFormatter struct {
40
 
        relationIndex []string
 
40
        relationIndex set.Strings
41
41
        relations     map[string]*statusRelation
42
42
}
43
43
 
44
44
func newRelationFormatter() *relationFormatter {
45
45
        return &relationFormatter{
46
 
                relations: make(map[string]*statusRelation),
 
46
                relationIndex: set.NewStrings(),
 
47
                relations:     make(map[string]*statusRelation),
47
48
        }
48
49
}
49
50
 
50
51
func (r *relationFormatter) len() int {
51
 
        return len(r.relationIndex)
 
52
        return r.relationIndex.Size()
52
53
}
53
54
 
54
55
func (r *relationFormatter) add(rel1, rel2, relation string, is2SubOf1 bool) {
63
64
                relation:    relation,
64
65
                subordinate: is2SubOf1,
65
66
        }
66
 
        r.relationIndex = append(r.relationIndex, k)
 
67
        r.relationIndex.Add(k)
67
68
}
68
69
 
69
70
func (r *relationFormatter) sorted() []string {
70
 
        sort.Sort(sort.StringSlice(r.relationIndex))
71
 
        return r.relationIndex
 
71
        return r.relationIndex.SortedValues()
72
72
}
73
73
 
74
74
func (r *relationFormatter) get(k string) *statusRelation {
137
137
 
138
138
        pUnit := func(name string, u unitStatus, level int) {
139
139
                message := u.WorkloadStatusInfo.Message
140
 
                agentDoing := agentDoing(u.AgentStatusInfo)
 
140
                agentDoing := agentDoing(u.JujuStatusInfo)
141
141
                if agentDoing != "" {
142
142
                        message = fmt.Sprintf("(%s) %s", agentDoing, message)
143
143
                }
144
144
                p(
145
145
                        indent("", level*2, name),
146
146
                        u.WorkloadStatusInfo.Current,
147
 
                        u.AgentStatusInfo.Current,
148
 
                        u.AgentStatusInfo.Version,
 
147
                        u.JujuStatusInfo.Current,
 
148
                        u.JujuStatusInfo.Version,
149
149
                        u.Machine,
150
150
                        strings.Join(u.OpenedPorts, ","),
151
151
                        u.PublicAddress,
153
153
                )
154
154
        }
155
155
 
156
 
        header := []string{"ID", "WORKLOAD-STATE", "AGENT-STATE", "VERSION", "MACHINE", "PORTS", "PUBLIC-ADDRESS", "MESSAGE"}
 
156
        header := []string{"ID", "WORKLOAD-STATUS", "JUJU-STATUS", "VERSION", "MACHINE", "PORTS", "PUBLIC-ADDRESS", "MESSAGE"}
157
157
 
158
158
        p("\n[Units]")
159
159
        p(strings.Join(header, "\t"))
178
178
                if hw.AvailabilityZone != nil {
179
179
                        az = *hw.AvailabilityZone
180
180
                }
181
 
                p(m.Id, m.AgentState, m.DNSName, m.InstanceId, m.Series, az)
 
181
                p(m.Id, m.JujuStatus.Current, m.DNSName, m.InstanceId, m.Series, az)
182
182
        }
183
183
        tw.Flush()
184
184
        return out.Bytes(), nil
213
213
                if hw.AvailabilityZone != nil {
214
214
                        az = *hw.AvailabilityZone
215
215
                }
216
 
                p(m.Id, m.AgentState, m.DNSName, m.InstanceId, m.Series, az)
 
216
                p(m.Id, m.JujuStatus.Current, m.DNSName, m.InstanceId, m.Series, az)
217
217
        }
218
218
        tw.Flush()
219
219
 
223
223
// agentDoing returns what hook or action, if any,
224
224
// the agent is currently executing.
225
225
// The hook name or action is extracted from the agent message.
226
 
func agentDoing(status statusInfoContents) string {
227
 
        if status.Current != params.StatusExecuting {
 
226
func agentDoing(agentStatus statusInfoContents) string {
 
227
        if agentStatus.Current != status.StatusExecuting {
228
228
                return ""
229
229
        }
230
230
        // First see if we can determine a hook name.
236
236
                hookNames = append(hookNames, string(h))
237
237
        }
238
238
        hookExp := regexp.MustCompile(fmt.Sprintf(`running (?P<hook>%s?) hook`, strings.Join(hookNames, "|")))
239
 
        match := hookExp.FindStringSubmatch(status.Message)
 
239
        match := hookExp.FindStringSubmatch(agentStatus.Message)
240
240
        if len(match) > 0 {
241
241
                return match[1]
242
242
        }
243
243
        // Now try for an action name.
244
244
        actionExp := regexp.MustCompile(`running action (?P<action>.*)`)
245
 
        match = actionExp.FindStringSubmatch(status.Message)
 
245
        match = actionExp.FindStringSubmatch(agentStatus.Message)
246
246
        if len(match) > 0 {
247
247
                return match[1]
248
248
        }