2016-11-05 17:09:05 -07:00
|
|
|
/*
|
|
|
|
|
Copyright 2016 The Rook Authors. All rights reserved.
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
2016-12-01 16:10:46 -08:00
|
|
|
package pool
|
2016-09-15 13:52:55 -07:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"fmt"
|
2016-10-19 15:40:40 -07:00
|
|
|
"os"
|
2016-09-15 13:52:55 -07:00
|
|
|
|
2017-06-20 12:10:30 -07:00
|
|
|
"github.com/rook/rook/cmd/rookctl/rook"
|
2016-10-26 00:38:39 +02:00
|
|
|
"github.com/rook/rook/pkg/model"
|
2016-10-27 13:26:25 +02:00
|
|
|
"github.com/rook/rook/pkg/rook/client"
|
2016-10-26 00:38:39 +02:00
|
|
|
"github.com/rook/rook/pkg/util/display"
|
|
|
|
|
"github.com/rook/rook/pkg/util/flags"
|
2016-09-15 13:52:55 -07:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
2016-12-01 16:10:46 -08:00
|
|
|
var listCmd = &cobra.Command{
|
2017-09-15 14:52:24 -07:00
|
|
|
Use: "list",
|
|
|
|
|
Short: "Gets a listing with details of all storage pools in the cluster",
|
|
|
|
|
Aliases: []string{"ls"},
|
2016-09-15 13:52:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
2016-12-01 16:10:46 -08:00
|
|
|
listCmd.RunE = listPoolsEntry
|
2016-09-15 13:52:55 -07:00
|
|
|
}
|
|
|
|
|
|
2016-09-20 15:20:17 -07:00
|
|
|
func listPoolsEntry(cmd *cobra.Command, args []string) error {
|
2016-12-01 16:10:46 -08:00
|
|
|
rook.SetupLogging()
|
|
|
|
|
|
2016-09-29 17:09:21 -07:00
|
|
|
if err := flags.VerifyRequiredFlags(cmd, []string{}); err != nil {
|
2016-09-15 13:52:55 -07:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 17:29:53 -08:00
|
|
|
c := rook.NewRookNetworkRestClient()
|
2016-09-20 15:20:17 -07:00
|
|
|
out, err := listPools(c)
|
2016-09-15 13:52:55 -07:00
|
|
|
if err != nil {
|
2016-10-19 15:40:40 -07:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
|
os.Exit(1)
|
2016-09-15 13:52:55 -07:00
|
|
|
}
|
|
|
|
|
|
2016-09-28 09:59:01 -07:00
|
|
|
fmt.Print(out)
|
2016-09-15 13:52:55 -07:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-27 13:26:25 +02:00
|
|
|
func listPools(c client.RookRestClient) (string, error) {
|
2016-09-20 15:20:17 -07:00
|
|
|
pools, err := c.GetPools()
|
2016-09-15 13:52:55 -07:00
|
|
|
if err != nil {
|
2016-09-20 15:20:17 -07:00
|
|
|
return "", fmt.Errorf("failed to get pools: %+v", err)
|
2016-09-15 13:52:55 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-28 17:38:06 -08:00
|
|
|
if len(pools) == 0 {
|
|
|
|
|
return "", nil
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-15 13:52:55 -07:00
|
|
|
var buffer bytes.Buffer
|
2016-12-01 16:10:46 -08:00
|
|
|
w := rook.NewTableWriter(&buffer)
|
2016-09-28 09:59:01 -07:00
|
|
|
|
2016-10-11 21:05:33 -07:00
|
|
|
fmt.Fprintln(w, "NAME\tNUMBER\tTYPE\tSIZE\tDATA\tCODING\tALGORITHM")
|
2016-09-15 13:52:55 -07:00
|
|
|
|
2016-09-20 15:20:17 -07:00
|
|
|
for _, p := range pools {
|
2016-10-11 21:05:33 -07:00
|
|
|
fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\t%s\t%s\n", p.Name, p.Number, model.PoolTypeToString(p.Type),
|
2017-09-11 14:56:10 -07:00
|
|
|
display.NumToStrOmitEmpty(p.ReplicatedConfig.Size),
|
2016-10-11 21:05:33 -07:00
|
|
|
display.NumToStrOmitEmpty(p.ErasureCodedConfig.DataChunkCount),
|
|
|
|
|
display.NumToStrOmitEmpty(p.ErasureCodedConfig.CodingChunkCount),
|
|
|
|
|
p.ErasureCodedConfig.Algorithm)
|
2016-09-15 13:52:55 -07:00
|
|
|
}
|
|
|
|
|
|
2016-09-28 09:59:01 -07:00
|
|
|
w.Flush()
|
2016-09-15 13:52:55 -07:00
|
|
|
return buffer.String(), nil
|
|
|
|
|
}
|