Class: VirtualServerService
- Inherits:
-
Object
- Object
- VirtualServerService
- Defined in:
- lib/api/virtualserver/VirtualServerService.rb
Overview
VirtualServerService
This class provides a facade for SOAP method calls to the ZXTM Virtual Server web service.
Instance Attribute Summary collapse
-
#driver ⇒ Object
Returns the value of attribute driver.
Instance Method Summary collapse
-
#add_request_rule(vs_name, rule) ⇒ Object
Adds a request rule (and enables it).
-
#add_response_rule(vs_name, rule) ⇒ Object
Adds a response rule (and enables it).
-
#copy(name, new_name) ⇒ Object
Copies a virtual server.
-
#create(name = nil, vs_info = {}) ⇒ Object
Creates new virtual server.
-
#delete(name) ⇒ Object
Deletes a virtual server.
-
#disable(vs_name = nil) ⇒ Object
Disables a virtual server.
-
#enable(vs_name = nil) ⇒ Object
Enables a virtual server.
-
#enabled?(vs_name) ⇒ Boolean
Checks whether the virtual server is enabled.
-
#initialize(endpoint = nil, username = nil, password = nil) ⇒ VirtualServerService
constructor
A new instance of VirtualServerService.
-
#list(status = nil) ⇒ Object
Returns a list of virtual servers.
-
#remove_request_rule(vs_name, rule) ⇒ Object
Removes a request rule.
-
#remove_response_rule(vs_name, rule) ⇒ Object
Removes a response rule.
-
#rename(name, new_name) ⇒ Object
Renames a virtual server.
Constructor Details
#initialize(endpoint = nil, username = nil, password = nil) ⇒ VirtualServerService
Returns a new instance of VirtualServerService.
11 12 13 14 15 |
# File 'lib/api/virtualserver/VirtualServerService.rb', line 11 def initialize(endpoint=nil, username=nil, password=nil) @driver = VirtualServerPort.new(endpoint) @driver.["protocol.http.ssl_config.verify_mode"] = OpenSSL::SSL::VERIFY_NONE @driver.["protocol.http.basic_auth"] << [endpoint, username, password] end |
Instance Attribute Details
#driver ⇒ Object
Returns the value of attribute driver.
9 10 11 |
# File 'lib/api/virtualserver/VirtualServerService.rb', line 9 def driver @driver end |
Instance Method Details
#add_request_rule(vs_name, rule) ⇒ Object
Adds a request rule (and enables it)
Args
name (String) - Virtual server's name
rule (String) - Rule name
Examples
add_request_rule("test", "some-rule")
161 162 163 164 165 166 |
# File 'lib/api/virtualserver/VirtualServerService.rb', line 161 def add_request_rule(vs_name, rule) vsr = VirtualServerRule.new vsr.name = rule vsr.enabled = true @driver.addRules([vs_name],[[vsr]]) end |
#add_response_rule(vs_name, rule) ⇒ Object
Adds a response rule (and enables it)
Args
name (String) - Virtual server's name
rule (String) - Rule name
Examples
add_request_rule("test", "some-rule")
190 191 192 193 194 195 |
# File 'lib/api/virtualserver/VirtualServerService.rb', line 190 def add_response_rule(vs_name, rule) vsr = VirtualServerRule.new vsr.name = rule vsr.enabled = true @driver.addResponseRules([vs_name], [[vsr]]) end |
#copy(name, new_name) ⇒ Object
Copies a virtual server
Args
name (String) - Name of current virtual server
new_name (String) - Name of new virtual server
Examples
copy(name, new_name) - Copies VS called "name" to a new VS called "new_name"
83 84 85 |
# File 'lib/api/virtualserver/VirtualServerService.rb', line 83 def copy(name, new_name) @driver.copyVirtualServer([name], [new_name]) end |
#create(name = nil, vs_info = {}) ⇒ Object
Creates new virtual server
Args
name (String) - Virtual server's name
vs_info (Hash) - Virtual server's properties
Examples
create("web") - Creates new virtual server called "web" with default properties
create("web", {:port => "80", :protocol => "http", :default_pool => "web-pool"})
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/api/virtualserver/VirtualServerService.rb', line 61 def create(name=nil, vs_info={}) default_port = "80" default_protocol = "http" default_pool = "discard" vs_basic_info = VirtualServerBasicInfo.new vs_basic_info.port = vs_info[:port] || default_port vs_basic_info.protocol = vs_info[:protocol] || default_protocol vs_basic_info.default_pool = vs_info[:default_pool] || default_pool @driver.addVirtualServer([name], [vs_basic_info]) end |
#delete(name) ⇒ Object
Deletes a virtual server
Args
name (String) - Name of virtual server
Examples
delete("test") - Deletes virtual server called "test"
108 109 110 |
# File 'lib/api/virtualserver/VirtualServerService.rb', line 108 def delete(name) @driver.deleteVirtualServer([name]) end |
#disable(vs_name = nil) ⇒ Object
Disables a virtual server
Args
name (String) - Virtual server's name to disable
Examples
disable("name") - Disables a virtual server called "name"
132 133 134 |
# File 'lib/api/virtualserver/VirtualServerService.rb', line 132 def disable(vs_name=nil) @driver.setEnabled([vs_name], [false]) end |
#enable(vs_name = nil) ⇒ Object
Enables a virtual server
Args
name (String) - Virtual server's name to enable
Examples
enable("web") - Enables a virtual server called "web"
120 121 122 |
# File 'lib/api/virtualserver/VirtualServerService.rb', line 120 def enable(vs_name=nil) @driver.setEnabled([vs_name], [true]) end |
#enabled?(vs_name) ⇒ Boolean
Checks whether the virtual server is enabled
Args
vs_name (String) - Virtual server's name
Returns
valid (boolean) - True if valid
Examples
enabled?("test") - Checks whether VS "test" is enabled
147 148 149 150 |
# File 'lib/api/virtualserver/VirtualServerService.rb', line 147 def enabled?(vs_name) res = @driver.getEnabled([vs_name]) return res.first end |
#list(status = nil) ⇒ Object
Returns a list of virtual servers
Args
status - Symbol (possible values: :all, :enabled, :disabled)
Examples
names(:all) - Returns all virtual server names (default)
names(:enabled) - Returns enabled virtual server names
names(:disabled) - Returns disabled virtual server names
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/api/virtualserver/VirtualServerService.rb', line 27 def list(status=nil) result = [] valid_status = [:all, :enabled, :disabled] status = :all if status.nil? or !valid_status.include?(status) vs_names = @driver.getVirtualServerNames return vs_names if status == :all enabled_vs = @driver.getEnabled(vs_names) case status when :enabled vs_names.length.times do |i| result << vs_names[i] if enabled_vs[i] end when :disabled vs_names.length.times do |i| result << vs_names[i] unless enabled_vs[i] end end return result end |
#remove_request_rule(vs_name, rule) ⇒ Object
Removes a request rule
Args
name (String) - Virtual server's name
rule (String) - Rule name
Examples
remove_request_rule("test", "some-rule")
177 178 179 |
# File 'lib/api/virtualserver/VirtualServerService.rb', line 177 def remove_request_rule(vs_name, rule) @driver.removeRules([vs_name], [[rule]]) end |
#remove_response_rule(vs_name, rule) ⇒ Object
Removes a response rule
Args
name (String) - Virtual server's name
rule (String) - Rule name
Examples
remove_response_rule("test", "some-rule")
206 207 208 |
# File 'lib/api/virtualserver/VirtualServerService.rb', line 206 def remove_response_rule(vs_name, rule) @driver.removeResponseRules([vs_name], [[rule]]) end |
#rename(name, new_name) ⇒ Object
Renames a virtual server
Args
name (String) - Current name of virtual server
new_name (String) - New name of virtual server
Examples
rename(name, new_name) - Renames VS "name" to "new_name"
96 97 98 |
# File 'lib/api/virtualserver/VirtualServerService.rb', line 96 def rename(name, new_name) @driver.renameVirtualServer([name], [new_name]) end |