halb 0.4.0 → 0.5.0
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.
- checksums.yaml +7 -0
- data/lib/halb.rb +3 -1
- data/lib/halb/abstract_load_balancer.rb +43 -0
- data/lib/halb/ha_proxy.rb +36 -0
- data/lib/halb/load_balancer.rb +8 -36
- metadata +39 -27
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b634f023dedc0bea8e7800ee6dfe6db62eca5a77
|
4
|
+
data.tar.gz: 8eccaeb06b0ccc9e4268fe696eac390797272b88
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a7eb04b4562fd23917938ab58e475953d4527c1bc39fbd8257f1c59acf7610e4d75e2fdb9e08e602f083135255ee3897883fae76a473a921874de23bb610c35
|
7
|
+
data.tar.gz: 70dc745da7e276dd49f0ff79ab4e7744923e943c4ae50c13e95586b99c1a9d9627ddb501873fb44f583fc8a068e943c2061a1521e8f115d61cc7e9b470f022a7
|
data/lib/halb.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
|
3
|
+
module Halb
|
4
|
+
class AbstractLoadBalancer
|
5
|
+
def initialize(host, user, ssh_keys)
|
6
|
+
@host, @user, @ssh_keys = host, user, ssh_keys
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_output_of(host=@host, command)
|
10
|
+
output=''
|
11
|
+
open_connection(host) do |ssh|
|
12
|
+
output=ssh.exec!(command)
|
13
|
+
end
|
14
|
+
output
|
15
|
+
end
|
16
|
+
|
17
|
+
def put_in_maintenance(machine)
|
18
|
+
service_endpoint=service_endpoint_for(machine)
|
19
|
+
perform(:command => in_maintenance_command(service_endpoint),
|
20
|
+
:exit_when => lambda { |ssh| !ssh.exec!(show_active_hosts_command).to_s.include?(service_endpoint) })
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove_from_maintenance(host)
|
24
|
+
service_endpoint = service_endpoint_for(host)
|
25
|
+
perform(:command => out_of_maintenance_command(service_endpoint),
|
26
|
+
:exit_when => lambda { |ssh| ssh.exec!(show_active_hosts_command).to_s.include?(service_endpoint) })
|
27
|
+
end
|
28
|
+
|
29
|
+
def perform(params)
|
30
|
+
open_connection do |ssh|
|
31
|
+
ssh.exec!(params[:command])
|
32
|
+
loop do
|
33
|
+
break if params[:exit_when].call(ssh)
|
34
|
+
sleep(1)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def open_connection(host=@host, &block)
|
40
|
+
Net::SSH.start(host, @user, :keys => @ssh_keys, &block)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Halb
|
2
|
+
class HAProxy < AbstractLoadBalancer
|
3
|
+
def initialize(host, user, ssh_keys, cluster_ip, proxy_names)
|
4
|
+
super(host, user, ssh_keys)
|
5
|
+
@cluster_ip, @proxy_names = cluster_ip, proxy_names
|
6
|
+
end
|
7
|
+
|
8
|
+
def show_active_hosts_command
|
9
|
+
proxy_names_expression = @proxy_names.join('|')
|
10
|
+
"echo 'show stat -1' | socat stdio /tmp/haproxy.sock | grep -P '(#{proxy_names_expression}).*,UP'"
|
11
|
+
end
|
12
|
+
|
13
|
+
def active?
|
14
|
+
get_output_of(@cluster_ip, 'hostname').strip == @host
|
15
|
+
end
|
16
|
+
|
17
|
+
def in_maintenance_command(machine)
|
18
|
+
maintenance_command_for(machine, 'disable')
|
19
|
+
end
|
20
|
+
|
21
|
+
def out_of_maintenance_command(machine)
|
22
|
+
maintenance_command_for(machine, 'enable')
|
23
|
+
end
|
24
|
+
|
25
|
+
def maintenance_command_for(machine, operation)
|
26
|
+
commands = @proxy_names.map do |proxy_name|
|
27
|
+
"#{operation} server #{proxy_name}/#{machine}"
|
28
|
+
end
|
29
|
+
"echo \"#{commands.join(' ; ')}\" | socat stdio /tmp/haproxy.sock"
|
30
|
+
end
|
31
|
+
|
32
|
+
def service_endpoint_for(machine)
|
33
|
+
machine
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/halb/load_balancer.rb
CHANGED
@@ -1,51 +1,23 @@
|
|
1
|
-
require 'net/ssh'
|
2
|
-
|
3
1
|
module Halb
|
4
|
-
class LoadBalancer
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(host, user, ssh_keys)
|
8
|
-
@host, @user, @ssh_keys = host, user, ssh_keys
|
2
|
+
class LoadBalancer < AbstractLoadBalancer
|
3
|
+
def show_active_hosts_command
|
4
|
+
'ipvsadm -l -n'
|
9
5
|
end
|
10
6
|
|
11
7
|
def active?
|
12
|
-
!/TCP[ ]+\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}/.match(get_output_of(
|
13
|
-
end
|
14
|
-
|
15
|
-
def get_output_of(command)
|
16
|
-
output=''
|
17
|
-
open_connection do |ssh|
|
18
|
-
output=ssh.exec!(command)
|
19
|
-
end
|
20
|
-
output
|
8
|
+
!/TCP[ ]+\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}/.match(get_output_of(show_active_hosts_command)).nil?
|
21
9
|
end
|
22
10
|
|
23
|
-
def
|
24
|
-
service_endpoint
|
25
|
-
perform(:command => "touch /etc/ha.d/maintenance/#{service_endpoint}", :exit_when => lambda { |ssh| !ssh.exec!(SHOW_ACTIVE_HOSTS_COMMAND).include?(service_endpoint) })
|
11
|
+
def in_maintenance_command(service_endpoint)
|
12
|
+
"touch /etc/ha.d/maintenance/#{service_endpoint}"
|
26
13
|
end
|
27
14
|
|
28
|
-
def
|
29
|
-
service_endpoint
|
30
|
-
perform(:command => "rm /etc/ha.d/maintenance/#{service_endpoint}", :exit_when => lambda { |ssh| ssh.exec!(SHOW_ACTIVE_HOSTS_COMMAND).include?(service_endpoint) })
|
15
|
+
def out_of_maintenance_command(service_endpoint)
|
16
|
+
"rm /etc/ha.d/maintenance/#{service_endpoint}"
|
31
17
|
end
|
32
18
|
|
33
19
|
def service_endpoint_for(ip_address)
|
34
20
|
"#{ip_address}:80"
|
35
21
|
end
|
36
|
-
|
37
|
-
def perform(params)
|
38
|
-
open_connection do |ssh|
|
39
|
-
ssh.exec!(params[:command])
|
40
|
-
loop do
|
41
|
-
break if params[:exit_when].call(ssh)
|
42
|
-
sleep(1)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def open_connection(&block)
|
48
|
-
Net::SSH.start(@host, @user, :keys => @ssh_keys, &block)
|
49
|
-
end
|
50
22
|
end
|
51
23
|
end
|
metadata
CHANGED
@@ -1,91 +1,103 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: halb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- TeamIguana
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-04-17 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: net-ssh
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: mocha
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - ">="
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '0'
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: test-unit
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - ">="
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
type: :development
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
58
69
|
description:
|
59
70
|
email:
|
60
71
|
executables: []
|
61
72
|
extensions: []
|
62
73
|
extra_rdoc_files: []
|
63
74
|
files:
|
75
|
+
- lib/halb.rb
|
76
|
+
- lib/halb/abstract_load_balancer.rb
|
64
77
|
- lib/halb/deploy.rb
|
78
|
+
- lib/halb/ha_proxy.rb
|
65
79
|
- lib/halb/load_balancer.rb
|
66
|
-
- lib/halb.rb
|
67
80
|
homepage: https://github.com/TeamIguana/halb
|
68
81
|
licenses: []
|
82
|
+
metadata: {}
|
69
83
|
post_install_message:
|
70
84
|
rdoc_options: []
|
71
85
|
require_paths:
|
72
86
|
- lib
|
73
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
88
|
requirements:
|
76
|
-
- -
|
89
|
+
- - ">="
|
77
90
|
- !ruby/object:Gem::Version
|
78
91
|
version: '0'
|
79
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
93
|
requirements:
|
82
|
-
- -
|
94
|
+
- - ">="
|
83
95
|
- !ruby/object:Gem::Version
|
84
96
|
version: '0'
|
85
97
|
requirements: []
|
86
98
|
rubyforge_project:
|
87
|
-
rubygems_version:
|
99
|
+
rubygems_version: 2.2.1
|
88
100
|
signing_key:
|
89
|
-
specification_version:
|
90
|
-
summary: Manage deploys behind HA.D/LDirector/LVS Load Balancers
|
101
|
+
specification_version: 4
|
102
|
+
summary: Manage deploys behind HA.D/LDirector/LVS/HAProxy Load Balancers
|
91
103
|
test_files: []
|