command_volume_delete.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package shell
  2. import (
  3. "fmt"
  4. "io"
  5. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  6. )
  7. func init() {
  8. Commands = append(Commands, &commandVolumeDelete{})
  9. }
  10. type commandVolumeDelete struct {
  11. }
  12. func (c *commandVolumeDelete) Name() string {
  13. return "volume.delete"
  14. }
  15. func (c *commandVolumeDelete) Help() string {
  16. return `delete a live volume from one volume server
  17. volume.delete <volume server host:port> <volume id>
  18. This command deletes a volume from one volume server.
  19. `
  20. }
  21. func (c *commandVolumeDelete) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  22. if len(args) != 2 {
  23. fmt.Fprintf(writer, "received args: %+v\n", args)
  24. return fmt.Errorf("need 2 args of <volume server host:port> <volume id>")
  25. }
  26. sourceVolumeServer, volumeIdString := args[0], args[1]
  27. volumeId, err := needle.NewVolumeId(volumeIdString)
  28. if err != nil {
  29. return fmt.Errorf("wrong volume id format %s: %v", volumeId, err)
  30. }
  31. return deleteVolume(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer)
  32. }