Class: SANStore::CLI::Commands::DeleteVol

Inherits:
Cri::Command show all
Defined in:
lib/SANStore/cli/commands/delete_vol.rb

Overview

The new_vol command adds a new ZFS volume to the specified volume store, and sets it up as an iSCSI target. Defaults are supplied to all arguments, but can be overridden by the user for slightly customised set-up of the volume store. However, the user interface should be kept as simple as possible.

Author:

  • David Love

Instance Attribute Summary

Attributes inherited from Cri::Command

#base

Instance Method Summary collapse

Methods inherited from Cri::Command

#<=>, #help

Instance Method Details

#aliasesObject

The aliases this sub-command is known by



44
45
46
47
48
# File 'lib/SANStore/cli/commands/delete_vol.rb', line 44

def aliases
  [
    "rm", "delete", "rm_vol"
  ]
end

#long_descObject

A longer description, detailing both the purpose and the use of this command



57
58
59
60
61
62
63
64
65
66
# File 'lib/SANStore/cli/commands/delete_vol.rb', line 57

def long_desc
  'This command deletes the specified target from the pool, and ' +
  'unlinks the volume store backing the target. Since the underlying ' +
  'volume store is destroyed, this action is ' + ANSI.bold{ "irreversible" } +
  'and so this command should be used with ' + ANSI.bold{ "great" } + 'care.' +
  "\n\n" +
  'NOTE: Any clients attached to the volume will have their ' +
  'iSCSI session forcibly closed. This may result in the premature ' +
  'death of the client if care is not taken.'
end

#nameObject

The name of the sub-command (as it appears in the command line app)



39
40
41
# File 'lib/SANStore/cli/commands/delete_vol.rb', line 39

def name
  'delete_vol'
end

#option_definitionsObject

Define the options for this command



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/SANStore/cli/commands/delete_vol.rb', line 74

def option_definitions
  [
    { :short => 'v', :long => 'volume_store', :argument => :optional,
      :desc => 'specifify the ZFS root of the new iSCSI volume. Defaults to "store/volumes".'
    },
    { :short => 'n', :long => 'name', :argument => :optional,
      :desc => 'the name of the new volume. This must be a valid ZFS volume name, and defaults to ' +
        'an RFC 4122 GUID.'
    },
    { :short => 's', :long => 'size', :argument => :optional,
      :desc => 'the size of the new iSCSI volume. Note that while ZFS allows you to change the size ' +
        'of the new volume relatively easily, because the iSCSI initiator sees this volume as a raw ' +
        'device changing the size later may be very easy or very difficult depending on the initiators ' +
        'operating system (and the specific file system being used). In other words, choose with care: ' +
        'by default this command uses a size of 20G, which should be enough for most tasks in the labs.'  
    },
  ]
end

#run(options, arguments) ⇒ Object

Execute the command



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/SANStore/cli/commands/delete_vol.rb', line 94

def run(options, arguments)

  # Check that we have been given a name
  if arguments.size > 1
    SANStore::CLI::Logger.instance.log_level(:high, :error, "You must specify the name of the target to remove")
    exit 1
  end

  # Delete the iSCSI target
  SANStore::CLI::Logger.instance.log_level(:high, :delete, "Removing target #{arguments[0]}")
  zfs_volume = COMStar.delete_target(arguments[0])
  
  # Remove the underlying ZFS store
  SANStore::CLI::Logger.instance.log_level(:low, :delete, "Removing ZFS store for #{arguments[0]}")
  ZFS.delete_volume(zfs_volume)    
end

#short_descObject

A short help text describing the purpose of this command



51
52
53
# File 'lib/SANStore/cli/commands/delete_vol.rb', line 51

def short_desc
  'Remove the specified target from the iSCSI volume store.'
end

#usageObject

Show the user the basic syntax of this command



69
70
71
# File 'lib/SANStore/cli/commands/delete_vol.rb', line 69

def usage
  "store delete_vol SHARE_NAME"
end