haproxy_manager 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/haproxy_manager/instance.rb +15 -3
- data/lib/haproxy_manager/version.rb +1 -1
- data/spec/instance_spec.rb +20 -8
- metadata +3 -3
@@ -10,10 +10,10 @@ module HAProxyManager
|
|
10
10
|
|
11
11
|
# Diables a server in the server in a backend for maintenance.
|
12
12
|
# If backend is not specified then all the backends in which the serverid exists are disabled.
|
13
|
-
|
13
|
+
# A disabled server shows up as in Maintance mode.
|
14
14
|
def disable(serverid, backend = nil)
|
15
15
|
all_servers(serverid, backend).each do |item|
|
16
|
-
@socket.
|
16
|
+
@socket.execute "disable server #{item[0]}/#{item[1]}", &@print_response
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -21,7 +21,7 @@ module HAProxyManager
|
|
21
21
|
# If backend is not specified then all the backends in which the serverid exists are enabled.
|
22
22
|
def enable(serverid, backend = nil)
|
23
23
|
all_servers(serverid, backend).each do |item|
|
24
|
-
@socket.
|
24
|
+
@socket.execute "enable server #{item[0]}/#{item[1]}", &@print_response
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -29,9 +29,21 @@ module HAProxyManager
|
|
29
29
|
@backends.keys
|
30
30
|
end
|
31
31
|
|
32
|
+
def info
|
33
|
+
@socket.execute( "show info").inject({}){|hash, item| x = item.split(":"); hash.merge(x[0].strip => x[1].strip)}
|
34
|
+
end
|
35
|
+
|
32
36
|
def servers(backend = nil)
|
33
37
|
backend.nil? ? @backends.values.flatten : @backends[backend]
|
34
38
|
end
|
39
|
+
|
40
|
+
# resets Haproxy counters. If no option is specified backend and frontend counters are cleared, but
|
41
|
+
# cumulative counters are not cleared. The cumulative counters can be cleared by passing the option of
|
42
|
+
# all to the method, in that case all the counters are cleared. This is similar to a restart.
|
43
|
+
# This is useful to reset stats after for example an incident.
|
44
|
+
def reset_counters(option = "")
|
45
|
+
@socket.execute "clear counters {option}", &@print_response
|
46
|
+
end
|
35
47
|
|
36
48
|
private
|
37
49
|
def all_servers(serverid, backend)
|
data/spec/instance_spec.rb
CHANGED
@@ -9,9 +9,10 @@ module HAProxyManager
|
|
9
9
|
"foo-https-farm,preprod-app,0,0,0,3,60,6219,2577996,71804141,,0,,1,30,3,0,UP,12,1,0,559,137,45394,255774,,1,2,1,,1948,,2,0,,2,L7OK,200,109,0,5912,181,11,29,0,0,,,,501,0,",
|
10
10
|
"foo-https-farm,preprod-bg,0,0,0,0,30,0,0,0,,0,,0,0,0,0,DOWN,5,1,0,4,4,2453494,4518368,,1,2,2,,0,,2,0,,0,L4CON,,0,0,0,0,0,0,0,0,,,,0,0,",
|
11
11
|
"foo-https-farm,preprod-test,0,0,0,0,30,0,0,0,,0,,0,0,0,0,DOWN,5,1,0,0,1,5017532,5017532,,1,2,3,,0,,2,0,,0,L4CON,,0,0,0,0,0,0,0,0,,,,0,0,"]
|
12
|
+
@info_response = ["Name: HAProxy", "Version: 1.5-dev11", "Release_date: 2012/06/04", "Nbproc: 1", "Process_num: 1", "Pid: 4084", "Uptime: 58d 3h50m53s", "Uptime_sec: 5025053", "Memmax_MB: 0", "Ulimit-n: 40029", "Maxsock: 40029", "Maxconn: 20000", "Hard_maxconn: 20000", "Maxpipes: 0", "CurrConns: 0", "PipesUsed: 0", "PipesFree: 0", "ConnRate: 0", "ConnRateLimit: 0", "MaxConnRate: 69", "Tasks: 10", "Run_queue: 1", "Idle_pct: 100", "node: some machine on ec3", "description: Our awesome load balancer"]
|
12
13
|
end
|
13
14
|
before(:each) do
|
14
|
-
HAPSocket.any_instance.expects(:execute).returns(@stat_response)
|
15
|
+
HAPSocket.any_instance.expects(:execute).once.returns(@stat_response)
|
15
16
|
@instance = Instance.new("foo")
|
16
17
|
end
|
17
18
|
|
@@ -32,28 +33,39 @@ module HAProxyManager
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
describe "enables servers" do
|
36
|
+
describe "enables/disables servers" do
|
36
37
|
it "enables a server" do
|
37
|
-
HAPSocket.any_instance.expects(:
|
38
|
+
HAPSocket.any_instance.expects(:execute).with('enable server foo-farm/preprod-bg')
|
38
39
|
@instance.enable("preprod-bg", "foo-farm")
|
39
40
|
end
|
40
41
|
|
41
42
|
it "enables a all servers in multiple backends" do
|
42
|
-
HAPSocket.any_instance.expects(:
|
43
|
-
HAPSocket.any_instance.expects(:
|
43
|
+
HAPSocket.any_instance.expects(:execute).with('enable server foo-farm/preprod-bg')
|
44
|
+
HAPSocket.any_instance.expects(:execute).with('enable server foo-https-farm/preprod-bg')
|
44
45
|
@instance.enable("preprod-bg")
|
45
46
|
end
|
46
47
|
|
47
48
|
it "disables a server" do
|
48
|
-
HAPSocket.any_instance.expects(:
|
49
|
+
HAPSocket.any_instance.expects(:execute).with('disable server foo-farm/preprod-bg')
|
49
50
|
@instance.disable("preprod-bg", "foo-farm")
|
50
51
|
end
|
51
52
|
|
52
53
|
it "disables a server in all backends" do
|
53
|
-
HAPSocket.any_instance.expects(:
|
54
|
-
HAPSocket.any_instance.expects(:
|
54
|
+
HAPSocket.any_instance.expects(:execute).with('disable server foo-farm/preprod-bg')
|
55
|
+
HAPSocket.any_instance.expects(:execute).with('disable server foo-https-farm/preprod-bg')
|
55
56
|
@instance.disable("preprod-bg")
|
56
57
|
end
|
57
58
|
end
|
59
|
+
|
60
|
+
describe "info about haproxy" do
|
61
|
+
it "has description/version and uptime" do
|
62
|
+
HAPSocket.any_instance.expects(:execute).with("show info").returns(@info_response)
|
63
|
+
|
64
|
+
info = @instance.info
|
65
|
+
info["description"].should == 'Our awesome load balancer'
|
66
|
+
info["Version"].should == '1.5-dev11'
|
67
|
+
info["Uptime"].should == '58d 3h50m53s'
|
68
|
+
end
|
69
|
+
end
|
58
70
|
end
|
59
71
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haproxy_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -124,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
segments:
|
126
126
|
- 0
|
127
|
-
hash:
|
127
|
+
hash: -4440927357192594363
|
128
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
129
|
none: false
|
130
130
|
requirements:
|
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
133
|
version: '0'
|
134
134
|
segments:
|
135
135
|
- 0
|
136
|
-
hash:
|
136
|
+
hash: -4440927357192594363
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project: haproxy_manager
|
139
139
|
rubygems_version: 1.8.24
|