netscaler-cli 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/VERSION +1 -1
- data/lib/netscaler/clitemplate.rb +23 -26
- data/lib/netscaler/server/cli.rb +2 -2
- data/lib/netscaler/server/executor.rb +3 -3
- data/lib/netscaler/service/cli.rb +6 -4
- data/lib/netscaler/service/executor.rb +7 -7
- data/lib/netscaler/transaction.rb +2 -0
- data/lib/netscaler/vserver/cli.rb +31 -6
- data/lib/netscaler/vserver/executor.rb +23 -21
- data/spec/helpers.rb +4 -0
- data/spec/server/cli_spec.rb +33 -0
- data/spec/service/cli_spec.rb +45 -0
- data/spec/vserver/cli_spec.rb +49 -19
- metadata +8 -4
data/lib/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
@@ -15,26 +15,16 @@ module Netscaler
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def execute!
|
18
|
-
parse!(@args.dup)
|
19
|
-
Netscaler::Logging.configure(options[:debug])
|
20
|
-
|
21
|
-
Netscaler::Transaction.new(netscaler_configuration) do |client|
|
22
|
-
action = options[:action].keys[0]
|
23
|
-
args = options[:action][action]
|
24
|
-
executor = create_executor(client)
|
25
|
-
|
26
|
-
if args.nil?
|
27
|
-
executor.send(action)
|
28
|
-
else
|
29
|
-
executor.send(action, args)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def parse!(args)
|
35
18
|
begin
|
36
|
-
|
37
|
-
|
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
|
38
28
|
rescue SystemExit => e
|
39
29
|
raise
|
40
30
|
rescue Netscaler::ConfigurationError => e
|
@@ -47,10 +37,15 @@ module Netscaler
|
|
47
37
|
end
|
48
38
|
end
|
49
39
|
|
40
|
+
def parse!(args)
|
41
|
+
parse_options(args)
|
42
|
+
validate_args(args)
|
43
|
+
end
|
44
|
+
|
50
45
|
def parse_options(args)
|
51
46
|
@options ||= {}
|
52
47
|
if @options.empty?
|
53
|
-
@options[:action] =
|
48
|
+
@options[:action] = Array.new
|
54
49
|
end
|
55
50
|
@parsed_options ||= OptionParser.new do |opts|
|
56
51
|
interface_header(opts)
|
@@ -62,14 +57,16 @@ module Netscaler
|
|
62
57
|
|
63
58
|
def interface_configuration(opts)
|
64
59
|
opts.separator " Configuration: "
|
65
|
-
opts.on('-n', '--netscaler
|
66
|
-
"The IP or hostname of the Netscaler
|
60
|
+
opts.on('-n', '--netscaler NETSCALER',
|
61
|
+
"The IP or hostname of the Netscaler",
|
62
|
+
"load balancer.",
|
67
63
|
"This argument is required.") do |n|
|
68
64
|
options[:netscaler] = n
|
69
65
|
end
|
70
66
|
opts.on('-c', '--config CONFIG',
|
71
|
-
"The path to the netscaler-cli configuration
|
72
|
-
"By default, it is
|
67
|
+
"The path to the netscaler-cli configuration",
|
68
|
+
"file. By default, it is the ",
|
69
|
+
"~/.netscaler-cli.yml") do |c|
|
73
70
|
options[:config] = c
|
74
71
|
end
|
75
72
|
opts.separator ""
|
@@ -105,8 +102,8 @@ module Netscaler
|
|
105
102
|
@host = args[0]
|
106
103
|
|
107
104
|
if options[:action].empty?
|
108
|
-
options[:action]
|
109
|
-
elsif options[:action].
|
105
|
+
options[:action] << :status
|
106
|
+
elsif options[:action].length != 1
|
110
107
|
raise Netscaler::ConfigurationError.new("Multiple actions specified -- only one action is supported at a time.")
|
111
108
|
end
|
112
109
|
|
data/lib/netscaler/server/cli.rb
CHANGED
@@ -30,11 +30,11 @@ DESC
|
|
30
30
|
opts.separator " Actions: "
|
31
31
|
opts.on('-e', '--enable',
|
32
32
|
"Enables the given server.") do |e|
|
33
|
-
options[:action]
|
33
|
+
options[:action] << :enable
|
34
34
|
end
|
35
35
|
opts.on('-d', '--disable',
|
36
36
|
"Disables the given server.") do |d|
|
37
|
-
options[:action]
|
37
|
+
options[:action] << :disable
|
38
38
|
end
|
39
39
|
opts.separator ""
|
40
40
|
end
|
@@ -7,15 +7,15 @@ module Netscaler::Server
|
|
7
7
|
@params = { :name => host }
|
8
8
|
end
|
9
9
|
|
10
|
-
def enable
|
10
|
+
def enable(options)
|
11
11
|
send_request('enableserver', @params)
|
12
12
|
end
|
13
13
|
|
14
|
-
def disable
|
14
|
+
def disable(options)
|
15
15
|
send_request('disableserver', @params)
|
16
16
|
end
|
17
17
|
|
18
|
-
def status
|
18
|
+
def status(options)
|
19
19
|
send_request('getserver', @params) do |response|
|
20
20
|
info = response[:return][:list][:item]
|
21
21
|
puts "Name: #{info[:name]}"
|
@@ -27,19 +27,21 @@ DESC
|
|
27
27
|
opts.separator " Actions: "
|
28
28
|
opts.on('-e', '--enable',
|
29
29
|
"Enables the given service.") do |e|
|
30
|
-
options[:action]
|
30
|
+
options[:action] << :enable
|
31
31
|
end
|
32
32
|
opts.on('-d', '--disable',
|
33
33
|
"Disables the given service.") do |d|
|
34
|
-
options[:action]
|
34
|
+
options[:action] << :disable
|
35
35
|
end
|
36
36
|
opts.on('-b', '--bind VSERVER',
|
37
37
|
"Binds a service to a virtual server.") do |b|
|
38
|
-
options[:action]
|
38
|
+
options[:action] << :bind
|
39
|
+
options[:vserver] = b
|
39
40
|
end
|
40
41
|
opts.on('-u', '--unbind VSERVER',
|
41
42
|
"Unbinds a serivce to a virtual server.") do |u|
|
42
|
-
options[:action]
|
43
|
+
options[:action] << :unbind
|
44
|
+
options[:vserver] = u
|
43
45
|
end
|
44
46
|
opts.separator ""
|
45
47
|
end
|
@@ -7,11 +7,11 @@ module Netscaler::Service
|
|
7
7
|
@params = { :name => host }
|
8
8
|
end
|
9
9
|
|
10
|
-
def enable
|
10
|
+
def enable(options)
|
11
11
|
send_request('enableservice', @params)
|
12
12
|
end
|
13
13
|
|
14
|
-
def disable
|
14
|
+
def disable(options)
|
15
15
|
params = {
|
16
16
|
:name => host,
|
17
17
|
:delay => 0
|
@@ -19,7 +19,7 @@ module Netscaler::Service
|
|
19
19
|
send_request('disableservice', params)
|
20
20
|
end
|
21
21
|
|
22
|
-
def status
|
22
|
+
def status(options)
|
23
23
|
send_request('getservice', @params) do |response|
|
24
24
|
info = response[:return][:list][:item]
|
25
25
|
puts "Name: #{info[:name]}"
|
@@ -29,9 +29,9 @@ module Netscaler::Service
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def bind(
|
32
|
+
def bind(options)
|
33
33
|
params = {
|
34
|
-
:name => vserver,
|
34
|
+
:name => options[:vserver],
|
35
35
|
:servicename => host
|
36
36
|
}
|
37
37
|
send_request('bindlbvserver_service', params) do |response|
|
@@ -40,9 +40,9 @@ module Netscaler::Service
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
def unbind(
|
43
|
+
def unbind(options)
|
44
44
|
params = {
|
45
|
-
:name => vserver,
|
45
|
+
:name => options[:vserver],
|
46
46
|
:servicename => host
|
47
47
|
}
|
48
48
|
send_request('unbindlbvserver_service', params) do |response|
|
@@ -30,21 +30,46 @@ DESC
|
|
30
30
|
opts.separator " Actions: "
|
31
31
|
opts.on('-e', '--enable',
|
32
32
|
"Enables the given virtual server.") do |e|
|
33
|
-
options[:action]
|
33
|
+
options[:action] << :enable
|
34
34
|
end
|
35
35
|
opts.on('-d', '--disable',
|
36
36
|
"Disables the given virtual server.") do |d|
|
37
|
-
options[:action]
|
37
|
+
options[:action] << :disable
|
38
38
|
end
|
39
39
|
opts.on('-b', '--bind POLICY_NAME',
|
40
|
-
"Binds a policy of a given name to a
|
41
|
-
|
40
|
+
"Binds a policy of a given name to a",
|
41
|
+
"virtual server.") do |b|
|
42
|
+
options[:action] << :bind
|
43
|
+
options[:policy_name] = b
|
44
|
+
end
|
45
|
+
opts.on('-p', '--priority NUMBER', Integer,
|
46
|
+
"The priority to bind the policy with.",
|
47
|
+
"Used only with the --bind flag.") do |p|
|
48
|
+
options[:priority] = p
|
42
49
|
end
|
43
50
|
opts.on('-u', '--unbind POLICY_NAME',
|
44
|
-
"Unbinds a policy of a given name to a
|
45
|
-
|
51
|
+
"Unbinds a policy of a given name to a",
|
52
|
+
"virtual server.") do |u|
|
53
|
+
options[:action] << :unbind
|
54
|
+
options[:policy_name] = u
|
46
55
|
end
|
47
56
|
opts.separator ""
|
48
57
|
end
|
58
|
+
|
59
|
+
def validate_args(args)
|
60
|
+
super(args)
|
61
|
+
|
62
|
+
if options[:action][0] == :bind
|
63
|
+
if options[:priority].nil?
|
64
|
+
options[:priority] = 1
|
65
|
+
elsif options[:priority] <= 0
|
66
|
+
raise Netscaler::ConfigurationError.new("The --priority must be greater than 0")
|
67
|
+
end
|
68
|
+
else
|
69
|
+
if options[:priority]
|
70
|
+
raise Netscaler::ConfigurationError.new("The --priority flag can only specified with the --bind option")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
49
74
|
end # CLI
|
50
75
|
end
|
@@ -1,55 +1,57 @@
|
|
1
|
+
require 'netscaler/logging'
|
1
2
|
require 'netscaler/baseexecutor'
|
2
3
|
|
3
4
|
module Netscaler::VServer
|
4
5
|
class Executor < Netscaler::BaseExecutor
|
6
|
+
include Netscaler::Logging
|
7
|
+
|
5
8
|
def initialize(host, client)
|
6
9
|
super(host, client)
|
7
10
|
@params = { :name => host }
|
8
11
|
end
|
9
12
|
|
10
|
-
def enable
|
13
|
+
def enable(options)
|
11
14
|
send_request('enablelbvserver', @params)
|
12
15
|
end
|
13
16
|
|
14
|
-
def disable
|
17
|
+
def disable(options)
|
15
18
|
send_request('disablelbvserver', @params)
|
16
19
|
end
|
17
20
|
|
18
|
-
def status
|
21
|
+
def status(options)
|
19
22
|
send_request('getlbvserver', @params) do |response|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
begin
|
24
|
+
info = response[:return][:list][:item]
|
25
|
+
puts "Name: #{info[:name]}"
|
26
|
+
puts "IP Address: #{info[:svcipaddress][:item]}"
|
27
|
+
puts "Port: #{info[:svcport][:item]}"
|
28
|
+
puts "State: #{info[:svcstate][:item]}"
|
29
|
+
rescue Exception => e
|
30
|
+
log.fatal "Unable to lookup any information for host: #{host}"
|
31
|
+
exit(1)
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|
27
35
|
|
28
|
-
def bind(
|
36
|
+
def bind(options)
|
29
37
|
params = {
|
30
38
|
:name => host,
|
31
|
-
:policyname => policy_name,
|
32
|
-
:priority =>
|
39
|
+
:policyname => options[:policy_name],
|
40
|
+
:priority => options[:priority],
|
33
41
|
:gotopriorityexpression => 'END'
|
34
42
|
}
|
35
43
|
|
36
|
-
send_request('bindlbvserver_policy', params)
|
37
|
-
#require 'pp'
|
38
|
-
#pp response
|
39
|
-
end
|
44
|
+
send_request('bindlbvserver_policy', params)
|
40
45
|
end
|
41
46
|
|
42
|
-
def unbind(
|
47
|
+
def unbind(options)
|
43
48
|
params = {
|
44
49
|
:name => host,
|
45
|
-
:policyname => policy_name,
|
50
|
+
:policyname => options[:policy_name],
|
46
51
|
:type => 'REQUEST'
|
47
52
|
}
|
48
53
|
|
49
|
-
send_request('unbindlbvserver_policy', params)
|
50
|
-
#require 'pp'
|
51
|
-
#pp response
|
52
|
-
end
|
54
|
+
send_request('unbindlbvserver_policy', params)
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
data/spec/helpers.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'helpers'
|
2
|
+
require 'netscaler/server/cli'
|
3
|
+
|
4
|
+
module Netscaler::Server
|
5
|
+
|
6
|
+
module CLIHelper
|
7
|
+
def parse(*args)
|
8
|
+
cli = CLI.new(args)
|
9
|
+
cli.parse_options(args)
|
10
|
+
cli.options
|
11
|
+
end
|
12
|
+
|
13
|
+
def validate(*args)
|
14
|
+
cli = CLI.new(args)
|
15
|
+
cli.parse_options(args)
|
16
|
+
cli.validate_args(args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "The CLI interface" do
|
21
|
+
include CLIHelper
|
22
|
+
|
23
|
+
describe "while parsing" do
|
24
|
+
it "should set the --enable flag correctly." do
|
25
|
+
parse('--enable')[:action][0].should eql(:enable)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should set the --disable flag correctly." do
|
29
|
+
parse('--disable')[:action][0].should eql(:disable)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'helpers'
|
2
|
+
require 'netscaler/service/cli'
|
3
|
+
|
4
|
+
module Netscaler::Service
|
5
|
+
|
6
|
+
module CLIHelper
|
7
|
+
def parse(*args)
|
8
|
+
cli = CLI.new(args)
|
9
|
+
cli.parse_options(args)
|
10
|
+
cli.options
|
11
|
+
end
|
12
|
+
|
13
|
+
def validate(*args)
|
14
|
+
cli = CLI.new(args)
|
15
|
+
cli.parse_options(args)
|
16
|
+
cli.validate_args(args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "The CLI interface" do
|
21
|
+
include CLIHelper
|
22
|
+
|
23
|
+
describe "while parsing" do
|
24
|
+
it "should set the --enable flag correctly." do
|
25
|
+
parse('--enable')[:action][0].should eql(:enable)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should set the --disable flag correctly." do
|
29
|
+
parse('--disable')[:action][0].should eql(:disable)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should set the --bind flag correctly." do
|
33
|
+
opts = parse('--bind', 'some-vserver')
|
34
|
+
opts[:action][0].should eql(:bind)
|
35
|
+
opts[:vserver].should eql('some-vserver')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should set the --unbind flag correctly." do
|
39
|
+
opts = parse('--unbind', 'some-vserver')
|
40
|
+
opts[:action][0].should eql(:unbind)
|
41
|
+
opts[:vserver].should eql('some-vserver')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/vserver/cli_spec.rb
CHANGED
@@ -9,37 +9,67 @@ module Netscaler::VServer
|
|
9
9
|
cli.parse_options(args)
|
10
10
|
cli.options
|
11
11
|
end
|
12
|
+
|
13
|
+
def validate(*args)
|
14
|
+
cli = CLI.new(args)
|
15
|
+
cli.parse_options(args)
|
16
|
+
cli.validate_args(args)
|
17
|
+
end
|
12
18
|
end
|
13
19
|
|
14
20
|
describe "The CLI interface" do
|
15
21
|
include CLIHelper
|
16
22
|
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
describe "while parsing" do
|
24
|
+
it "should set the --netscaler flag correctly." do
|
25
|
+
parse('--netscaler', 'localhost')[:netscaler].should eql('localhost')
|
26
|
+
end
|
20
27
|
|
21
|
-
|
22
|
-
|
23
|
-
|
28
|
+
it "should set the --debug flag correctly." do
|
29
|
+
parse('--debug')[:debug].should be(true)
|
30
|
+
end
|
24
31
|
|
25
|
-
|
26
|
-
|
27
|
-
|
32
|
+
it "should set the --enable flag correctly." do
|
33
|
+
parse('--enable')[:action][0].should eql(:enable)
|
34
|
+
end
|
28
35
|
|
29
|
-
|
30
|
-
|
31
|
-
|
36
|
+
it "should set the --disable flag correctly." do
|
37
|
+
parse('--disable')[:action][0].should eql(:disable)
|
38
|
+
end
|
32
39
|
|
33
|
-
|
34
|
-
|
35
|
-
|
40
|
+
it "should set the --bind flag correctly." do
|
41
|
+
opts = parse('--bind', 'some-policy')
|
42
|
+
opts[:action][0].should eql(:bind)
|
43
|
+
opts[:policy_name].should eql('some-policy')
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should set the --unbind flag correctly." do
|
47
|
+
opts = parse('--unbind', 'some-policy')
|
48
|
+
opts[:action][0].should eql(:unbind)
|
49
|
+
opts[:policy_name].should eql('some-policy')
|
50
|
+
end
|
36
51
|
|
37
|
-
|
38
|
-
|
52
|
+
it "should fail when the --priority flag is not an integer" do
|
53
|
+
attempting_to { parse('--priority', 'blah') }.should raise_error(OptionParser::InvalidArgument)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should set the --priority flag correctly." do
|
57
|
+
parse('--priority', '6')[:priority].should eql(6)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should set the --config flag correctly." do
|
61
|
+
parse('--config', 'CONFIG')[:config].should eql('CONFIG')
|
62
|
+
end
|
39
63
|
end
|
40
64
|
|
41
|
-
|
42
|
-
|
65
|
+
describe "while validating" do
|
66
|
+
it "should fail when the priority flag is set with unbind" do
|
67
|
+
attempting_to { validate('-n', 'net', '--unbind', 'policy', '--priority', '5', 'host') }.should raise_error(Netscaler::ConfigurationError, /priority/)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should set the priority when the bind flag is set." do
|
71
|
+
validate('-n', 'net', '--bind', 'policy', '--priority', '5', 'host')
|
72
|
+
end
|
43
73
|
end
|
44
74
|
end
|
45
75
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netscaler-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gabe McArthur
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-12 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -118,6 +118,8 @@ files:
|
|
118
118
|
- spec/configs/missing-username.yml
|
119
119
|
- spec/configs/simple-config.yml
|
120
120
|
- spec/helpers.rb
|
121
|
+
- spec/server/cli_spec.rb
|
122
|
+
- spec/service/cli_spec.rb
|
121
123
|
- spec/vserver/cli_spec.rb
|
122
124
|
has_rdoc: true
|
123
125
|
homepage: http://github.com/gabemc/netscaler-cli
|
@@ -156,4 +158,6 @@ summary: Simple command line utilities for interacting remotely with a Netscaler
|
|
156
158
|
test_files:
|
157
159
|
- spec/vserver/cli_spec.rb
|
158
160
|
- spec/helpers.rb
|
161
|
+
- spec/server/cli_spec.rb
|
162
|
+
- spec/service/cli_spec.rb
|
159
163
|
- spec/config_spec.rb
|