netscaler-cli 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/etc/Version CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -17,6 +17,8 @@ module Netscaler
17
17
  raise Netscaler::TransactionError.new("The parameters were empty.")
18
18
  end
19
19
 
20
+ params.delete(:empty)
21
+
20
22
  log.debug("Calling: #{name}")
21
23
 
22
24
  result = client.send("#{name}!") do |soap|
@@ -96,14 +96,25 @@ module Netscaler
96
96
  opts.separator ""
97
97
  end
98
98
 
99
+ def requires_argument?
100
+ true
101
+ end
102
+
103
+ def validate_noargs
104
+ end
105
+
99
106
  def validate_args(args)
100
- if args.length == 0
101
- raise Netscaler::ConfigurationError.new("No hosts specified to act on.")
102
- elsif args.length != 1
103
- raise Netscaler::ConfigurationError.new("Only one #{cli_type} can be acted on at a time.")
104
- end
107
+ if requires_argument?
108
+ if args.length == 0
109
+ raise Netscaler::ConfigurationError.new("No hosts specified to act on.")
110
+ elsif args.length != 1
111
+ raise Netscaler::ConfigurationError.new("Only one #{cli_type} can be acted on at a time.")
112
+ end
105
113
 
106
- @host = args[0]
114
+ @host = args[0]
115
+ else
116
+ validate_noargs
117
+ end
107
118
 
108
119
  if options[:action].empty?
109
120
  options[:action] << :status
@@ -1,4 +1,5 @@
1
1
  require 'netscaler/clitemplate'
2
+ require 'netscaler/errors'
2
3
  require 'netscaler/server/executor'
3
4
 
4
5
  module Netscaler::Server
@@ -12,7 +13,7 @@ module Netscaler::Server
12
13
  end
13
14
 
14
15
  def interface_header(opts)
15
- opts.banner = "Usage: #{File.basename($0)} [OPTIONS] SERVER"
16
+ opts.banner = "Usage: #{File.basename($0)} [OPTIONS] [SERVER]"
16
17
  opts.separator <<DESC
17
18
  Description:
18
19
  This is a tool for enabling and disabling a server in a Netscaler
@@ -22,10 +23,23 @@ Description:
22
23
  By default, this script will tell you what its current status of the
23
24
  server is.
24
25
 
26
+ If you want to list all of the services, use the --list flag with no
27
+ server argument.
28
+
25
29
  Options:
26
30
  DESC
27
31
  end
28
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
+
29
43
  def interface_actions(opts)
30
44
  opts.separator " Actions: "
31
45
  opts.on('-e', '--enable',
@@ -36,6 +50,10 @@ DESC
36
50
  "Disables the given server.") do |d|
37
51
  options[:action] << :disable
38
52
  end
53
+ opts.on('-l', '--list',
54
+ "Lists all of the servers in the environment") do |l|
55
+ options[:action] << :list
56
+ end
39
57
  opts.separator ""
40
58
  end
41
59
  end # CLI
@@ -15,9 +15,32 @@ module Netscaler::Server
15
15
  send_request('disableserver', @params)
16
16
  end
17
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
+
18
41
  def status(options)
19
42
  send_request('getserver', @params) do |response|
20
- resp = Response.new(response)
43
+ resp = Response.new(response[:return][:list][:item])
21
44
  if options[:json]
22
45
  puts resp.to_json
23
46
  else
@@ -28,11 +51,10 @@ module Netscaler::Server
28
51
  end
29
52
 
30
53
  class Response
31
- attr_reader :raw_response, :info
54
+ attr_reader :info
32
55
 
33
56
  def initialize(raw_response)
34
- @raw_response = raw_response
35
- @info = raw_response[:return][:list][:item]
57
+ @info = raw_response
36
58
  end
37
59
 
38
60
  def name
@@ -48,28 +70,46 @@ module Netscaler::Server
48
70
  end
49
71
 
50
72
  def services
51
- info[:servicename][:item]
73
+ if info[:servicename]
74
+ info[:servicename][:item]
75
+ else
76
+ []
77
+ end
52
78
  end
53
79
 
54
80
  def to_s
55
- base = "Name:\t#{name}\nIP Address:\t#{ip_address}\nState:\t#{state}\nServices:\n"
56
- services.each do |service|
57
- base << "\t#{service}\n"
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
58
89
  end
90
+
59
91
  base
60
92
  end
61
93
 
62
94
  def to_json
63
- base = "{ 'name': '#{name}', 'ip_address': '#{ip_address}', 'state': '#{state}', 'services': ["
95
+ base = "{ 'name': '#{name}', 'ip_address': '#{ip_address}', 'state': '#{state}'"
96
+
97
+ if services.empty?
98
+ base << " }"
99
+ else
100
+ base << ", 'services': ["
64
101
 
65
- services.each_with_index do |service, i|
66
- base << "'#{service}'"
67
- if i != services.length - 1
68
- base << ", "
102
+ services.each_with_index do |service, i|
103
+ base << "'#{service}'"
104
+ if i != services.length - 1
105
+ base << ", "
106
+ end
69
107
  end
108
+
109
+ base << "] }"
70
110
  end
71
111
 
72
- base << "] }"
112
+ base
73
113
  end
74
114
  end
75
115
  end
@@ -12,7 +12,7 @@ module Netscaler::VServer
12
12
  end
13
13
 
14
14
  def interface_header(opts)
15
- opts.banner = "Usage: #{File.basename($0)} [OPTIONS] VSERVER"
15
+ opts.banner = "Usage: #{File.basename($0)} [OPTIONS] [VSERVER]"
16
16
  opts.separator <<DESC
17
17
  Description:
18
18
  This is a tool for enabling and disabling a virtual server in a Netscaler
@@ -22,6 +22,9 @@ Description:
22
22
  By default, this script will tell you what its current status of the
23
23
  virtual server is.
24
24
 
25
+ If you want to list all of the virtual servers, use the --list flag with no
26
+ server argument.
27
+
25
28
  Options:
26
29
  DESC
27
30
  end
@@ -53,9 +56,23 @@ DESC
53
56
  options[:action] << :unbind
54
57
  options[:policy_name] = u
55
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
56
63
  opts.separator ""
57
64
  end
58
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
+
59
76
  def validate_args(args)
60
77
  super(args)
61
78
 
@@ -18,10 +18,33 @@ module Netscaler::VServer
18
18
  send_request('disablelbvserver', @params)
19
19
  end
20
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
+
21
44
  def status(options)
22
45
  send_request('getlbvserver', @params) do |response|
23
46
  begin
24
- resp = Response.new(response)
47
+ resp = Response.new(response[:return][:list][:item])
25
48
  if options[:json]
26
49
  puts resp.to_json
27
50
  else
@@ -58,11 +81,10 @@ module Netscaler::VServer
58
81
  end
59
82
 
60
83
  class Response
61
- attr_reader :raw_response, :info
84
+ attr_reader :info
62
85
 
63
86
  def initialize(raw_response)
64
- @raw_response = raw_response
65
- @info = raw_response[:return][:list][:item]
87
+ @info = raw_response
66
88
  end
67
89
 
68
90
  def name
@@ -91,7 +113,7 @@ module Netscaler::VServer
91
113
 
92
114
  def servers
93
115
  @parsed_servers ||= []
94
- if !@parsed_servers.empty?
116
+ if !@parsed_servers.empty? || info[:servicename].nil?
95
117
  return @parsed_servers
96
118
  end
97
119
 
@@ -121,27 +143,40 @@ module Netscaler::VServer
121
143
  end
122
144
 
123
145
  def to_s
124
- base = "Name:\t#{name}\nIP:\t#{ip_address}\nState:\t#{state}\nPort:\t#{port}\nType:\t#{type}\nServers:\n"
125
- servers.each do |server|
126
- base << server.to_s
127
- base << "\n\n"
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
128
154
  end
155
+
129
156
  base
130
157
  end
131
158
 
132
159
  def to_json
133
- base = "{ 'name': '#{name}', 'ip_address': '#{ip_address}', 'state': '#{state}', 'port': '#{port}', 'type': #{type}, 'servers': [\n "
134
-
135
- servers.each_with_index do |server, i|
136
- base << server.to_json
137
- if i != servers.length - 1
138
- base << ",\n "
139
- else
140
- base << "\n"
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
141
174
  end
175
+
176
+ base << "] }"
142
177
  end
143
178
 
144
- base << "] }"
179
+ base
145
180
  end
146
181
  end
147
182
 
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: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 1
10
- version: 0.3.1
9
+ - 2
10
+ version: 0.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gabe McArthur