netscaler-cli 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/Gemfile +7 -3
  2. data/Gemfile.lock +17 -8
  3. data/README.markdown +6 -3
  4. data/Rakefile +4 -6
  5. data/bin/{netscaler-server → netscaler} +2 -2
  6. data/etc/Version +1 -1
  7. data/lib/netscaler/{baseexecutor.rb → base_request.rb} +3 -4
  8. data/lib/netscaler/cli.rb +201 -0
  9. data/lib/netscaler/config.rb +20 -15
  10. data/lib/netscaler/executor.rb +34 -0
  11. data/lib/netscaler/extensions.rb +47 -0
  12. data/lib/netscaler/server/request.rb +35 -0
  13. data/lib/netscaler/server/response.rb +67 -0
  14. data/lib/netscaler/service/request.rb +42 -0
  15. data/lib/netscaler/service/response.rb +44 -0
  16. data/lib/netscaler/vserver/request.rb +67 -0
  17. data/lib/netscaler/vserver/response.rb +125 -0
  18. data/spec/netscaler/cli_spec.rb +140 -0
  19. data/spec/{config_spec.rb → netscaler/config_spec.rb} +23 -9
  20. data/spec/{configs → netscaler/configs}/bad-yaml.yml +0 -0
  21. data/spec/{configs → netscaler/configs}/missing-username.yml +0 -0
  22. data/spec/{configs → netscaler/configs}/simple-config.yml +2 -1
  23. data/spec/netscaler/extenstions_spec.rb +26 -0
  24. data/spec/{helpers.rb → spec_helpers.rb} +0 -0
  25. metadata +108 -53
  26. data/bin/netscaler-service +0 -5
  27. data/bin/netscaler-vserver +0 -5
  28. data/lib/netscaler/clitemplate.rb +0 -147
  29. data/lib/netscaler/server/cli.rb +0 -60
  30. data/lib/netscaler/server/executor.rb +0 -115
  31. data/lib/netscaler/service/cli.rb +0 -49
  32. data/lib/netscaler/service/executor.rb +0 -82
  33. data/lib/netscaler/vserver/cli.rb +0 -92
  34. data/lib/netscaler/vserver/executor.rb +0 -194
  35. data/spec/server/cli_spec.rb +0 -33
  36. data/spec/service/cli_spec.rb +0 -45
  37. data/spec/vserver/cli_spec.rb +0 -75
@@ -1,4 +1,4 @@
1
- require 'helpers'
1
+ require 'spec_helpers'
2
2
  require 'netscaler/config'
3
3
  require 'netscaler/errors'
4
4
 
@@ -7,28 +7,42 @@ module Netscaler
7
7
  module ConfigurationHelper
8
8
  def reading(file)
9
9
  actual_file = File.expand_path("./configs/#{file}", File.dirname(__FILE__))
10
- Netscaler::ConfigurationReader.new(actual_file)
10
+ Netscaler::ConfigurationReader.read_config_file(actual_file)
11
11
  end
12
12
  end
13
13
 
14
14
  describe "Configuration Reader" do
15
15
  include ConfigurationHelper
16
16
 
17
+ before :each do
18
+ @config = reading('simple-config.yml')
19
+ end
20
+
17
21
  describe "when reading an existing file" do
18
22
  it "should be able to load the basic config file" do
19
- reading('simple-config.yml').load_balancers.length.should eql(2)
23
+ @config.load_balancers.length.should eql(2)
20
24
  end
21
25
 
22
26
  it "should set the username and password correctly when set in the file." do
23
- config = reading('simple-config.yml')['something.goes.here']
24
- config.username.should eql('some_user')
25
- config.password.should eql('somepass')
27
+ ns = @config['something.goes.here']
28
+ ns.username.should eql('some_user')
29
+ ns.password.should eql('somepass')
26
30
  end
27
31
 
28
32
  it "should load via an alias" do
29
- config = reading('simple-config.yml')['else']
30
- config.alias.should eql('else')
31
- config.username.should eql('here')
33
+ ns = @config['else']
34
+ ns.alias.should eql('else')
35
+ ns.username.should eql('here')
36
+ end
37
+
38
+ it "should set the default version to 9.2" do
39
+ ns = @config['something.goes.here']
40
+ ns.version.should eql("9.2")
41
+ end
42
+
43
+ it "should read the version if present" do
44
+ ns = @config['else']
45
+ ns.version.should eql("9.1")
32
46
  end
33
47
  end
34
48
 
File without changes
@@ -4,4 +4,5 @@ something.goes.here:
4
4
  something.else:
5
5
  username: here
6
6
  alias: else
7
- password: blah
7
+ password: blah
8
+ version: 9.1
@@ -0,0 +1,26 @@
1
+ require 'spec_helpers'
2
+ require 'netscaler/extensions'
3
+
4
+ describe Array do
5
+ it "should just print out the [] when empty" do
6
+ [].to_json.should eql('[]')
7
+ end
8
+
9
+ it "should indent the [] if given" do
10
+ [].to_json(' ').should eql(' []')
11
+ end
12
+
13
+ class Integer
14
+ def to_json(prefix=nil)
15
+ to_s
16
+ end
17
+ end
18
+
19
+ it "should print out the contents, one line each." do
20
+ [1, 2, 3].to_json.should eql("[\n 1,\n 2,\n 3\n]\n")
21
+ end
22
+
23
+ it "should print out the contents indented" do
24
+ [1, 2, 3].to_json(' ').should eql(" [\n 1,\n 2,\n 3\n ]\n")
25
+ end
26
+ end
File without changes
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netscaler-cli
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 3
9
- - 3
10
- version: 0.3.3
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Gabe McArthur
@@ -15,8 +14,8 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-12-07 00:00:00 -08:00
19
- default_executable:
17
+ date: 2011-03-08 00:00:00 -08:00
18
+ default_executable: netscaler
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: log4r
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ~>
28
27
  - !ruby/object:Gem::Version
29
- hash: 13
30
28
  segments:
31
29
  - 1
32
30
  - 1
@@ -41,11 +39,11 @@ dependencies:
41
39
  requirements:
42
40
  - - ~>
43
41
  - !ruby/object:Gem::Version
44
- hash: 5
45
42
  segments:
46
43
  - 0
47
44
  - 7
48
- version: "0.7"
45
+ - 0
46
+ version: 0.7.0
49
47
  type: :runtime
50
48
  version_requirements: *id002
51
49
  - !ruby/object:Gem::Dependency
@@ -56,7 +54,6 @@ dependencies:
56
54
  requirements:
57
55
  - - ">="
58
56
  - !ruby/object:Gem::Version
59
- hash: 3
60
57
  segments:
61
58
  - 1
62
59
  - 6
@@ -64,75 +61,137 @@ dependencies:
64
61
  type: :runtime
65
62
  version_requirements: *id003
66
63
  - !ruby/object:Gem::Dependency
67
- name: log4r
64
+ name: choosy
68
65
  prerelease: false
69
66
  requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ - 2
74
+ version: "0.2"
75
+ type: :runtime
76
+ version_requirements: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ name: rspec
79
+ prerelease: false
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ type: :development
89
+ version_requirements: *id005
90
+ - !ruby/object:Gem::Dependency
91
+ name: autotest
92
+ prerelease: false
93
+ requirement: &id006 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ type: :development
102
+ version_requirements: *id006
103
+ - !ruby/object:Gem::Dependency
104
+ name: autotest-notification
105
+ prerelease: false
106
+ requirement: &id007 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ type: :development
115
+ version_requirements: *id007
116
+ - !ruby/object:Gem::Dependency
117
+ name: log4r
118
+ prerelease: false
119
+ requirement: &id008 !ruby/object:Gem::Requirement
70
120
  none: false
71
121
  requirements:
72
122
  - - ">="
73
123
  - !ruby/object:Gem::Version
74
- hash: 1
75
124
  segments:
76
125
  - 1
77
126
  - 1
78
127
  - 9
79
128
  version: 1.1.9
80
129
  type: :runtime
81
- version_requirements: *id004
130
+ version_requirements: *id008
82
131
  - !ruby/object:Gem::Dependency
83
132
  name: savon
84
133
  prerelease: false
85
- requirement: &id005 !ruby/object:Gem::Requirement
134
+ requirement: &id009 !ruby/object:Gem::Requirement
86
135
  none: false
87
136
  requirements:
88
137
  - - ">="
89
138
  - !ruby/object:Gem::Version
90
- hash: 17
91
139
  segments:
92
140
  - 0
93
141
  - 7
94
142
  - 9
95
143
  version: 0.7.9
96
144
  type: :runtime
97
- version_requirements: *id005
145
+ version_requirements: *id009
98
146
  - !ruby/object:Gem::Dependency
99
147
  name: highline
100
148
  prerelease: false
101
- requirement: &id006 !ruby/object:Gem::Requirement
149
+ requirement: &id010 !ruby/object:Gem::Requirement
102
150
  none: false
103
151
  requirements:
104
152
  - - ">="
105
153
  - !ruby/object:Gem::Version
106
- hash: 3
107
154
  segments:
108
155
  - 1
109
156
  - 6
110
157
  version: "1.6"
111
158
  type: :runtime
112
- version_requirements: *id006
159
+ version_requirements: *id010
113
160
  - !ruby/object:Gem::Dependency
114
- name: rspec
161
+ name: choosy
115
162
  prerelease: false
116
- requirement: &id007 !ruby/object:Gem::Requirement
163
+ requirement: &id011 !ruby/object:Gem::Requirement
117
164
  none: false
118
165
  requirements:
119
166
  - - ">="
120
167
  - !ruby/object:Gem::Version
121
- hash: 7
122
168
  segments:
169
+ - 0
123
170
  - 2
171
+ - 3
172
+ version: 0.2.3
173
+ type: :runtime
174
+ version_requirements: *id011
175
+ - !ruby/object:Gem::Dependency
176
+ name: rspec
177
+ prerelease: false
178
+ requirement: &id012 !ruby/object:Gem::Requirement
179
+ none: false
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ segments:
124
184
  - 2
185
+ - 5
125
186
  - 0
126
- version: 2.2.0
187
+ version: 2.5.0
127
188
  type: :development
128
- version_requirements: *id007
189
+ version_requirements: *id012
129
190
  description: This gem installs several simple command line utilities locally. It uses the NSConfig.wsdl SOAP interface for remote access.
130
191
  email:
131
192
  - madeonamac@gmail.com
132
193
  executables:
133
- - netscaler-vserver
134
- - netscaler-service
135
- - netscaler-server
194
+ - netscaler
136
195
  extensions: []
137
196
 
138
197
  extra_rdoc_files:
@@ -142,31 +201,30 @@ files:
142
201
  - Gemfile.lock
143
202
  - README.markdown
144
203
  - Rakefile
145
- - bin/netscaler-server
146
- - bin/netscaler-service
147
- - bin/netscaler-vserver
204
+ - bin/netscaler
148
205
  - etc/Version
149
- - lib/netscaler/baseexecutor.rb
150
- - lib/netscaler/clitemplate.rb
206
+ - lib/netscaler/base_request.rb
207
+ - lib/netscaler/cli.rb
151
208
  - lib/netscaler/config.rb
152
209
  - lib/netscaler/errors.rb
210
+ - lib/netscaler/executor.rb
211
+ - lib/netscaler/extensions.rb
153
212
  - lib/netscaler/logging.rb
154
- - lib/netscaler/server/cli.rb
155
- - lib/netscaler/server/executor.rb
156
- - lib/netscaler/service/cli.rb
157
- - lib/netscaler/service/executor.rb
213
+ - lib/netscaler/server/request.rb
214
+ - lib/netscaler/server/response.rb
215
+ - lib/netscaler/service/request.rb
216
+ - lib/netscaler/service/response.rb
158
217
  - lib/netscaler/transaction.rb
159
218
  - lib/netscaler/version.rb
160
- - lib/netscaler/vserver/cli.rb
161
- - lib/netscaler/vserver/executor.rb
162
- - spec/config_spec.rb
163
- - spec/configs/bad-yaml.yml
164
- - spec/configs/missing-username.yml
165
- - spec/configs/simple-config.yml
166
- - spec/helpers.rb
167
- - spec/server/cli_spec.rb
168
- - spec/service/cli_spec.rb
169
- - spec/vserver/cli_spec.rb
219
+ - lib/netscaler/vserver/request.rb
220
+ - lib/netscaler/vserver/response.rb
221
+ - spec/netscaler/cli_spec.rb
222
+ - spec/netscaler/config_spec.rb
223
+ - spec/netscaler/configs/bad-yaml.yml
224
+ - spec/netscaler/configs/missing-username.yml
225
+ - spec/netscaler/configs/simple-config.yml
226
+ - spec/netscaler/extenstions_spec.rb
227
+ - spec/spec_helpers.rb
170
228
  has_rdoc: true
171
229
  homepage: http://github.com/gabemc/netscaler-cli
172
230
  licenses: []
@@ -181,7 +239,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
239
  requirements:
182
240
  - - ">="
183
241
  - !ruby/object:Gem::Version
184
- hash: 3
185
242
  segments:
186
243
  - 0
187
244
  version: "0"
@@ -190,7 +247,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
247
  requirements:
191
248
  - - ">="
192
249
  - !ruby/object:Gem::Version
193
- hash: 3
194
250
  segments:
195
251
  - 0
196
252
  version: "0"
@@ -202,8 +258,7 @@ signing_key:
202
258
  specification_version: 3
203
259
  summary: Simple command line utilities for interacting remotely with a Netscaler load balancer.
204
260
  test_files:
205
- - spec/config_spec.rb
206
- - spec/helpers.rb
207
- - spec/server/cli_spec.rb
208
- - spec/service/cli_spec.rb
209
- - spec/vserver/cli_spec.rb
261
+ - spec/netscaler/cli_spec.rb
262
+ - spec/netscaler/config_spec.rb
263
+ - spec/netscaler/extenstions_spec.rb
264
+ - spec/spec_helpers.rb
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
-
4
- require 'netscaler/service/cli'
5
- Netscaler::Service::CLI.new(ARGV).execute!
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
-
4
- require 'netscaler/vserver/cli'
5
- Netscaler::VServer::CLI.new(ARGV).execute!
@@ -1,147 +0,0 @@
1
- require 'optparse'
2
- require 'netscaler/errors'
3
- require 'netscaler/version'
4
- require 'netscaler/logging'
5
- require 'netscaler/transaction'
6
- require 'netscaler/config'
7
-
8
- module Netscaler
9
- class CLITemplate
10
- attr_reader :options, :args, :host, :cli_type
11
-
12
- def initialize(cli_type, args)
13
- @cli_type = cli_type
14
- @args = args
15
- end
16
-
17
- def execute!
18
- begin
19
- parse!(@args.dup)
20
- Netscaler::Logging.configure(options[:debug])
21
-
22
- Netscaler::Transaction.new(netscaler_configuration) do |client|
23
- action = options[:action][0]
24
- executor = create_executor(client)
25
-
26
- executor.send(action, options)
27
- end
28
- rescue SystemExit => e
29
- raise
30
- rescue Netscaler::ConfigurationError => e
31
- print_error(e.message)
32
- rescue OptionParser::ParseError => e
33
- print_error(e.message)
34
- rescue Exception => e
35
- STDERR.puts e.backtrace
36
- print_error(e.message)
37
- end
38
- end
39
-
40
- def parse!(args)
41
- parse_options(args)
42
- validate_args(args)
43
- end
44
-
45
- def parse_options(args)
46
- @options ||= {}
47
- if @options.empty?
48
- @options[:action] = Array.new
49
- end
50
- @parsed_options ||= OptionParser.new do |opts|
51
- interface_header(opts)
52
- interface_configuration(opts)
53
- interface_actions(opts)
54
- interface_information(opts)
55
- end.parse!(args)
56
- end
57
-
58
- def interface_configuration(opts)
59
- opts.separator " Configuration: "
60
- opts.on('-n', '--netscaler NETSCALER',
61
- "The IP or hostname of the Netscaler",
62
- "load balancer.",
63
- "This argument is required.") do |n|
64
- options[:netscaler] = n
65
- end
66
- opts.on('-c', '--config CONFIG',
67
- "The path to the netscaler-cli configuration",
68
- "file. By default, it is the ",
69
- "~/.netscaler-cli.yml") do |c|
70
- options[:config] = c
71
- end
72
- opts.separator ""
73
- end
74
-
75
- def interface_information(opts)
76
- opts.separator " Informative:"
77
- opts.on('--debug',
78
- "Prints extra debug information") do |d|
79
- options[:debug] = d
80
- end
81
- opts.on('--json',
82
- "Prints out JSON data instead of textual output.") do |j|
83
- options[:json] = j
84
- end
85
- opts.on('-v', '--version',
86
- "Show the version information") do |v|
87
- puts "#{File.basename($0)} version: #{Netscaler::Version.to_s}"
88
- exit
89
- end
90
- opts.on('-h', '--help',
91
- "Show this help message") do
92
- puts opts
93
- exit
94
- end
95
-
96
- opts.separator ""
97
- end
98
-
99
- def requires_argument?
100
- true
101
- end
102
-
103
- def validate_noargs
104
- end
105
-
106
- def validate_args(args)
107
- if args.length == 0
108
- if requires_argument?
109
- raise Netscaler::ConfigurationError.new("No hosts specified to act on.")
110
- else
111
- validate_noargs
112
- end
113
- elsif args.length != 1
114
- raise Netscaler::ConfigurationError.new("Only one #{cli_type} can be acted on at a time.")
115
- else
116
- @host = args[0]
117
- end
118
-
119
- if options[:action].empty?
120
- options[:action] << :status
121
- elsif options[:action].length != 1
122
- raise Netscaler::ConfigurationError.new("Multiple actions specified -- only one action is supported at a time.")
123
- end
124
-
125
- if options[:netscaler].nil?
126
- raise Netscaler::ConfigurationError.new("No Netscaler IP/Hostname given.")
127
- end
128
- end
129
-
130
- def netscaler_configuration
131
- reader = Netscaler::ConfigurationReader.new(options[:config])
132
- config = reader[options[:netscaler]]
133
- if config.nil?
134
- raise Netscaler::ConfigurationError.new("The Netscaler address '#{options[:netscaler]}' is not defined in the configuration file")
135
- end
136
-
137
- config
138
- end
139
-
140
- private
141
- def print_error(e)
142
- STDERR.puts "#{File.basename($0)}: #{e}"
143
- STDERR.puts "Try '#{File.basename($0)} --help' for more information"
144
- exit 1
145
- end
146
- end # CLI
147
- end