mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-21 10:37:24 +08:00
weed shell: list volumes
This commit is contained in:
@@ -30,7 +30,7 @@ func (c *commandCollectionList) Do(args []string, commandEnv *commandEnv, writer
|
||||
}
|
||||
|
||||
for _, c := range resp.Collections {
|
||||
fmt.Fprintf(writer, "collection:\"%s\"\treplication:\"%s\"\tTTL:\"%s\"\n", c.GetName(), c.GetReplication(), c.GetTtl())
|
||||
fmt.Fprintf(writer, "collection:\"%s\"\n", c.GetName())
|
||||
}
|
||||
|
||||
fmt.Fprintf(writer, "Total %d collections.\n", len(resp.Collections))
|
||||
|
64
weed/shell/command_volume_list.go
Normal file
64
weed/shell/command_volume_list.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||
"io"
|
||||
)
|
||||
|
||||
func init() {
|
||||
commands = append(commands, &commandVolumeList{})
|
||||
}
|
||||
|
||||
type commandVolumeList struct {
|
||||
}
|
||||
|
||||
func (c *commandVolumeList) Name() string {
|
||||
return "volume.list"
|
||||
}
|
||||
|
||||
func (c *commandVolumeList) Help() string {
|
||||
return "# list all volumes"
|
||||
}
|
||||
|
||||
func (c *commandVolumeList) Do(args []string, commandEnv *commandEnv, writer io.Writer) error {
|
||||
|
||||
resp, err := commandEnv.masterClient.VolumeList(context.Background())
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
writeTopologyInfo(writer,resp.TopologyInfo)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeTopologyInfo(writer io.Writer, t *master_pb.TopologyInfo) {
|
||||
fmt.Fprintf(writer, "Topology volume:%d/%d active:%d free:%d\n", t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
|
||||
for _, dc := range t.DataCenterInfos {
|
||||
writeDataCenterInfo(writer, dc)
|
||||
}
|
||||
}
|
||||
func writeDataCenterInfo(writer io.Writer, t *master_pb.DataCenterInfo) {
|
||||
fmt.Fprintf(writer, " DataCenter %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
|
||||
for _, r := range t.RackInfos {
|
||||
writeRackInfo(writer, r)
|
||||
}
|
||||
}
|
||||
func writeRackInfo(writer io.Writer, t *master_pb.RackInfo) {
|
||||
fmt.Fprintf(writer, " Rack %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
|
||||
for _, dn := range t.DataNodeInfos {
|
||||
writeDataNodeInfo(writer, dn)
|
||||
}
|
||||
}
|
||||
func writeDataNodeInfo(writer io.Writer, t *master_pb.DataNodeInfo) {
|
||||
fmt.Fprintf(writer, " DataNode %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
|
||||
for _, vi := range t.VolumeInfos {
|
||||
writeVolumeInformationMessage(writer, vi)
|
||||
}
|
||||
}
|
||||
func writeVolumeInformationMessage(writer io.Writer, t *master_pb.VolumeInformationMessage) {
|
||||
fmt.Fprintf(writer, " volume %+v \n", t)
|
||||
}
|
Reference in New Issue
Block a user