You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1 KiB

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