Class: PoolService

Inherits:
Object
  • Object
show all
Defined in:
lib/api/pool/PoolService.rb

Overview

PoolService

This class provides a facade for SOAP method calls to the ZXTM Pool web service.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint = nil, username = nil, password = nil) ⇒ PoolService

Returns a new instance of PoolService.



11
12
13
14
15
# File 'lib/api/pool/PoolService.rb', line 11

def initialize(endpoint=nil, username=nil, password=nil)
  @driver = PoolPort.new(endpoint)
  @driver.options["protocol.http.ssl_config.verify_mode"] = OpenSSL::SSL::VERIFY_NONE
  @driver.options["protocol.http.basic_auth"] << [endpoint, username, password]
end

Instance Attribute Details

#driverObject

Returns the value of attribute driver.



9
10
11
# File 'lib/api/pool/PoolService.rb', line 9

def driver
  @driver
end

Instance Method Details

#add_node(name, node) ⇒ Object

Adds a node to a pool

Args

name (String)     - Pool name
node (String)     - Node ("host:port")

Examples

add_node("pool", "host:80") - Returns nodes for pool "name"


137
138
139
# File 'lib/api/pool/PoolService.rb', line 137

def add_node(name, node)
  @driver.addNodes([name], [[node]])
end

#add_nodes(name, nodes) ⇒ Object

Adds nodes to a pool

Args

name (String)     - Pool name
nodes (Array)     - Nodes (["host1:port", "host2:port"])

Examples

add_nodes("pool",["host1:80", "host2:80"])


150
151
152
# File 'lib/api/pool/PoolService.rb', line 150

def add_nodes(name, nodes)
  @driver.addNodes([name], [nodes])
end

#connection_count(node) ⇒ Object

Return current connection count for node

Args

name (String)     - Pool name
nodes (Array)     - Nodes (["host1:port", "host2:port"])

Examples

remove_draining_nodes("pool",["host1:80", "host2:80"])


241
242
243
# File 'lib/api/pool/PoolService.rb', line 241

def connection_count(node)
  @driver.getNodesConnectionCounts([node])
end

#copy(name, new_name) ⇒ Object

Copies a pool

Args

name (String)       - Name of current pool
new_name (String)   - Name of new pool

Examples

copy(name, new_name)  - Copies pool called "name" to a new pool, called "new_name"


56
57
58
# File 'lib/api/pool/PoolService.rb', line 56

def copy(name, new_name)
  @driver.copyPool([name], [new_name])
end

#create(name = nil, nodes = []) ⇒ Object

Creates new pool

Args

name (String)          - Pool's name
vs_info (Array)        - Pool's nodes

Examples

create("web-pool", ["10.0.0.2", "10.0.0.3"])  - Creates new pool called "web-pool" with 2 nodes


43
44
45
# File 'lib/api/pool/PoolService.rb', line 43

def create(name=nil, nodes=[])
  @driver.addPool([name], [nodes])
end

#delete(name) ⇒ Object

Deletes a pool

Args

name (String)       - Name of pool

Examples

delete(name)        - Deletes pool called "name"


81
82
83
# File 'lib/api/pool/PoolService.rb', line 81

def delete(name)
  @driver.deletePool([name])
end

#drain_node(name, node) ⇒ Object

Mark a node as draining

Args

name (String)     - Pool name
node (String)     - Node ("host:port")

Examples

add_draining_node("pool", "host:80")


189
190
191
# File 'lib/api/pool/PoolService.rb', line 189

def drain_node(name, node)
  @driver.addDrainingNodes([name], [[node]])
end

#drain_nodes(name, nodes) ⇒ Object

Mark nodes as draining

Args

name (String)     - Pool name
nodes (Array)     - Nodes (["host1:port", "host2:port"])

Examples

add_draining_nodes("pool",["host1:80", "host2:80"])


202
203
204
# File 'lib/api/pool/PoolService.rb', line 202

def drain_nodes(name, nodes)
  @driver.addDrainingNodes([name], [nodes])
end

#failure_pool(name, failure_name = nil) ⇒ Object

Sets or return failure pool for pool

Args

name (String)     - Pool name
nodes (Array)     - Nodes (["host1:port", "host2:port"])

Examples

failure_pool("test", "failure_pool")
failure_pool("test") - Returns


95
96
97
98
99
100
101
# File 'lib/api/pool/PoolService.rb', line 95

def failure_pool(name, failure_name=nil)
  if failure_name.nil?
    @driver.getFailurePool([name])
  else
    @driver.setFailurePool([name],[failure_name])
  end
end

#listObject

Returns a list of pool names

Args

N/A

Examples

list()   - Returns all pool names


25
26
27
28
29
30
31
32
# File 'lib/api/pool/PoolService.rb', line 25

def list()
  result = []
  pools = @driver.getPoolNames
  pools.length.times do |i|
    result << pools[i]
  end
  return result
end

#list_nodes(name, status = nil) ⇒ Object

Returns a list of nodes within a pool

Args

name (String)     - Pool name

Examples

list_nodes(name)   - Returns nodes for pool "name"


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/api/pool/PoolService.rb', line 112

def list_nodes(name, status=nil)
  result = []
  valid_status = [:all, :draining]
  status = :all if status.nil? or !valid_status.include?(status)
  
  case status
  when :all
    result = @driver.getNodes([name])
  when :draining
    result = @driver.getDrainingNodes([name])
  end

  return result
  
end

#remove_node(name, node) ⇒ Object

Removes a node from a pool

Args

name (String)     - Pool name
node (String)     - Node ("host:port")

Examples

remove_node("pool", "host:80")


163
164
165
# File 'lib/api/pool/PoolService.rb', line 163

def remove_node(name, node)
  @driver.removeNodes([name], [[node]])
end

#remove_nodes(name, nodes) ⇒ Object

Removes nodes to a pool

Args

name (String)     - Pool name
nodes (Array)     - Nodes (["host1:port", "host2:port"])

Examples

remove_nodes("pool",["host1:80", "host2:80"])


176
177
178
# File 'lib/api/pool/PoolService.rb', line 176

def remove_nodes(name, nodes)
  @driver.removeNodes([name], [nodes])
end

#rename(name, new_name) ⇒ Object

Renames a pool

Args

name (String)       - Current name of pool
new_name (String)   - New name of pool

Examples

rename(name, new_name)  - Renames pool "name" to "new_name"


69
70
71
# File 'lib/api/pool/PoolService.rb', line 69

def rename(name, new_name)
  @driver.renamePool([name], [new_name])
end

#undrain_node(name, node) ⇒ Object

Mark a draining node as active

Args

name (String)     - Pool name
node (String)     - Node ("host:port")

Examples

undrain_node("pool", "host:80")


215
216
217
# File 'lib/api/pool/PoolService.rb', line 215

def undrain_node(name, node)
  @driver.removeDrainingNodes([name], [[node]])
end

#undrain_nodes(name, nodes) ⇒ Object

Mark draining nodes as active

Args

name (String)     - Pool name
nodes (Array)     - Nodes (["host1:port", "host2:port"])

Examples

undrain_nodes("pool",["host1:80", "host2:80"])


228
229
230
# File 'lib/api/pool/PoolService.rb', line 228

def undrain_nodes(name, nodes)
  @driver.removeDrainingNodes([name], [nodes])
end