command_volume_delete.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package shell
  2. import (
  3. "flag"
  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 -node <volume server host:port> -volumeId <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 err = commandEnv.confirmIsLocked(); err != nil {
  23. return
  24. }
  25. volDeleteCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  26. volumeIdInt := volDeleteCommand.Int("volumeId", 0, "the volume id")
  27. nodeStr := volDeleteCommand.String("node", "", "the volume server <host>:<port>")
  28. if err = volDeleteCommand.Parse(args); err != nil {
  29. return nil
  30. }
  31. sourceVolumeServer := *nodeStr
  32. volumeId := needle.VolumeId(*volumeIdInt)
  33. return deleteVolume(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer)
  34. }