exazk 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +35 -0
- data/exazk.gemspec +17 -0
- data/lib/exazk.rb +57 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d5b2fe8898f276ea675160a7ee638d738ed0309c
|
4
|
+
data.tar.gz: f2fe7cc09d850688203a6877419b16cb5bd278b2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 91996e8ed29abcc364e786190ed4bb0f3bf189b7cf0ada1f6e0e10c76ab4649fe0672916e3955e722b651a04e1c67d01a2382c7ec303ddcd8474dd21d8406b79
|
7
|
+
data.tar.gz: 133b16825f33acd54a391247d55aad47a33e99d0535ca155d2ddd2bc551acc4b303e9840589b9b17b5309120785436777da89377ee8b7f5bbfedbf197059ac95
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
## Workflow
|
2
|
+
* ExaBGP forks new process (exazk.rb);
|
3
|
+
* exazk.rb is trying to acquire mutex on ZK:
|
4
|
+
* on success - announce routes and write some information to ZK about master node;
|
5
|
+
* on failure - withdraw routes and spin around trying to acquire mutex once again.
|
6
|
+
|
7
|
+
![](http://donatas.net/exazk.png)
|
8
|
+
|
9
|
+
## Requirements
|
10
|
+
* Zookeeper
|
11
|
+
* ExaBGP
|
12
|
+
* Ruby
|
13
|
+
* zk rubygem
|
14
|
+
|
15
|
+
## Install
|
16
|
+
* gem install exazk
|
17
|
+
|
18
|
+
## Recommendations
|
19
|
+
* set `minSessionTimeout` or `tickTime` (zookeeper) as low as you can, to have faster convergence.
|
20
|
+
|
21
|
+
## Configuration example
|
22
|
+
```
|
23
|
+
neighbor 10.0.0.1 {
|
24
|
+
router-id 10.0.0.2;
|
25
|
+
local-address 10.0.0.2;
|
26
|
+
local-as 65501;
|
27
|
+
peer-as 65501;
|
28
|
+
hold-time 5;
|
29
|
+
|
30
|
+
process announce-routes {
|
31
|
+
run /etc/exabgp/exazk.rb;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
```
|
35
|
+
|
data/exazk.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'exazk'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2016-10-18'
|
5
|
+
s.summary = 'ExaZK'
|
6
|
+
s.description = 'ExaZK is simple L3 high availability plugin for ExaBGP'
|
7
|
+
s.authors = ['Donatas Abraitis']
|
8
|
+
s.email = 'donatas.abraitis@gmail.com'
|
9
|
+
s.files = ['README.md', 'exazk.gemspec', 'lib/exazk.rb']
|
10
|
+
# s.add_development_dependency 'zk', '~> 1.9', '>= 1.9.0'
|
11
|
+
# s.add_development_dependency 'json', '~> 2.0', '>= 2.0.0'
|
12
|
+
s.add_runtime_dependency 'zk'
|
13
|
+
s.add_runtime_dependency 'json'
|
14
|
+
s.homepage =
|
15
|
+
'http://rubygems.org/gems/exazk'
|
16
|
+
s.license = 'MIT'
|
17
|
+
end
|
data/lib/exazk.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'zk'
|
2
|
+
require 'socket'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class ExaZK
|
6
|
+
def initialize(mutex, zk_string, routes, data)
|
7
|
+
@mutex = mutex
|
8
|
+
@zk_string = zk_string
|
9
|
+
@routes = routes
|
10
|
+
@data = {
|
11
|
+
hostname: Socket.gethostname,
|
12
|
+
data: data
|
13
|
+
}.to_json
|
14
|
+
@zk = ZK.new(@zk_string)
|
15
|
+
end
|
16
|
+
|
17
|
+
def send_update(route)
|
18
|
+
$stdout.write route
|
19
|
+
$stdout.flush
|
20
|
+
end
|
21
|
+
|
22
|
+
def withdraw_routes
|
23
|
+
@routes.map do |route|
|
24
|
+
route % 'withdraw'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def announce_routes
|
29
|
+
@routes.map do |route|
|
30
|
+
route % 'announce'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def mutex_exists?
|
35
|
+
if @zk.exists?(@mutex)
|
36
|
+
data = JSON.parse(@zk.get(@mutex).first)
|
37
|
+
return true if data['hostname'] == Socket.gethostname
|
38
|
+
else
|
39
|
+
begin
|
40
|
+
@zk.create(@mutex, "#{@data}", :ephemeral => true)
|
41
|
+
return true
|
42
|
+
rescue ZK::Exceptions::NodeExists
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def main_loop
|
49
|
+
withdraw_routes.each do |route|
|
50
|
+
send_update(route)
|
51
|
+
end unless mutex_exists?
|
52
|
+
|
53
|
+
announce_routes.each do |route|
|
54
|
+
send_update(route)
|
55
|
+
end if mutex_exists?
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: exazk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Donatas Abraitis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: zk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: ExaZK is simple L3 high availability plugin for ExaBGP
|
42
|
+
email: donatas.abraitis@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- README.md
|
48
|
+
- exazk.gemspec
|
49
|
+
- lib/exazk.rb
|
50
|
+
homepage: http://rubygems.org/gems/exazk
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 2.2.2
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: ExaZK
|
74
|
+
test_files: []
|