~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/history.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:
35
35
 
36
36
var statusHistoryDoc = `
37
37
This command will report the history of status changes for
38
 
a given unit.
39
 
The statuses for the unit workload and/or agent are available.
 
38
a given entity.
 
39
The statuses are available for the following types.
40
40
-type supports:
41
 
    agent: will show statuses for the unit's agent
42
 
    workload: will show statuses for the unit's workload
43
 
    combined: will show agent and workload statuses combined
 
41
    juju-unit: will show statuses for the unit's juju agent.
 
42
    workload: will show statuses for the unit's workload.
 
43
    unit: will show workload and juju agent combined for the specified unit.
 
44
    juju-machine: will show statuses for machine's juju agent.
 
45
    machine: will show statuses for machines.
 
46
    juju-container: will show statuses for the container's juju agent.
 
47
    container: will show statuses for containers.
44
48
 and sorted by time of occurrence.
 
49
 The default is unit.
45
50
`
46
51
 
47
52
func (c *statusHistoryCommand) Info() *cmd.Info {
48
53
        return &cmd.Info{
49
54
                Name:    "status-history",
50
 
                Args:    "[-n N] <unit>",
51
 
                Purpose: "output past statuses for a unit",
 
55
                Args:    "[-n N] [--type T] [--utc] <entity name>",
 
56
                Purpose: "output past statuses for the passed entity",
52
57
                Doc:     statusHistoryDoc,
53
58
        }
54
59
}
55
60
 
56
61
func (c *statusHistoryCommand) SetFlags(f *gnuflag.FlagSet) {
57
 
        f.StringVar(&c.outputContent, "type", "combined", "type of statuses to be displayed [agent|workload|combined].")
 
62
        f.StringVar(&c.outputContent, "type", "unit", "type of statuses to be displayed [agent|workload|combined|machine|machineInstance|container|containerinstance].")
58
63
        f.IntVar(&c.backlogSize, "n", 20, "size of logs backlog.")
59
64
        f.BoolVar(&c.isoTime, "utc", false, "display time as UTC in RFC3339 format")
60
65
}
62
67
func (c *statusHistoryCommand) Init(args []string) error {
63
68
        switch {
64
69
        case len(args) > 1:
65
 
                return errors.Errorf("unexpected arguments after unit name.")
 
70
                return errors.Errorf("unexpected arguments after entity name.")
66
71
        case len(args) == 0:
67
 
                return errors.Errorf("unit name is missing.")
 
72
                return errors.Errorf("entity name is missing.")
68
73
        default:
69
74
                c.unitName = args[0]
70
75
        }
81
86
        }
82
87
        kind := params.HistoryKind(c.outputContent)
83
88
        switch kind {
84
 
        case params.KindCombined, params.KindAgent, params.KindWorkload:
 
89
        case params.KindUnit, params.KindUnitAgent, params.KindWorkload,
 
90
                params.KindMachineInstance, params.KindMachine, params.KindContainer,
 
91
                params.KindContainerInstance:
85
92
                return nil
86
 
 
87
93
        }
88
94
        return errors.Errorf("unexpected status type %q", c.outputContent)
89
95
}
91
97
func (c *statusHistoryCommand) Run(ctx *cmd.Context) error {
92
98
        apiclient, err := c.NewAPIClient()
93
99
        if err != nil {
94
 
                return fmt.Errorf(connectionError, c.ConnectionName(), err)
 
100
                return errors.Trace(err)
95
101
        }
96
102
        defer apiclient.Close()
97
 
        var statuses *params.UnitStatusHistory
 
103
        var statuses *params.StatusHistoryResults
98
104
        kind := params.HistoryKind(c.outputContent)
99
 
        statuses, err = apiclient.UnitStatusHistory(kind, c.unitName, c.backlogSize)
 
105
        statuses, err = apiclient.StatusHistory(kind, c.unitName, c.backlogSize)
100
106
        if err != nil {
101
107
                if len(statuses.Statuses) == 0 {
102
108
                        return errors.Trace(err)