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,60 +0,0 @@
1
- require 'netscaler/clitemplate'
2
- require 'netscaler/errors'
3
- require 'netscaler/server/executor'
4
-
5
- module Netscaler::Server
6
- class CLI < Netscaler::CLITemplate
7
- def initialize(args)
8
- super('server', args)
9
- end
10
-
11
- def create_executor(client)
12
- Netscaler::Server::Executor.new(host, client)
13
- end
14
-
15
- def interface_header(opts)
16
- opts.banner = "Usage: #{File.basename($0)} [OPTIONS] [SERVER]"
17
- opts.separator <<DESC
18
- Description:
19
- This is a tool for enabling and disabling a server in a Netscaler
20
- load balancer. The name of the server is required, as is the
21
- address of the Netscaler load balancer.
22
-
23
- By default, this script will tell you what its current status of the
24
- server is.
25
-
26
- If you want to list all of the services, use the --list flag with no
27
- server argument.
28
-
29
- Options:
30
- DESC
31
- end
32
-
33
- def requires_argument?
34
- false
35
- end
36
-
37
- def validate_noargs
38
- if !options[:action].include?(:list)
39
- raise Netscaler::ConfigurationError.new("No hosts specified to act on.")
40
- end
41
- end
42
-
43
- def interface_actions(opts)
44
- opts.separator " Actions: "
45
- opts.on('-e', '--enable',
46
- "Enables the given server.") do |e|
47
- options[:action] << :enable
48
- end
49
- opts.on('-d', '--disable',
50
- "Disables the given server.") do |d|
51
- options[:action] << :disable
52
- end
53
- opts.on('-l', '--list',
54
- "Lists all of the servers in the environment") do |l|
55
- options[:action] << :list
56
- end
57
- opts.separator ""
58
- end
59
- end # CLI
60
- end
@@ -1,115 +0,0 @@
1
- require 'netscaler/baseexecutor'
2
-
3
- module Netscaler::Server
4
- class Executor < Netscaler::BaseExecutor
5
- def initialize(host, client)
6
- super(host, client)
7
- @params = { :name => host }
8
- end
9
-
10
- def enable(options)
11
- send_request('enableserver', @params)
12
- end
13
-
14
- def disable(options)
15
- send_request('disableserver', @params)
16
- end
17
-
18
- def list(options)
19
- send_request('getserver', {:empty => :ok}) do |response|
20
- puts "[" if options[:json]
21
-
22
- servers = response[:return][:list][:item]
23
- servers.each_with_index do |server, i|
24
- resp = Response.new(server)
25
- if options[:json]
26
- if i == servers.length - 1
27
- puts " #{resp.to_json}"
28
- else
29
- puts " #{resp.to_json},"
30
- end
31
- else
32
- puts resp.to_s
33
- puts
34
- end
35
- end
36
-
37
- puts "]"if options[:json]
38
- end
39
- end
40
-
41
- def status(options)
42
- send_request('getserver', @params) do |response|
43
- resp = Response.new(response[:return][:list][:item])
44
- if options[:json]
45
- puts resp.to_json
46
- else
47
- puts resp.to_s
48
- end
49
- end
50
- end
51
- end
52
-
53
- class Response
54
- attr_reader :info
55
-
56
- def initialize(raw_response)
57
- @info = raw_response
58
- end
59
-
60
- def name
61
- info[:name]
62
- end
63
-
64
- def ip_address
65
- info[:ipaddress]
66
- end
67
-
68
- def state
69
- info[:state]
70
- end
71
-
72
- def services
73
- if info[:servicename]
74
- info[:servicename][:item]
75
- else
76
- []
77
- end
78
- end
79
-
80
- def to_s
81
- base = "Name:\t#{name}\nIP:\t#{ip_address}\nState:\t#{state}"
82
-
83
- if !services.empty?
84
- base << "\nServices:\n"
85
- services.each do |service|
86
- base << "\t#{service}\n"
87
- end
88
- base
89
- end
90
-
91
- base
92
- end
93
-
94
- def to_json
95
- base = "{ 'name': '#{name}', 'ip_address': '#{ip_address}', 'state': '#{state}'"
96
-
97
- if services.empty?
98
- base << " }"
99
- else
100
- base << ", 'services': ["
101
-
102
- services.each_with_index do |service, i|
103
- base << "'#{service}'"
104
- if i != services.length - 1
105
- base << ", "
106
- end
107
- end
108
-
109
- base << "] }"
110
- end
111
-
112
- base
113
- end
114
- end
115
- end
@@ -1,49 +0,0 @@
1
- require 'netscaler/clitemplate'
2
- require 'netscaler/service/executor'
3
-
4
- module Netscaler::Service
5
- class CLI < Netscaler::CLITemplate
6
- def initialize(args)
7
- super('service', args)
8
- end
9
-
10
- def create_executor(client)
11
- Netscaler::Service::Executor.new(host, client)
12
- end
13
-
14
- def interface_header(opts)
15
- opts.banner = "Usage: #{File.basename($0)} [OPTIONS] SERVICE"
16
- opts.separator <<DESC
17
- Description:
18
- This is a tool for enabling and disabling services in a Netscaler
19
- load balancer. The name of the service is required, as is the
20
- address of the Netscaler load balancer.
21
-
22
- Options:
23
- DESC
24
- end
25
-
26
- def interface_actions(opts)
27
- opts.separator " Actions: "
28
- opts.on('-e', '--enable',
29
- "Enables the given service.") do |e|
30
- options[:action] << :enable
31
- end
32
- opts.on('-d', '--disable',
33
- "Disables the given service.") do |d|
34
- options[:action] << :disable
35
- end
36
- opts.on('-b', '--bind VSERVER',
37
- "Binds a service to a virtual server.") do |b|
38
- options[:action] << :bind
39
- options[:vserver] = b
40
- end
41
- opts.on('-u', '--unbind VSERVER',
42
- "Unbinds a serivce to a virtual server.") do |u|
43
- options[:action] << :unbind
44
- options[:vserver] = u
45
- end
46
- opts.separator ""
47
- end
48
- end # CLI
49
- end
@@ -1,82 +0,0 @@
1
- require 'netscaler/baseexecutor'
2
-
3
- module Netscaler::Service
4
- class Executor < Netscaler::BaseExecutor
5
- def initialize(host, client)
6
- super(host, client)
7
- @params = { :name => host }
8
- end
9
-
10
- def enable(options)
11
- send_request('enableservice', @params)
12
- end
13
-
14
- def disable(options)
15
- params = {
16
- :name => host,
17
- :delay => 0
18
- }
19
- send_request('disableservice', params)
20
- end
21
-
22
- def bind(options)
23
- params = {
24
- :name => options[:vserver],
25
- :servicename => host
26
- }
27
- send_request('bindlbvserver_service', params)
28
- end
29
-
30
- def unbind(options)
31
- params = {
32
- :name => options[:vserver],
33
- :servicename => host
34
- }
35
- send_request('unbindlbvserver_service', params)
36
- end
37
-
38
- def status(options)
39
- send_request('getservice', @params) do |response|
40
- resp = Response.new(response)
41
- if options[:json]
42
- puts resp.to_json
43
- else
44
- puts resp.to_s
45
- end
46
- end
47
- end
48
- end
49
-
50
- class Response
51
- attr_reader :raw_response, :info
52
-
53
- def initialize(raw_response)
54
- @raw_response = raw_response
55
- @info = raw_response[:return][:list][:item]
56
- end
57
-
58
- def name
59
- info[:name]
60
- end
61
-
62
- def ip_address
63
- info[:ipaddress]
64
- end
65
-
66
- def state
67
- info[:svrstate]
68
- end
69
-
70
- def port
71
- info[:port]
72
- end
73
-
74
- def to_s
75
- "Name:\t#{name}\nIP:\t#{ip_address}\nState:\t#{state}\nPort:\t#{port}"
76
- end
77
-
78
- def to_json
79
- "{ 'name': '#{name}', 'ip_address': '#{ip_address}', 'state': '#{state}', 'port': #{port} }"
80
- end
81
- end
82
- end
@@ -1,92 +0,0 @@
1
- require 'netscaler/clitemplate'
2
- require 'netscaler/vserver/executor'
3
-
4
- module Netscaler::VServer
5
- class CLI < Netscaler::CLITemplate
6
- def initialize(args)
7
- super('vserver', args)
8
- end
9
-
10
- def create_executor(client)
11
- Netscaler::VServer::Executor.new(host, client)
12
- end
13
-
14
- def interface_header(opts)
15
- opts.banner = "Usage: #{File.basename($0)} [OPTIONS] [VSERVER]"
16
- opts.separator <<DESC
17
- Description:
18
- This is a tool for enabling and disabling a virtual server in a Netscaler
19
- load balancer. The name of the virtual server is required, as is the
20
- address of the Netscaler load balancer.
21
-
22
- By default, this script will tell you what its current status of the
23
- virtual server is.
24
-
25
- If you want to list all of the virtual servers, use the --list flag with no
26
- server argument.
27
-
28
- Options:
29
- DESC
30
- end
31
-
32
- def interface_actions(opts)
33
- opts.separator " Actions: "
34
- opts.on('-e', '--enable',
35
- "Enables the given virtual server.") do |e|
36
- options[:action] << :enable
37
- end
38
- opts.on('-d', '--disable',
39
- "Disables the given virtual server.") do |d|
40
- options[:action] << :disable
41
- end
42
- opts.on('-b', '--bind POLICY_NAME',
43
- "Binds a policy of a given name to a",
44
- "virtual server.") do |b|
45
- options[:action] << :bind
46
- options[:policy_name] = b
47
- end
48
- opts.on('-p', '--priority NUMBER', Integer,
49
- "The priority to bind the policy with.",
50
- "Used only with the --bind flag.") do |p|
51
- options[:priority] = p
52
- end
53
- opts.on('-u', '--unbind POLICY_NAME',
54
- "Unbinds a policy of a given name to a",
55
- "virtual server.") do |u|
56
- options[:action] << :unbind
57
- options[:policy_name] = u
58
- end
59
- opts.on('-l', '--list',
60
- "List all of the virtual servers in the environment.") do |l|
61
- options[:action] << :list
62
- end
63
- opts.separator ""
64
- end
65
-
66
- def requires_argument?
67
- false
68
- end
69
-
70
- def validate_noargs
71
- if !options[:action].include?(:list)
72
- raise Netscaler::ConfigurationError.new("No hosts specified to act on.")
73
- end
74
- end
75
-
76
- def validate_args(args)
77
- super(args)
78
-
79
- if options[:action][0] == :bind
80
- if options[:priority].nil?
81
- options[:priority] = 1
82
- elsif options[:priority] <= 0
83
- raise Netscaler::ConfigurationError.new("The --priority must be greater than 0")
84
- end
85
- else
86
- if options[:priority]
87
- raise Netscaler::ConfigurationError.new("The --priority flag can only specified with the --bind option")
88
- end
89
- end
90
- end
91
- end # CLI
92
- end
@@ -1,194 +0,0 @@
1
- require 'netscaler/logging'
2
- require 'netscaler/baseexecutor'
3
-
4
- module Netscaler::VServer
5
- class Executor < Netscaler::BaseExecutor
6
- include Netscaler::Logging
7
-
8
- def initialize(host, client)
9
- super(host, client)
10
- @params = { :name => host }
11
- end
12
-
13
- def enable(options)
14
- send_request('enablelbvserver', @params)
15
- end
16
-
17
- def disable(options)
18
- send_request('disablelbvserver', @params)
19
- end
20
-
21
- def list(options)
22
- send_request('getlbvserver', {:empty => :ok}) do |response|
23
- puts "[" if options[:json]
24
-
25
- vservers = response[:return][:list][:item]
26
- vservers.each_with_index do |vserver, i|
27
- resp = Response.new(vserver)
28
- if options[:json]
29
- if i == vservers.length - 1
30
- puts " #{resp.to_json}"
31
- else
32
- puts " #{resp.to_json},"
33
- end
34
- else
35
- puts resp.to_s
36
- puts
37
- end
38
- end
39
-
40
- puts "]"if options[:json]
41
- end
42
- end
43
-
44
- def status(options)
45
- send_request('getlbvserver', @params) do |response|
46
- begin
47
- resp = Response.new(response[:return][:list][:item])
48
- if options[:json]
49
- puts resp.to_json
50
- else
51
- puts resp.to_s
52
- end
53
- rescue Exception => e
54
- log.fatal "Unable to lookup any information for host: #{host}"
55
- puts e
56
- exit(1)
57
- end
58
- end
59
- end
60
-
61
- def bind(options)
62
- params = {
63
- :name => host,
64
- :policyname => options[:policy_name],
65
- :priority => options[:priority],
66
- :gotopriorityexpression => 'END'
67
- }
68
-
69
- send_request('bindlbvserver_policy', params)
70
- end
71
-
72
- def unbind(options)
73
- params = {
74
- :name => host,
75
- :policyname => options[:policy_name],
76
- :type => 'REQUEST'
77
- }
78
-
79
- send_request('unbindlbvserver_policy', params)
80
- end
81
- end
82
-
83
- class Response
84
- attr_reader :info
85
-
86
- def initialize(raw_response)
87
- @info = raw_response
88
- end
89
-
90
- def name
91
- info[:name]
92
- end
93
-
94
- def ip_address
95
- if info[:ipaddress] =~ /0\.0\.0\.0/
96
- info[:ipaddress2]
97
- else
98
- info[:ipaddress]
99
- end
100
- end
101
-
102
- def type
103
- info[:servicetype]
104
- end
105
-
106
- def port
107
- info[:port]
108
- end
109
-
110
- def state
111
- info[:state]
112
- end
113
-
114
- def servers
115
- @parsed_servers ||= []
116
- if !@parsed_servers.empty? || info[:servicename].nil?
117
- return @parsed_servers
118
- end
119
-
120
- info[:servicename][:item].each do |name|
121
- srv = ServerInfo.new
122
- srv.name = name
123
- @parsed_servers << srv
124
- end
125
-
126
- info[:svcstate][:item].each_with_index do |state, i|
127
- @parsed_servers[i].state = state
128
- end
129
-
130
- info[:svcport][:item].each_with_index do |port, i|
131
- @parsed_servers[i].port = port
132
- end
133
-
134
- info[:svcipaddress][:item].each_with_index do |ip_address, i|
135
- @parsed_servers[i].ip_address = ip_address
136
- end
137
-
138
- info[:svctype][:item].each_with_index do |type, i|
139
- @parsed_servers[i].type = type
140
- end
141
-
142
- @parsed_servers
143
- end
144
-
145
- def to_s
146
- base = "Name:\t#{name}\nIP:\t#{ip_address}\nState:\t#{state}\nPort:\t#{port}\nType:\t#{type}"
147
-
148
- if !servers.empty?
149
- base << "\nServers:\n"
150
- servers.each do |server|
151
- base << server.to_s
152
- base << "\n\n"
153
- end
154
- end
155
-
156
- base
157
- end
158
-
159
- def to_json
160
- base = "{ 'name': '#{name}', 'ip_address': '#{ip_address}', 'state': '#{state}', 'port': #{port}, 'type': '#{type}'"
161
-
162
- if servers.empty?
163
- base << " }"
164
- else
165
- base << ", 'servers': [\n "
166
-
167
- servers.each_with_index do |server, i|
168
- base << server.to_json
169
- if i != servers.length - 1
170
- base << ",\n "
171
- else
172
- base << "\n"
173
- end
174
- end
175
-
176
- base << "] }"
177
- end
178
-
179
- base
180
- end
181
- end
182
-
183
- class ServerInfo
184
- attr_accessor :name, :ip_address, :state, :port, :type
185
-
186
- def to_s
187
- "\tName:\t#{name}\n\tIP:\t#{ip_address}\n\tState:\t#{state}\n\tPort:\t#{port}\n\tType:\t#{type}"
188
- end
189
-
190
- def to_json
191
- "{ 'name': '#{name}', 'ip_address': '#{ip_address}', 'state': '#{state}', 'port': #{port}, 'type': '#{type}' }"
192
- end
193
- end
194
- end