Class: SANStore::CLI::Commands::ListVols

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

Overview

The list_vols command show the current iSCSI targets available on this host

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



38
39
40
41
42
# File 'lib/SANStore/cli/commands/list_vols.rb', line 38

def aliases
  [
    "list_vol", "list", "ls"
  ]
end

#long_descObject

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



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/SANStore/cli/commands/list_vols.rb', line 51

def long_desc
  'Displays a list of valid iSCSI targets, all of which ' +
  'should be available on the local network' + "\n\n"
  'NOTE: Because of the way iSCSI works, this host has no ' +
  'way of knowing what is actually '+ ANSI.bold{ "in" } + ' the volume. So even ' +
  'if a target is defined, this host has no way of knowing if ' +
  'a given initiator can actually ' + ANSI.bold{ "use" } +
  'the contents of this volume. If something appears to be '
  'wrong, check the set-up of the host to make sure it can '
  'actually connect to the targets defined here.' 
end

#nameObject

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



33
34
35
# File 'lib/SANStore/cli/commands/list_vols.rb', line 33

def name
  'list_vols'
end

#option_definitionsObject

Define the options for this command



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

def option_definitions
  [
  ]
end

#run(options, arguments) ⇒ Object

Execute the command



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/SANStore/cli/commands/list_vols.rb', line 75

def run(options, arguments)

  # Get the list of defined volumes
  volumes = COMStar.list_vols
  
  # Show the list to the caller
  text = String.new
  volumes.each{|target|
    text << sprintf("%-60s ", target[:name])
    
    if target[:state] == "online" then
      text << sprintf("%-20s ", ANSI.green{ target[:state] })
    else
      text << sprintf("%-20s ", ANSI.black{ target[:state] })
    end
    
    if target[:sessions].to_i > 0 then
      text << sprintf("%-10s\n", ANSI.white{ target[:sessions] })
    else
      text << sprintf("%-10s\n", ANSI.black{ target[:sessions] })
    end
  }
  puts sprintf("%-68s %-19s %-10s\n", ANSI.bold{ "Target Name"}, ANSI.bold{ "Status" }, ANSI.bold{ "Open Sessions" })
  puts text
end

#short_descObject

A short help text describing the purpose of this command



45
46
47
# File 'lib/SANStore/cli/commands/list_vols.rb', line 45

def short_desc
  'Show the currently defined iSCSI targets on this host.'
end

#usageObject

Show the user the basic syntax of this command



64
65
66
# File 'lib/SANStore/cli/commands/list_vols.rb', line 64

def usage
  "store list_vols"
end