1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
10
"launchpad.net/gnuflag"
12
"github.com/juju/juju/apiserver/params"
13
"github.com/juju/juju/cmd/modelcmd"
16
func newFilesystemListCommand() cmd.Command {
17
cmd := &filesystemListCommand{}
18
cmd.newAPIFunc = func() (FilesystemListAPI, error) {
19
return cmd.NewStorageAPI()
21
return modelcmd.Wrap(cmd)
24
const filesystemListCommandDoc = `
25
List filesystems in the model.
29
juju model to operate in
31
specify an output file
33
machine ids for filtering the list
37
// filesystemListCommand lists storage filesystems.
38
type filesystemListCommand struct {
42
newAPIFunc func() (FilesystemListAPI, error)
45
// Init implements Command.Init.
46
func (c *filesystemListCommand) Init(args []string) (err error) {
51
// Info implements Command.Info.
52
func (c *filesystemListCommand) Info() *cmd.Info {
55
Purpose: "list storage filesystems",
56
Doc: filesystemListCommandDoc,
60
// SetFlags implements Command.SetFlags.
61
func (c *filesystemListCommand) SetFlags(f *gnuflag.FlagSet) {
62
c.FilesystemCommandBase.SetFlags(f)
64
c.out.AddFlags(f, "tabular", map[string]cmd.Formatter{
65
"yaml": cmd.FormatYaml,
66
"json": cmd.FormatJson,
67
"tabular": formatFilesystemListTabular,
71
// Run implements Command.Run.
72
func (c *filesystemListCommand) Run(ctx *cmd.Context) (err error) {
73
api, err := c.newAPIFunc()
79
results, err := api.ListFilesystems(c.Ids)
83
// filter out valid output, if any
84
var valid []params.FilesystemDetails
85
for _, result := range results {
86
if result.Error == nil {
87
valid = append(valid, result.Result...)
90
// display individual error
91
fmt.Fprintf(ctx.Stderr, "%v\n", result.Error)
96
info, err := convertToFilesystemInfo(valid)
101
var output interface{}
102
switch c.out.Name() {
104
output = map[string]map[string]FilesystemInfo{"filesystems": info}
108
return c.out.Write(ctx, output)
111
// FilesystemListAPI defines the API methods that the filesystem list command use.
112
type FilesystemListAPI interface {
114
ListFilesystems(machines []string) ([]params.FilesystemDetailsListResult, error)