~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/storage/filesystem.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:
4
4
package storage
5
5
 
6
6
import (
 
7
        "fmt"
 
8
 
7
9
        "github.com/juju/cmd"
8
10
        "github.com/juju/errors"
9
11
        "github.com/juju/names"
10
12
 
11
13
        "github.com/juju/juju/apiserver/params"
12
 
        jujucmd "github.com/juju/juju/cmd"
13
14
        "github.com/juju/juju/cmd/juju/common"
14
15
)
15
16
 
16
 
const filesystemCmdDoc = `
17
 
"juju storage filesystem" is used to manage storage filesystems in
18
 
 the Juju model.
19
 
`
20
 
 
21
 
const filesystemCmdPurpose = "manage storage filesystems"
22
 
 
23
 
// NewFilesystemSuperCommand creates the storage filesystem super subcommand and
24
 
// registers the subcommands that it supports.
25
 
func NewFilesystemSuperCommand() cmd.Command {
26
 
        supercmd := jujucmd.NewSubSuperCommand(cmd.SuperCommandParams{
27
 
                Name:        "filesystem",
28
 
                Doc:         filesystemCmdDoc,
29
 
                UsagePrefix: "juju storage",
30
 
                Purpose:     filesystemCmdPurpose,
31
 
        })
32
 
        supercmd.Register(newFilesystemListCommand())
33
 
        return supercmd
34
 
}
35
 
 
36
17
// FilesystemCommandBase is a helper base structure for filesystem commands.
37
18
type FilesystemCommandBase struct {
38
19
        StorageCommandBase
70
51
        ReadOnly   bool   `yaml:"read-only" json:"read-only"`
71
52
}
72
53
 
 
54
// generateListFilesystemOutput returns a map filesystem IDs to filesystem info
 
55
func (c *listCommand) generateListFilesystemsOutput(ctx *cmd.Context, api StorageListAPI) (output interface{}, err error) {
 
56
 
 
57
        results, err := api.ListFilesystems(c.ids)
 
58
        if err != nil {
 
59
                return nil, err
 
60
        }
 
61
 
 
62
        // filter out valid output, if any
 
63
        var valid []params.FilesystemDetails
 
64
        for _, result := range results {
 
65
                if result.Error == nil {
 
66
                        valid = append(valid, result.Result...)
 
67
                        continue
 
68
                }
 
69
                // display individual error
 
70
                fmt.Fprintf(ctx.Stderr, "%v\n", result.Error)
 
71
        }
 
72
        if len(valid) == 0 {
 
73
                return nil, nil
 
74
        }
 
75
        info, err := convertToFilesystemInfo(valid)
 
76
        if err != nil {
 
77
                return nil, err
 
78
        }
 
79
        switch c.out.Name() {
 
80
        case "yaml", "json":
 
81
                output = map[string]map[string]FilesystemInfo{"filesystems": info}
 
82
        default:
 
83
                output = info
 
84
        }
 
85
 
 
86
        return output, nil
 
87
}
 
88
 
73
89
// convertToFilesystemInfo returns a map of filesystem IDs to filesystem info.
74
90
func convertToFilesystemInfo(all []params.FilesystemDetails) (map[string]FilesystemInfo, error) {
75
91
        result := make(map[string]FilesystemInfo)