shu-san-scripts 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shu-san-scripts
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Love
@@ -181,24 +181,6 @@ extra_rdoc_files:
181
181
  - LICENSE.txt
182
182
  - README.rdoc
183
183
  files:
184
- - lib/SANStore.rb
185
- - lib/SANStore/cli.rb
186
- - lib/SANStore/cli/base.rb
187
- - lib/SANStore/cli/commands.rb
188
- - lib/SANStore/cli/commands/delete_vol.rb
189
- - lib/SANStore/cli/commands/help.rb
190
- - lib/SANStore/cli/commands/list_vols.rb
191
- - lib/SANStore/cli/commands/new_vol.rb
192
- - lib/SANStore/cli/logger.rb
193
- - lib/SANStore/cri.rb
194
- - lib/SANStore/cri/base.rb
195
- - lib/SANStore/cri/command.rb
196
- - lib/SANStore/cri/core_ext.rb
197
- - lib/SANStore/cri/core_ext/string.rb
198
- - lib/SANStore/cri/option_parser.rb
199
- - lib/SANStore/helpers/uuid.rb
200
- - lib/SANStore/iSCSI/comstar.rb
201
- - lib/SANStore/zfs/zfs.rb
202
184
  - LICENSE.txt
203
185
  - README.rdoc
204
186
  homepage: http://github.com/dlove24/shu-san-scripts
@@ -1,24 +0,0 @@
1
- ### Copyright (c) 2010, David Love
2
- ###
3
- ### Permission to use, copy, modify, and/or distribute this software for
4
- ### any purpose with or without fee is hereby granted, provided that the
5
- ### above copyright notice and this permission notice appear in all copies.
6
- ###
7
- ### THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
- ### WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
- ### MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
- ### ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
- ### WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
- ### ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
- ### OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
- ###
15
-
16
- module SANStore
17
-
18
- ## Define Application Global constants
19
-
20
- # The current SANStore client version.
21
- VERSION = '0.1'
22
-
23
- end
24
-
@@ -1,29 +0,0 @@
1
- ### Copyright (c) 2009 Denis Defreyne, 2010-2011 David Love
2
- ###
3
- ### Permission to use, copy, modify, and/or distribute this software for
4
- ### any purpose with or without fee is hereby granted, provided that the
5
- ### above copyright notice and this permission notice appear in all copies.
6
- ###
7
- ### THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
- ### WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
- ### MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
- ### ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
- ### WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
- ### ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
- ### OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
- ###
15
-
16
- require 'rubygems'
17
-
18
- # Load command line handling library
19
- require 'cri'
20
-
21
- # Install module for command line
22
- # interface
23
- module SANStore:CLI
24
- end
25
-
26
- # Load the command line handling modules
27
- require 'SANStore/cli/logger'
28
- require 'SANStore/cli/commands'
29
- require 'SANStore/cli/base'
@@ -1,103 +0,0 @@
1
- # Copyright (c) 2009 Denis Defreyne, 2010-2011 David Love
2
- #
3
- # Permission to use, copy, modify, and/or distribute this software for
4
- # any purpose with or without fee is hereby granted, provided that the
5
- # above copyright notice and this permission notice appear in all copies.
6
- #
7
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
- # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
- # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
- # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
- # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
- # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
- # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
- #
15
-
16
- # @author Denis Defreyne
17
- # @author David Love
18
- #
19
- # The +CLI+ module acts as the gathering place for all the gloabl options
20
- # and the sub-commands which the +SANStore+ command can deal with.
21
- # Sub-commands are themselves defined in the {SANStore::CLI::Commands}
22
- # module
23
- module SANStore::CLI
24
-
25
- # @author Denis Defreyne
26
- # @author David Love
27
- #
28
- # Details the global options applicable to all commands, and the code necessary
29
- # to process those options. Each sub-command also needs to be registered with
30
- # this class for it to work: strange things will happen if the sub-command is
31
- # not set-up here!
32
- #
33
- # When creating a new sub-command, the constructor for that sub-command needs
34
- # to be added to the {Base#initialize} function of *this* class as well. Be sure to
35
- # also add the path to the file where the sub-command is defined to the file
36
- # +lib/SANStore/cli/commands.rb+, otherwise you will get warnings of unknown
37
- # classes.
38
- class Base < Cri::Base
39
-
40
- # Instantiates the sub-commands by creating a single reference to each
41
- # known sub-command.
42
- #
43
- # @note This means that if your sub-command is not in this constructor
44
- # it *will not* be found, and *will not* appear as a valid sub-command.
45
- # If something is missing from the 'help' command, check this method!
46
- def initialize
47
- super('SANStore')
48
-
49
- # Add help command
50
- self.help_command = SANStore::CLI::Commands::Help.new
51
- add_command(self.help_command)
52
-
53
- # Add other commands
54
- add_command(SANStore::CLI::Commands::DeleteVol.new)
55
- add_command(SANStore::CLI::Commands::ListVols.new)
56
- add_command(SANStore::CLI::Commands::NewVol.new)
57
- end
58
-
59
- # Returns the list of global option definitionss.
60
- def global_option_definitions
61
- [
62
- {
63
- :long => 'help', :short => 'h', :argument => :forbidden,
64
- :desc => 'show this help message and quit'
65
- },
66
- {
67
- :long => 'no-color', :short => 'C', :argument => :forbidden,
68
- :desc => 'disable color'
69
- },
70
- {
71
- :long => 'version', :short => 'v', :argument => :forbidden,
72
- :desc => 'show version information and quit'
73
- },
74
- {
75
- :long => 'verbose', :short => 'V', :argument => :forbidden,
76
- :desc => 'make store command output more detailed'
77
- }
78
- ]
79
- end
80
-
81
- # Process the global options, and set/change the application state from them
82
- def handle_option(option)
83
- # Handle version option
84
- if option == :version
85
- puts "SANStore Bootstrap Client #{SANStore::VERSION} (c) 2011 David Love."
86
- puts "Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) running on #{RUBY_PLATFORM}"
87
- exit 0
88
- # Handle verbose option
89
- elsif option == :verbose
90
- SANStore::CLI::Logger.instance.level = :low
91
- # Handle no-color option
92
- elsif option == :'no-color'
93
- SANStore::CLI::Logger.instance.color = false
94
- # Handle help option
95
- elsif option == :help
96
- show_help
97
- exit 0
98
- end
99
- end
100
-
101
- end
102
-
103
- end
@@ -1,31 +0,0 @@
1
- # Copyright (c) 2009 Denis Defreyne, 2010-2011 David Love
2
- #
3
- # Permission to use, copy, modify, and/or distribute this software for
4
- # any purpose with or without fee is hereby granted, provided that the
5
- # above copyright notice and this permission notice appear in all copies.
6
- #
7
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
- # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
- # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
- # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
- # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
- # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
- # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
-
15
- # @author David Love
16
- #
17
- # The +Commands+ module acts as the gathering place for all the sub-commands
18
- # which the +store+ command can deal with. Each sub-command defines both
19
- # the command action, options, and associated help text.
20
- #
21
- # All commands should live under +lib/SANStore/cli/commands+, with the
22
- # file-name named after the sub-command defined within it.
23
-
24
- module SANStore::CLI::Commands
25
- end
26
-
27
- require 'SANStore/cli/commands/help'
28
-
29
- require 'SANStore/cli/commands/delete_vol'
30
- require 'SANStore/cli/commands/list_vols'
31
- require 'SANStore/cli/commands/new_vol'
@@ -1,113 +0,0 @@
1
- # Copyright (c) 2009 Denis Defreyne, 2010-2011 David Love
2
- #
3
- # Permission to use, copy, modify, and/or distribute this software for
4
- # any purpose with or without fee is hereby granted, provided that the
5
- # above copyright notice and this permission notice appear in all copies.
6
- #
7
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
- # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
- # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
- # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
- # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
- # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
- # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
-
15
- # Volume names are based on RFC 4122 UUIDs
16
- require "uuidtools"
17
-
18
- # Use the ANSI library to report the status to the user
19
- require "ansi/code"
20
-
21
- # Use the ZFS library
22
- require "SANStore/zfs/zfs"
23
-
24
- # Use the COMStar iSCSI library
25
- require "SANStore/iSCSI/comstar.rb"
26
-
27
- module SANStore::CLI::Commands
28
-
29
- # @author David Love
30
- #
31
- # The +new_vol+ command adds a new ZFS volume to the specified volume
32
- # store, and sets it up as an iSCSI target. Defaults are supplied to
33
- # all arguments, but can be overridden by the user for slightly
34
- # customised set-up of the volume store. However, the user interface
35
- # should be kept as simple as possible.
36
- class DeleteVol < Cri::Command
37
-
38
- # The name of the sub-command (as it appears in the command line app)
39
- def name
40
- 'delete_vol'
41
- end
42
-
43
- # The aliases this sub-command is known by
44
- def aliases
45
- [
46
- "rm", "delete", "rm_vol"
47
- ]
48
- end
49
-
50
- # A short help text describing the purpose of this command
51
- def short_desc
52
- 'Remove the specified target from the iSCSI volume store.'
53
- end
54
-
55
- # A longer description, detailing both the purpose and the
56
- # use of this command
57
- def long_desc
58
- 'This command deletes the specified target from the pool, and ' +
59
- 'unlinks the volume store backing the target. Since the underlying ' +
60
- 'volume store is destroyed, this action is ' + ANSI.bold{ "irreversible" } +
61
- 'and so this command should be used with ' + ANSI.bold{ "great" } + 'care.' +
62
- "\n\n" +
63
- 'NOTE: Any clients attached to the volume will have their ' +
64
- 'iSCSI session forcibly closed. This may result in the premature ' +
65
- 'death of the client if care is not taken.'
66
- end
67
-
68
- # Show the user the basic syntax of this command
69
- def usage
70
- "store delete_vol SHARE_NAME"
71
- end
72
-
73
- # Define the options for this command
74
- def option_definitions
75
- [
76
- { :short => 'v', :long => 'volume_store', :argument => :optional,
77
- :desc => 'specifify the ZFS root of the new iSCSI volume. Defaults to "store/volumes".'
78
- },
79
- { :short => 'n', :long => 'name', :argument => :optional,
80
- :desc => 'the name of the new volume. This must be a valid ZFS volume name, and defaults to ' +
81
- 'an RFC 4122 GUID.'
82
- },
83
- { :short => 's', :long => 'size', :argument => :optional,
84
- :desc => 'the size of the new iSCSI volume. Note that while ZFS allows you to change the size ' +
85
- 'of the new volume relatively easily, because the iSCSI initiator sees this volume as a raw ' +
86
- 'device changing the size later may be very easy or very difficult depending on the initiators ' +
87
- 'operating system (and the specific file system being used). In other words, choose with care: ' +
88
- 'by default this command uses a size of 20G, which should be enough for most tasks in the labs.'
89
- },
90
- ]
91
- end
92
-
93
- # Execute the command
94
- def run(options, arguments)
95
-
96
- # Check that we have been given a name
97
- if arguments.size > 1
98
- SANStore::CLI::Logger.instance.log_level(:high, :error, "You must specify the name of the target to remove")
99
- exit 1
100
- end
101
-
102
- # Delete the iSCSI target
103
- SANStore::CLI::Logger.instance.log_level(:high, :delete, "Removing target #{arguments[0]}")
104
- zfs_volume = COMStar.delete_target(arguments[0])
105
-
106
- # Remove the underlying ZFS store
107
- SANStore::CLI::Logger.instance.log_level(:low, :delete, "Removing ZFS store for #{arguments[0]}")
108
- ZFS.delete_volume(zfs_volume)
109
- end
110
-
111
- end
112
-
113
- end
@@ -1,106 +0,0 @@
1
- ### Copyright (c) 2009 Denis Defreyne, 2010-2011 David Love
2
- ###
3
- ### Permission to use, copy, modify, and/or distribute this software for
4
- ### any purpose with or without fee is hereby granted, provided that the
5
- ### above copyright notice and this permission notice appear in all copies.
6
- ###
7
- ### THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
- ### WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
- ### MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
- ### ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
- ### WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
- ### ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
- ### OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
- ###
15
-
16
- module SANStore::CLI::Commands
17
-
18
- # @author Denis Defreyne
19
- # @author David Love
20
- #
21
- # The +help+ command show the user a brief summary of the available
22
- # sub-commands, and the short description of each of those commands.
23
- #
24
- # Further help is available to the user, if one of the sub-commands
25
- # is named as an argument to this command. In that case, the longer
26
- # help for the command is displayed.
27
- #
28
- # @note This class is merely a helper class: the actual text, options
29
- # and other details are drawn directly from the source code of those
30
- # commands. In the execution of this command, we rely on the +cri+
31
- # and +cli+ libraries to do the hard work of actually processing the
32
- # sub-commands.
33
- class Help < Cri::Command
34
-
35
- # The name of the sub-command (as it appears in the command line app)
36
- def name
37
- 'help'
38
- end
39
-
40
- # The aliases this sub-command is known by
41
- def aliases
42
- []
43
- end
44
-
45
- # A short help text describing the purpose of this command
46
- def short_desc
47
- 'Show help for a command'
48
- end
49
-
50
- # A longer description, detailing both the purpose and the
51
- # use of this command
52
- def long_desc
53
- 'Show help for the given command, or show general help. When no ' +
54
- 'command is given, a list of available commands is displayed, as ' +
55
- 'well as a list of global command-line options. When a command is ' +
56
- 'given, a command description as well as command-specific ' +
57
- 'command-line options are shown.'
58
- end
59
-
60
- # Show the user the basic syntax of this command
61
- def usage
62
- "store help [command]"
63
- end
64
-
65
- # Execute the command
66
- def run(options, arguments)
67
- # Check arguments
68
- if arguments.size > 1
69
- $stderr.puts "usage: #{usage}"
70
- exit 1
71
- end
72
-
73
- if arguments.length == 0
74
- # Build help text
75
- text = ''
76
-
77
- # Add title
78
- text << "A command-line tool for managing iSCSI targets on OpenSolaris.\n"
79
-
80
- # Add available commands
81
- text << "\n"
82
- text << "Available commands:\n"
83
- text << "\n"
84
- @base.commands.sort.each do |command|
85
- text << sprintf(" %-20s %s\n", command.name, command.short_desc)
86
- end
87
-
88
- # Add global options
89
- text << "\n"
90
- text << "Global options:\n"
91
- text << "\n"
92
- @base.global_option_definitions.sort { |x,y| x[:long] <=> y[:long] }.each do |opt_def|
93
- text << sprintf(" -%1s --%-15s %s\n", opt_def[:short], opt_def[:long], opt_def[:desc])
94
- end
95
-
96
- # Display text
97
- puts text
98
- elsif arguments.length == 1
99
- command = @base.command_named(arguments[0])
100
- puts command.help
101
- end
102
- end
103
-
104
- end
105
-
106
- end