icontrol 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ # For the
2
+ IControl::LocalLB::Monitor
3
+
4
+ class IControl::LocalLB::Monitor
5
+
6
+ set_id_name :pool_name
7
+
8
+ def self.id_name
9
+ :pool_name
10
+ end
11
+
12
+
13
+ private
14
+ def default_body
15
+ {"pool_names" => {:value => [@attributes[:id]] }}
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ class IControl::LocalLB::MonitorRule
2
+
3
+ include Attributable
4
+
5
+ def self.from_xml(xml_hash)
6
+ monitor_templates = [xml_hash.delete(:monitor_templates)[:item]].flatten
7
+ return self.new(:quorum => xml_hash[:quorum],:monitor_templates => monitor_templates,:type => xml_hash[:type])
8
+ end
9
+
10
+ def initialize(attributes)
11
+ attributes[:quorum] ||= "0"
12
+ super
13
+ end
14
+
15
+ def rule_type
16
+ @attributes[:type]
17
+ end
18
+
19
+ def rule_type=(monitor_type)
20
+ @attributes[:type] = monitor_type
21
+ end
22
+ end
@@ -0,0 +1,76 @@
1
+ # For the
2
+ IControl::LocalLB::Pool
3
+
4
+ class IControl::LocalLB::Pool
5
+
6
+ set_id_name :pool_name
7
+
8
+ def status_for(pool_member)
9
+ status = IControl::LocalLB::PoolMember.get_object_status do |soap|
10
+ soap.body = { "pool_names" => {:value => [@attributes[:id]] } }
11
+ end
12
+ pool_info = status.find { |i| i.address == pool_member.address && i.port == pool_member.port }
13
+ return pool_info.status if pool_info
14
+ end
15
+
16
+ def lb_method
17
+ aux = super
18
+ return aux.first if aux.respond_to? 'first'
19
+ aux
20
+ end
21
+
22
+ # This method clones a pool with another name (id)
23
+ def clone(new_id)
24
+ prv_monitor_rule = monitor_rule
25
+ new_pool = IControl::LocalLB::Pool.create(:id => new_id, :lb_method => lb_method, :members => member)
26
+ new_pool.monitor_rule = prv_monitor_rule
27
+ return new_pool
28
+ end
29
+
30
+ def destroy
31
+ return delete_pool
32
+ end
33
+
34
+ # Returns a collection of the monitors associated with this pool
35
+ def monitor_rule
36
+ return monitor_association
37
+ end
38
+
39
+ def monitor_rule=(new_monitor_rule)
40
+ item = 0
41
+
42
+ templates = new_monitor_rule.monitor_templates.map { |i| {:"item#{item+=1}" => i}}
43
+ rule_type = ( templates.length > 1 ) ? "MONITOR_RULE_TYPE_AND_LIST" : "MONITOR_RULE_TYPE_SINGLE"
44
+ response = IControl::LocalLB::Pool.set_monitor_association do |soap|
45
+ soap.body = {
46
+ "monitor_associations" => {
47
+ "item" => {
48
+ "pool_name" => @attributes[:id] ,
49
+
50
+ "monitor_rule" => {
51
+ :type => rule_type,
52
+ :quorum => new_monitor_rule.quorum,
53
+ "monitor_templates" => templates
54
+ }
55
+ }
56
+
57
+ }
58
+ }
59
+ end
60
+ end
61
+
62
+ def self.create(attributes)
63
+ response = super do |soap|
64
+ item = 0
65
+ members = {}
66
+ attributes[:members].each{ |i| members[:"item#{item+=1}"] = {:address => i.address, :port => i.port } }
67
+
68
+ soap.body = {
69
+ "pool_names" => {:item => attributes[:id] },
70
+ "lb_methods" => {:item => attributes[:lb_method]},
71
+ "members" => {:item => members}
72
+ }
73
+ end
74
+ return new(attributes)
75
+ end
76
+ end
@@ -0,0 +1,5 @@
1
+ IControl::LocalLB::PoolMember
2
+
3
+ class IControl::LocalLB::PoolMember
4
+ set_id_name :pool_name
5
+ end
@@ -0,0 +1,6 @@
1
+ # For the
2
+ IControl::LocalLB::ProfileAuth
3
+ class IControl::LocalLB::ProfileAuth
4
+ set_id_name :profile_name
5
+ end
6
+
@@ -0,0 +1,242 @@
1
+ # For the
2
+ IControl::LocalLB::ProfileHttpClass
3
+
4
+ class IControl::LocalLB::ProfileHttpClass
5
+
6
+ set_id_name :profile_name
7
+
8
+
9
+ # Deletes the specified HTTP class profiles.
10
+ def delete
11
+ super.delete_profile
12
+ end
13
+
14
+ def ==(profile)
15
+ return self.id == profile.id
16
+ end
17
+
18
+
19
+ # Creates the specified HTTP class profiles.
20
+ def self.create!(profile_name)
21
+ self.create do |soap|
22
+ soap.body = {"profile_names" => {"value" => profile_name} }
23
+ end
24
+ return self.find(profile_name)
25
+ end
26
+
27
+ def profile_type
28
+ return IControl::LocalLB::ProfileType::PROFILE_TYPE_HTTPCLASS
29
+ end
30
+
31
+ def pool
32
+ self.pool_name.first
33
+ end
34
+
35
+ def pool=(pool,default_flag = false)
36
+ IControl::LocalLB::ProfileHttpClass.set_pool_name do |soap|
37
+ soap.body = {
38
+ "pool_names" => { :item => {:value => pool.id, "default_flag" => default_flag } },
39
+ "profile_names" => { "value" => id }
40
+ }
41
+ end
42
+ end
43
+
44
+ # Determines whether the specified profile is base/pre-configured profile, or user-defined profile.
45
+ def base_profile?
46
+ self.is_base_profile
47
+ end
48
+
49
+ # Gets the names of the default profile from which the specifie profile will derive default values for its attributes.
50
+ def default_profile
51
+ profile = super
52
+ IControl::LocalLB::ProfileHttpClass.find(profile)
53
+ end
54
+
55
+ # Sets the names of the default profiles from which the specified profiles will derive default values for its attributes.
56
+ def default_profile=(profile)
57
+ IControl::LocalLB::ProfileHttpClass.set_default_profile do |soap|
58
+ soap.body = {
59
+ "profile_names" => {"value" => id},
60
+ "defaults" => {"value" => profile.id}
61
+ }
62
+ end
63
+ end
64
+
65
+ # Gets the lists of patterns used to match the hosts.
66
+ def host_match_pattern
67
+ super
68
+ end
69
+
70
+ # Resets the lists to parent defaults.
71
+ def set_default_host_match_pattern
72
+ super
73
+ host_match_pattern
74
+ end
75
+
76
+ # Adds a new pattern to the lists of patterns used to match the hosts
77
+ # * pattern: The string of the pattern that is to be used
78
+ # * is_glob: Whether the pattern is a string or not (defaults to false, i.e. regexps)
79
+ def add_host_match_pattern (pattern,is_glob = false)
80
+ pattern_operation("add","host",pattern,is_glob)
81
+ end
82
+
83
+ # Removes from the lists of patterns used to match the hosts
84
+ # * pattern: The string of the pattern that is to be used
85
+ # * is_glob: Whether the pattern is a string or not (defaults to false, i.e. regexps)
86
+ def remove_host_match_pattern (pattern,is_glob = false)
87
+ pattern_operation("remove","host",pattern,is_glob)
88
+ end
89
+
90
+ # Gets the lists of patterns used to match the paths.
91
+ def path_match_pattern
92
+ super
93
+ end
94
+
95
+ # Resets the lists to parent defaults.
96
+ def set_default_path_match_pattern
97
+ super
98
+ path_match_pattern
99
+ end
100
+
101
+ # Adds a pattern to the lists of patterns used to match the paths
102
+ # * pattern: The string of the pattern that is to be used
103
+ # * is_glob: Whether the pattern is a string or not (defaults to false, i.e. regexps)
104
+ def add_path_match_pattern (pattern,is_glob = false)
105
+ pattern_operation("add","path",pattern,is_glob)
106
+ end
107
+
108
+ # Removes from the lists of patterns used to match the paths
109
+ # * pattern: The string of the pattern that is to be used
110
+ # * is_glob: Whether the pattern is a string or not (defaults to false, i.e. regexps)
111
+ def remove_path_match_pattern (pattern,is_glob = false)
112
+ pattern_operation("remove","path",pattern,is_glob)
113
+ end
114
+
115
+ # Gets the lists of used to match the headers.
116
+ def header_match_pattern
117
+ super
118
+ end
119
+
120
+ # Resets the lists to parent defaults.
121
+ def set_default_header_match_pattern
122
+ super
123
+ header_match_pattern
124
+ end
125
+
126
+ # Adds a pattern to the lists of patterns used to match the headers
127
+ # * pattern: The string of the pattern that is to be used
128
+ # * is_glob: Whether the pattern is a string or not (defaults to false, i.e. regexps)
129
+ def add_header_match_pattern (pattern,is_glob = false)
130
+ pattern_operation("add","header",pattern,is_glob)
131
+ end
132
+
133
+ # Removes from the lists of patterns used to match the headers
134
+ # * pattern: The string of the pattern that is to be used
135
+ # * is_glob: Whether the pattern is a string or not (defaults to false, i.e. regexps)
136
+ def remove_header_match_pattern (pattern,is_glob = false)
137
+ pattern_operation("remove","header",pattern,is_glob)
138
+ end
139
+
140
+ # Gets the lists of used to match the headers.
141
+ def cookie_match_pattern
142
+ super
143
+ end
144
+
145
+ # Resets the lists to parent defaults.
146
+ def set_default_cookie_match_pattern
147
+ super
148
+ cookie_match_pattern
149
+ end
150
+
151
+ # Adds a pattern to the lists of patterns used to match the cookies
152
+ # * pattern: The string of the pattern that is to be used
153
+ # * is_glob: Whether the pattern is a string or not (defaults to false, i.e. regexps)
154
+ def add_cookie_match_pattern (pattern,is_glob = false)
155
+ pattern_operation("add","cookie",pattern,is_glob)
156
+ end
157
+
158
+ # Removes from the lists of patterns used to match the cookies
159
+ # * pattern: The string of the pattern that is to be used
160
+ # * is_glob: Whether the pattern is a string or not (defaults to false, i.e. regexps)
161
+ def remove_cookie_match_pattern (pattern,is_glob = false)
162
+ pattern_operation("remove","cookie",pattern,is_glob)
163
+ end
164
+
165
+ # Gets the string (which may include a TCL expression) with which to rewrite the URLs.
166
+ def rewrite_url
167
+ value = super.first
168
+ if value
169
+ value_string = value.value
170
+ value_string = "" if value_string.class != String
171
+ return {:rule => value_string,:default_flag => value.default_flag}
172
+ end
173
+ value
174
+ end
175
+
176
+ # Sets the strings (which may include a TCL expression) with which to rewrite the URLs.
177
+ # if default_flag is true then the rewriting is disabled (default_flag means work as default)
178
+ def set_rewrite_url(rule,default_flag = false)
179
+ match_operation("rewrite_url",rule,default_flag)
180
+ end
181
+
182
+ # Unsets the rewrite url
183
+ def unset_rewrite_url
184
+ set_rewrite_url("",true)
185
+ end
186
+
187
+ # Gets the string (which may include a TCL expression) to indicates where to
188
+ # redirect the original HTTP request once a match occurs. For example, to redirect
189
+ # requests to https://myserver.com to http://myotherserver.com.
190
+ def redirect_location
191
+ value = super.first
192
+ if value
193
+ value_string = value.value
194
+ value_string = "" if value_string.class != String
195
+ return {:rule => value_string,:default_flag => value.default_flag}
196
+ end
197
+ value
198
+ end
199
+
200
+ # Sets the strings (which may include a TCL expression) with which to rewrite the URLs.
201
+ # if default_flag is true then the rewriting is disabled (default_flag means work as default)
202
+ def set_redirect_location(rule,default_flag = false)
203
+ match_operation("redirect_location",rule,default_flag)
204
+ end
205
+
206
+ # Unsets the rewrite url
207
+ def unset_redirect_location
208
+ set_redirect_location("",true)
209
+ end
210
+
211
+ private
212
+
213
+ #
214
+ def match_operation(type,rule,default_flag)
215
+ parameter = type == "redirect_location" ? "redirect_locations" : "urls"
216
+ IControl::LocalLB::ProfileHttpClass.send("set_#{type}") do |soap|
217
+ soap.body = {
218
+ "profile_names" => {"value" => id},
219
+ parameter => {"item" => {"value" => rule,"default_flag" => default_flag}}
220
+ }
221
+ end
222
+ send("#{type}")
223
+ end
224
+
225
+ # Generic method for matching manipulation
226
+ def pattern_operation(op,type,pattern,is_glob)
227
+ if pattern.class == Hash
228
+ pattern["is_glob"] = pattern[:is_glob]
229
+ pattern_hash = pattern
230
+ else
231
+ pattern_hash = {"pattern" => pattern ,"is_glob" => is_glob}
232
+ end
233
+ IControl::LocalLB::ProfileHttpClass.send("#{op}_#{type}_match_pattern") do |soap|
234
+ soap.body = {
235
+ "profile_names" => {"value" => id},
236
+ "patterns" => {"item" => {"value" => pattern_hash }}
237
+ }
238
+ end
239
+ pattern_hash
240
+ end
241
+
242
+ end
@@ -0,0 +1,4 @@
1
+ IControl::LocalLB::RateClass
2
+ class IControl::LocalLB::RateClass
3
+ set_id_name :rate_class_name
4
+ end
@@ -0,0 +1,4 @@
1
+ IControl::LocalLB::Rule
2
+ class IControl::LocalLB::Rule
3
+ set_id_name :rule_name
4
+ end
@@ -0,0 +1,4 @@
1
+ IControl::LocalLB::SNATPool
2
+ class IControl::LocalLB::SNATPool
3
+ set_id_name :snat_pool_name
4
+ end
@@ -0,0 +1,611 @@
1
+ #
2
+ # TODO:
3
+ # - protocol_type= does not seem to work ( there is something that prevent the protocol to be assigned in the server side )
4
+ # - module_score Does not return any module score
5
+ # - persostence_record Does not work, it expects more arguments than documented
6
+ #
7
+
8
+ IControl::LocalLB::VirtualServer
9
+ class IControl::LocalLB::VirtualServer
10
+
11
+ class Type
12
+ include IControl::ConstDefiner
13
+ valid_consts = [:RESOURCE_TYPE_POOL,:RESOURCE_TYPE_IP_FORWARDING,:RESOURCE_TYPE_L2_FORWARDING,
14
+ :RESOURCE_TYPE_REJECT,:RESOURCE_TYPE_FAST_L4,:RESOURCE_TYPE_FAST_HTTP]
15
+
16
+ declare_constants valid_consts,Type
17
+ end
18
+
19
+ class CMPEnableMode
20
+ include IControl::ConstDefiner
21
+ valid_consts = [:RESOURCE_TYPE_CMP_ENABLE_ALL,:RESOURCE_TYPE_CMP_ENABLE_SINGLE,
22
+ :RESOURCE_TYPE_CMP_ENABLE_GROUP,:RESOURCE_TYPE_CMP_ENABLE_UNKNOWN]
23
+
24
+ declare_constants valid_consts,CMPEnableMode
25
+ end
26
+
27
+ class StatisticEntry
28
+ attr_accessor :virtual_server,:statistics
29
+
30
+ def self.from_xml(result)
31
+ result[:item] = [result[:item]].flatten
32
+ aux_result = result[:item].map do |i|
33
+ aux = self.new
34
+ aux.virtual_server = IControl::LocalLB::VirtualServer.find(i[:virtual_server][:name])
35
+ aux.statistics = {}
36
+ i[:statistics][:item].each do |entry|
37
+ aux.statistics[IControl::Common::StatisticType.from_string(entry[:type])] = IControl::Common::ULong64.new(entry[:value])
38
+ end
39
+ aux
40
+ end
41
+ return aux_result.length == 1 ? aux_result.first : aux_result
42
+ end
43
+ end
44
+
45
+ class ModuleScore
46
+ attr_accessor :tmos_module ,:score
47
+ def initialize(attribules)
48
+ @score = attributes[:score]
49
+ @tmos_module = IControl::Common::TMOSModule.from_string(attributes[:tmos_module])
50
+ end
51
+ end
52
+ =begin
53
+ class Rule
54
+ attr_accessor :rule_name,:priority
55
+ def initialize(attributes)
56
+ @rule_name = attributes[:rule_name]
57
+ @priority = ( attributes[:priority] && attributes[:priority].to_i ) || -1
58
+ end
59
+ end
60
+ =end
61
+
62
+ class ClonePool
63
+ attr_accessor :pool,:clone_type
64
+ def initialize(attributes)
65
+ @pool = IControl::LocalLB::Pool.find(attributes[:pool_name])
66
+ @clone_type = IControl::LocalLB::ClonePoolType.from_string(attributes[:type])
67
+ end
68
+ end
69
+
70
+ class ProfileAttribute
71
+ attr_accessor :profile_type,:profile_context,:profile_name
72
+ def initialize(options)
73
+ @profile_type = options[:profile_type]
74
+ @profile_context = options[:profile_context]
75
+ @profile_name = options[:profile_name]
76
+ end
77
+ end
78
+
79
+ class Persistence
80
+ attr_accessor :profile_name,:default_profile
81
+ def initialize(options)
82
+ @profile_name = options[:profile_name]
83
+ @default_profile = ( options[:default_profile] == "true" )
84
+ end
85
+ end
86
+
87
+ class GenericEnumerator
88
+
89
+ STATE_CHANGED=[ :<<, :push, :pop, :shift, :unshift, :insert, :join, :reverse!, :sort!, :collect!,:map!, :delete, :delete_at, :delete_if, :reject!,:slice!, :uniq!, :compact!, :flatten!, :shuffle! ]
90
+
91
+ attr_accessor :parent,:contents
92
+
93
+ def initialize(contents,parent)
94
+ @contents = contents
95
+ @parent = parent
96
+ end
97
+
98
+
99
+ def method_missing(method_name,*args)
100
+ if @contents.methods.include? method_name
101
+ output = @contents.send(method_name,*args)
102
+ save! if STATE_CHANGED.include? method_name
103
+ return output
104
+ else
105
+ super
106
+ end
107
+ end
108
+ end
109
+
110
+
111
+ class HttpClassProfileEnumerator < GenericEnumerator
112
+ def save!
113
+ @parent.remove_all_httpclass_profiles
114
+ @parent.add_httpclass_profile(@contents)
115
+ end
116
+ end
117
+
118
+ class RuleEnumerator < GenericEnumerator
119
+ def save!
120
+ @parent.remove_all_rules
121
+ @parent.add_rule(@contents)
122
+ end
123
+ end
124
+
125
+ class AuthProfileEnumerator < GenericEnumerator
126
+ def save!
127
+ @parent.remove_all_authentication_profiles
128
+ @parent.add_authentication_profile(@contents)
129
+ end
130
+ end
131
+
132
+ set_id_name :virtual_server
133
+
134
+ # This method creates a new virtual_server
135
+ # receives a Hash with this values
136
+ # :name => "The name of the virtual host"
137
+ # :address => "the ip address of the virtual server"
138
+ # :port => "the port the server is going to listen to"
139
+ # :protocol => "a protocol type"
140
+ # :wildmask => "The wildmask of the virtual server"
141
+ # :type => "The type of the virtual_server"
142
+ # :default_pool_name => "The default pool name"
143
+ # :profiles
144
+ #
145
+ def self.create(attributes)
146
+ item = 0
147
+ profiles = {}
148
+ raise IControl::NoSuchPoolException.new(attributes[:default_pool]) unless attributes[:default_pool]
149
+
150
+ attributes[:profiles].each do |i|
151
+ if i.class == Hash
152
+ profiles["item#{item+=1}"] = {"profile_context" => i["profile_context"].class_name,"profile_name" => ( i["profile"] ? i["profile"] : "tcp" ) }
153
+ else
154
+ profiles["item#{item+=1}"] = {"profile_context" => i.profile_context,"profile_name" => i.profile_name || "tcp" }
155
+ end
156
+ end
157
+ response = super do |soap|
158
+ soap.body = {
159
+ "definitions" => {:item => {
160
+ :name => attributes[:name],
161
+ :address => attributes[:address],
162
+ "port" => attributes[:port],
163
+ :protocol => (attributes[:protocol] || IControl::Common::ProtocolType::PROTOCOL_TCP).class_name
164
+ }
165
+ },
166
+ "wildmasks" => {:item => attributes[:wildmask] || "255.255.255.255"},
167
+ "resources" => {:item => {
168
+ :type => (attributes[:type] || IControl::LocalLB::VirtualServer::Type::RESOURCE_TYPE_POOL).class_name,
169
+ "default_pool_name" => attributes[:default_pool] ? attributes[:default_pool].id : ""
170
+ }
171
+ },
172
+ "profiles" => {:item => profiles}
173
+ }
174
+ end
175
+ return find(attributes[:name])
176
+ end
177
+
178
+ def destroy
179
+ return delete_virtual_server
180
+ end
181
+
182
+ # Gets the wildmask for the specified virtual server.
183
+ def wildmask
184
+ super
185
+ end
186
+ # Sets the wildmask
187
+ def wildmask=(wildmask)
188
+ IControl::LocalLB::VirtualServer.set_wildmask do |soap|
189
+ soap.body = {
190
+ "virtual_servers" => {:item => id},
191
+ "wildmasks" => {:item => wildmask }
192
+ }
193
+ end
194
+ end
195
+
196
+
197
+ def type
198
+ super
199
+ end
200
+
201
+ # Sets the type for the virtual server
202
+ def type=(new_type)
203
+ IControl::LocalLB::VirtualServer.set_type do |soap|
204
+ soap.body = {
205
+ "virtual_servers" => {:item => id},
206
+ "types" => {:item => new_type.class_name}
207
+ }
208
+ end
209
+ end
210
+
211
+ # Gets the CMP enable modes from the specified virtual servers.
212
+ # This is read-only, as the modes are set according to the system and
213
+ # configuration, and influenced by the desired CMP enabled state.
214
+ def cmp_enable_mode
215
+ super
216
+ end
217
+
218
+ # Gets the destination IP and port of the specified virtual servers.
219
+ # it returns an instance of class IControl::Common::IPPortDefinition
220
+ # that has mainly two methods, address and port
221
+ def destination
222
+ super
223
+ end
224
+
225
+ # Sets the destination IP and port
226
+ # it receives an IPPortDefinition instance with the keys
227
+ # :address and :port
228
+ def destination=(destination)
229
+ IControl::LocalLB::VirtualServer.set_destination do |soap|
230
+ soap.body = {
231
+ "virtual_servers" => {:item => id},
232
+ "destinations" => {:item => {:address => destination.address, :port => destination.port }}
233
+ }
234
+ end
235
+ end
236
+
237
+ # Gets the protocols supported by the specified virtual servers
238
+ def protocol
239
+ super
240
+ end
241
+
242
+ # Gets the protocols supported by the specified virtual servers.
243
+ def enabled_state
244
+ super
245
+ end
246
+
247
+ # Sets the enabled state of the specified virtual servers.
248
+ def enabled_state=(state)
249
+ IControl::LocalLB::VirtualServer.set_enabled_state do |soap|
250
+ soap.body = {
251
+ "virtual_servers" => {:item => id},
252
+ "states" => {:item => state.class_name}
253
+ }
254
+ end if state
255
+ end
256
+
257
+ # Gets the rate classes that will be used to rate limit the traffic.
258
+ def rate_class
259
+ rate_class = get_rate_class
260
+ IControl::LocalLB::RateClass.find(rate_class) if rate_class
261
+ end
262
+
263
+ # Sets the rate class that will be used to rate limit the traffic.
264
+ def rate_class=(rate)
265
+ IControl::LocalLB::VirtualServer.set_rate_class do |soap|
266
+ soap.body = {"virtual_servers" => {:item => id},"rate_classes" => {:item => rate}}
267
+ end
268
+ end
269
+
270
+ # Gets the mirror connection states for the specified virtual servers.
271
+ def connection_mirror_state
272
+ super
273
+ end
274
+
275
+ def connection_mirror_state=(state)
276
+ IControl::LocalLB::VirtualServer.set_connection_mirror_state do |soap|
277
+ soap.body = {"virtual_servers" => {:item => id},:states => {:item => state.class_name }}
278
+ end
279
+ end
280
+
281
+ # Gets the connection limits for the specified virtual servers.
282
+ def connection_limit
283
+ super
284
+ end
285
+
286
+ # Sets the connection limits of the specified virtual server.
287
+ def connection_limit=(limit)
288
+ IControl::LocalLB::VirtualServer.set_connection_limit do |soap|
289
+ soap.body = {"virtual_servers" => {:item => id},:limits => {:item => IControl::Common::ULong64.new(:low => limit).to_hash}}
290
+ end
291
+ end
292
+
293
+ # Gets the port translation states for the specified virtual servers. Enables or disables port translation.
294
+ def translate_port_state
295
+ super
296
+ end
297
+
298
+ # Gets the address translation states for the specified virtual servers. Enables or disables address translation.
299
+ def translate_address_state
300
+ super
301
+ end
302
+
303
+ # Gets the source port behavior for the specified virtual servers.
304
+ def source_port_behavior
305
+ super
306
+ end
307
+
308
+ # Gets the last hop pools for the specified virtual servers.
309
+ def last_hop_pool
310
+ pool_name = super
311
+ IControl::LocalLB::Pool.find(pool_name) if pool_name
312
+ end
313
+
314
+ # Gets the actual hardware acceleration modes for the specified virtual servers.
315
+ def actual_hardware_acceleration
316
+ super
317
+ end
318
+
319
+ # Gets the SNAT type for the specified virtual servers.
320
+ def snat_type
321
+ super
322
+ end
323
+
324
+ def snat_type=(new_type)
325
+ method = new_type == IControl::LocalLB::SnatType::SNAT_TYPE_AUTOMAP ? "set_snat_automap" : "set_snat_none"
326
+ IControl::LocalLB::VirtualServer.send(method) do |soap|
327
+ soap.body = {"virtual_servers" => {:item => id}}
328
+ end
329
+ end
330
+
331
+ # Gets the SNAT pools to be used in iSNAT configurations for the specified virtual servers.
332
+ def snat_pool
333
+ snat = super
334
+ IControl::LocalLB::SNATPool.find(snat) if snat
335
+ end
336
+
337
+ # Gets the persistence profiles to use for fallback persistence for the specified virtual servers.
338
+ # A string is returned
339
+ def fallback_persistence_profile
340
+ super
341
+ end
342
+
343
+
344
+ def enable_fallback_persistence_profile!
345
+ fallback_persistence_profile = IControl::Common::EnabledState::STATE_ENABLED
346
+ end
347
+
348
+ def disable_fallback_persistence_profile!
349
+ fallback_persistence_profile = IControl::Common::EnabledState::STATE_DISABLED
350
+ end
351
+
352
+ private
353
+
354
+ # Sets de fallback persistence profile profile has to be a string
355
+ def fallback_persistence_profile=(profile)
356
+ IControl::LocalLB::VirtualServer.set_fallback_persistence_profile do |soap|
357
+ soap.body = {
358
+ "virtual_servers" => {:item => id},
359
+ "profile_names" => {:item => profile}
360
+ }
361
+ end if profile
362
+ end
363
+
364
+ public
365
+
366
+ # Gets the lists of VLANs on which access to the specified Virtual Servers are enabled/disabled.
367
+ def vlan
368
+ super
369
+ end
370
+
371
+ # Gets the lists of profiles the specified virtual server are associated with.
372
+ def profiles
373
+ return get_profile
374
+ end
375
+
376
+ # Gets the default pool for the specified virtual server.
377
+ def default_pool
378
+ return IControl::LocalLB::Pool.find(default_pool_name)
379
+ end
380
+
381
+ def default_pool=(pool)
382
+ IControl::LocalLB::VirtualServer.set_default_pool_name do |soap|
383
+ soap.body = {
384
+ "virtual_servers" => {:item => id},
385
+ "default_pools" => {:item => pool.id }
386
+ }
387
+ end if pool
388
+ end
389
+
390
+ # Gets the lists of persistence profiles the virtual server is associated with.
391
+ def persistence_profile
392
+ super
393
+ end
394
+
395
+ # Gets the lists of clone pools the virtual server is associated with.
396
+ def clone_pool
397
+ super
398
+ end
399
+
400
+ # Gets the lists of rules the specified virtual servers are associated with.
401
+ # If a specified virtual server is not associated with any rule, then the list
402
+ # of rules for that virtual server will be empty
403
+ def rules
404
+ @rules ||= RuleEnumerator.new( get_rule.sort {|a,b| a.priority.to_i <=> b.priority.to_i}.map{|i| i}.compact,self)
405
+ end
406
+
407
+ # Gets the statistics.
408
+ def statistics
409
+ get_statistics.statistics
410
+ end
411
+
412
+ # Gets the version information for this interface.
413
+ def version
414
+ super
415
+ end
416
+
417
+ def gtm_score
418
+ super
419
+ end
420
+
421
+ def persistence_profile=(persistence_profile)
422
+ add_persistence_profile(persistence_profile)
423
+ end
424
+
425
+ def add_persistence_profile(persistence_profile)
426
+ IControl::LocalLB::VirtualServer.add_persistence_profile do |soap|
427
+ soap.body = {
428
+ "virtual_servers" => {:item => id},
429
+ "profiles" => {:item => {:item => {"profile_name" => persistence_profile.profile_name,"default_profile" => persistence_profile.default_profile}}}
430
+ }
431
+ end if persistence_profile && persistence_profile!= ""
432
+ end
433
+
434
+ def rules=(my_rules)
435
+ @rules = my_rules
436
+ @rules.parent = self
437
+ @rules.save!
438
+ end
439
+
440
+ def httpclass_profiles
441
+ @httpclass_profile ||= HttpClassProfileEnumerator.new( httpclass_profile.sort {|a,b| a.priority.to_i <=> b.priority.to_i}.map{|i| i}.compact,self)
442
+ end
443
+
444
+ def httpclass_profiles=(profiles)
445
+ @httpclass_profile = profiles
446
+ @httpclass_profile.parent = self
447
+ @httpclass_profile.save!
448
+ end
449
+
450
+ # Adds/associates HTTP class profiles to the specified virtual server.
451
+ def add_httpclass_profile(http_class_profiles)
452
+ IControl::LocalLB::VirtualServer.add_httpclass_profile do |soap|
453
+ item = "item"; count = 0
454
+ profiles = {}
455
+ http_class_profiles.each{ |i| profiles[item + (count +=1).to_s] = {"profile_name" => i.class == String ? i : i.id, "priority" => count } }
456
+ soap.body = {
457
+ "virtual_servers" => {:item => id},
458
+ "profiles" => {"value" => profiles }
459
+ }
460
+ end
461
+ end
462
+
463
+
464
+ def add_rule(rules)
465
+ IControl::LocalLB::VirtualServer.add_rule do |soap|
466
+ item = "item"; count = 0
467
+ my_rules = {}
468
+ rules.each{ |i| my_rules[item + (count +=1).to_s] = {"rule_name" => i.class == String ? i : i.id, "priority" => count } }
469
+ soap.body = {
470
+ "virtual_servers" => {:item => id},
471
+ "rules" => {"value" => my_rules }
472
+ }
473
+ end
474
+ end
475
+
476
+ def add_authentication_profile(profiles)
477
+ IControl::LocalLB::VirtualServer.add_authentication_profile do |soap|
478
+ item = "item"; count = 0
479
+ my_profiles = {}
480
+ profiles.each{ |i| my_profiles[item + (count +=1).to_s] = {"profile_name" => i.class == String ? i : i.id, "priority" => count } }
481
+ soap.body = {
482
+ "virtual_servers" => {:item => id},
483
+ "profiles" => {"value" => my_profiles }
484
+ }
485
+ end
486
+ end
487
+
488
+ # add_authentication_profile
489
+ # remove_authentication_profile
490
+ # remove_all_authentication_profiles
491
+
492
+ def object_status
493
+ super
494
+ end
495
+
496
+ def authentication_profiles
497
+ @authentication_profile ||= AuthProfileEnumerator.new(authentication_profile.sort {|a,b| a.priority.to_i <=> b.priority.to_i}.map{|i| i}.compact,self)
498
+ end
499
+
500
+ def authentication_profiles=(profiles)
501
+ @authentication_profile = profiles
502
+ @authentication_profile.parent = self
503
+ @authentication_profile.save!
504
+ end
505
+
506
+ def self.all_statistics
507
+ self.get_all_statistics
508
+ end
509
+
510
+ def persistence_record(mode)
511
+ raise "Not Implemented"
512
+ end
513
+
514
+ def version
515
+ super
516
+ end
517
+
518
+ def module_score
519
+ super
520
+ end
521
+
522
+ # Sets the protocol it reeives a ProtocolType constant
523
+ def protocol=(protocol)
524
+ IControl::LocalLB::VirtualServer.set_protocol do |soap|
525
+ soap.body = {
526
+ "virtual_servers" => {:item => id},
527
+ "protocols" => {:item => protocol.class_name }
528
+ }
529
+ end
530
+ end
531
+
532
+ def enable_address_translation!
533
+ translate_address_state = IControl::Common::EnabledState::STATE_ENABLED
534
+ end
535
+
536
+ def disable_address_translation!
537
+ translate_address_state = IControl::Common::EnabledState::STATE_DISABLED
538
+ end
539
+
540
+ # Sets the translate address state receives a EnabledState constant
541
+ def translate_address_state=(translate_address_state)
542
+ IControl::LocalLB::VirtualServer.set_translate_address_state do |soap|
543
+ soap.body = {
544
+ "virtual_servers" => {:item => id},
545
+ "states" => {:item => translate_address_state}
546
+ }
547
+ end
548
+ end
549
+
550
+ def enable_cmp!
551
+ cmp_enabled_state = IControl::Common::EnabledState::STATE_ENABLED
552
+ end
553
+
554
+ def disable_cmp!
555
+ cmp_enabled_state = IControl::Common::EnabledState::STATE_DISABLED
556
+ end
557
+
558
+ # Sets the translate cmp address state receives a EnabledState constant
559
+ def cmp_enabled_state=(cmp_enabled_state)
560
+ IControl::LocalLB::VirtualServer.set_cmp_enabled_state do |soap|
561
+ soap.body = {
562
+ "virtual_servers" => {:item => id},
563
+ "states" => {:item => cmp_enabled_state}
564
+ }
565
+ end
566
+ end
567
+
568
+ # sets the snat_pool receives a Pool instance
569
+ def snat_pool=(snat_pool)
570
+ IControl::LocalLB::VirtualServer.set_snat_pool do |soap|
571
+ soap.body = {
572
+ "virtual_servers" => {:item => id},
573
+ "snatpools" => {:item => snat_pool.id}
574
+ }
575
+ end
576
+ end
577
+
578
+ def destroy
579
+ IControl::LocalLB::VirtualServer.delete_virtual_server do |soap|
580
+ soap.body = {
581
+ "virtual_servers" => {:item => id}
582
+ }
583
+ end
584
+ end
585
+
586
+ def self.destroy_all
587
+ puts "NOT IMPLEMENTED (for security reasons)"
588
+ end
589
+
590
+ def vlan=(vlan)
591
+ puts "NOT IMPLEMENTED"
592
+ raise LocalLB::MethodNotImplementedException
593
+ end
594
+
595
+ =begin
596
+ add_profile
597
+ remove_profile
598
+ remove_all_profiles
599
+ remove_persistence_profile
600
+
601
+
602
+ add_clone_pool
603
+ remove_clone_pool
604
+ remove_all_clone_pools
605
+
606
+ + reset_statistics
607
+ delete_persistence_record
608
+ remove_httpclass_profile
609
+ set_gtm_score
610
+ =end
611
+ end