clusterlb 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2de6ba2cde0d88abe2a7599960d6d2d842a690ab
4
+ data.tar.gz: 0572fbaeb8b990cbcb90f7ea08193b5f9c26cd1d
5
+ SHA512:
6
+ metadata.gz: 70b103bbcf407c76b127097910a1b1971c7013af2f31deb1ea81281d0923bccf05e723288ac122f61db71f06e7de62baf510481c884ef09f5f4ef7d862dc9705
7
+ data.tar.gz: 2f86021696c4035e71126d382edffbe04bd1d59ecdbdcdc7c55c764efa597cbf93d61ade052bfc38fef692d100cc8c8621ed303cc260e36c27293242c126bedc
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /test/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in clusterlb.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ clusterlb (0.1.0)
5
+ colorize (~> 0.8.1)
6
+ console_table (~> 0.3.0)
7
+ fileutils (~> 1.2, >= 1.2.0)
8
+ json (~> 2.2, >= 2.2.0)
9
+ openssl (~> 2.1, >= 2.1.2)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ colorize (0.8.1)
15
+ console_table (0.3.0)
16
+ ruby-terminfo (~> 0.1)
17
+ fileutils (1.2.0)
18
+ json (2.2.0)
19
+ openssl (2.1.2)
20
+ rake (10.5.0)
21
+ ruby-terminfo (0.1.1)
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ bundler (~> 1.16)
28
+ clusterlb!
29
+ rake (~> 10.0)
30
+
31
+ BUNDLED WITH
32
+ 1.16.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Dr. Ogg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Clusterlb
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/clusterlb`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'clusterlb'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install clusterlb
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/clusterlb.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "clusterlb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/clusterlb.gemspec ADDED
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "clusterlb/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "clusterlb"
8
+ spec.version = Clusterlb::VERSION
9
+ spec.authors = ["Dr. Ogg"]
10
+ spec.email = ["ogg@sr375.com"]
11
+
12
+ spec.summary = "Simple tools to manage a group of nginx lb's"
13
+ spec.description = "Simple tools to manage a group of nginx lb's with shared nfs configs"
14
+ spec.license = "MIT"
15
+
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
18
+ else
19
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
20
+ end
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.16"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_dependency 'colorize', '~> 0.8.1'
34
+ spec.add_dependency 'console_table', '~> 0.3.0'
35
+ spec.add_dependency 'fileutils', '~> 1.2', '>= 1.2.0'
36
+ spec.add_dependency 'json', '~> 2.2', '>= 2.2.0'
37
+ spec.add_dependency 'openssl', '~> 2.1', '>= 2.1.2'
38
+ end
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler'
3
+ Bundler.require(:default)
4
+ require 'clusterlb'
5
+ require 'colorize'
6
+ require 'getoptLong'
7
+
8
+ include Clusterlb
9
+
10
+ # puts Clusterlb.config["clusterlb"]["sites"]
11
+
12
+ def display_help
13
+ puts
14
+ puts "Lists/Enables/Disables Sites on specific load balancers"
15
+ puts "VERSION: #{Clusterlb::VERSION}".colorize(:light_blue)
16
+ puts "CONFIG: #{Clusterlb.config_file}".colorize(:light_blue)
17
+ puts "CLUSTERLB_HOME: #{ENV['CLUSTERLB_HOME']}".colorize(:light_blue)
18
+ puts
19
+ puts "Options:"
20
+ puts "-h or --help ".ljust(30) + "-> Display this help message"
21
+ puts "-l or --list".ljust(30) + "-> List LB Nodes"
22
+ puts "-m or --matrix".ljust(30) + "-> Show Matrix of Enabled Sites and Nodes"
23
+ puts "-e or --enable".ljust(30) + "-> Enable Site (used with -n for node)"
24
+ puts "-d or --disable".ljust(30) + "-> Disable Site (used with -n for node)"
25
+ puts "-n or --node".ljust(30) + "-> node to enable or disable site on"
26
+ puts
27
+ exit 1
28
+ end
29
+
30
+
31
+ def parse_cli
32
+ opts = GetoptLong.new(
33
+ ["-h", "--help", GetoptLong::NO_ARGUMENT],
34
+ ["-e", "--enable", GetoptLong::REQUIRED_ARGUMENT],
35
+ ["-n", "--node", GetoptLong::REQUIRED_ARGUMENT],
36
+ ["-d", "--disable", GetoptLong::REQUIRED_ARGUMENT],
37
+ ["-m", "--matrix", GetoptLong::NO_ARGUMENT],
38
+ ["-l", "--list", GetoptLong::NO_ARGUMENT]
39
+ )
40
+
41
+ opts.each do |opt, arg|
42
+ case opt
43
+ when "-h" || "--help"
44
+ display_help; exit
45
+ when "-m" || "--matrix"
46
+ Clusterlb.matrix_list; exit 1
47
+ when "-e" || "--enable"
48
+ @site = arg.strip().downcase(); @mode='enable'
49
+ when "-d" || "--disable"
50
+ @site = arg.strip().downcase(); @mode='disable'
51
+ when "-n" || "--node"
52
+ @node = arg.strip().downcase();
53
+ when "-l" || "--list"
54
+ puts Clusterlb.list_lbs; exit
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+
61
+
62
+ parse_cli
63
+ if @site.nil? || @mode.nil? || @node.nil?
64
+ display_help
65
+ exit 1
66
+ end
67
+
68
+ case @mode
69
+ when "enable"
70
+ Clusterlb.enable_site(@site,@node)
71
+ when "disable"
72
+ Clusterlb.disable_site(@site,@node)
73
+ end
@@ -0,0 +1,3 @@
1
+ module Clusterlb
2
+ VERSION = "0.1.0"
3
+ end
data/lib/clusterlb.rb ADDED
@@ -0,0 +1,120 @@
1
+ require "clusterlb/version"
2
+ require 'bundler'
3
+ require 'json'
4
+ require 'console_table'
5
+ require 'colorize'
6
+ Bundler.require(:default)
7
+
8
+ module Clusterlb
9
+
10
+ class << self
11
+ attr_accessor :config_dir
12
+ attr_accessor :config_file
13
+ end
14
+
15
+ self.config_dir = "#{ENV["CLUSTERLB_HOME"]}/configs"
16
+ self.config_file = "#{self.config_dir}/clusterlb.json"
17
+
18
+ def list_lbs
19
+ ensure_lb_sites_enabled_dir_exitsts
20
+ config["clusterlb"]["lb_nodes"]
21
+ end
22
+
23
+ def config
24
+ envCheck
25
+ writeSampleConfig(config_file) if !File.exists? config_file
26
+ begin
27
+ config = JSON.parse(File.read config_file)
28
+ rescue
29
+ puts "ERROR: Unable to load config file: #{ENV["CLUSTERLB_HOME"]}/configs/clusterlb.json "
30
+ exit 1
31
+ end
32
+ end
33
+
34
+ def enable_site(site,node)
35
+ Dir.chdir ENV["CLUSTERLB_HOME"]
36
+ link_to_dir="#{config["clusterlb"]["sites_enabled"]}/#{node}"
37
+
38
+ if !config["clusterlb"]["lb_nodes"].include? node
39
+ puts "#{node} is not listed as an active loadballancer, check your configs".colorize(:yellow)
40
+ exit 1
41
+ end
42
+
43
+ if !File.directory?(link_to_dir)
44
+ puts "#{link_to_dir} does not exist, check your configs".colorize(:yellow)
45
+ exit 1
46
+ end
47
+
48
+ FileUtils.ln_s "../../#{config["clusterlb"]["sites"]}/#{site}", "#{link_to_dir}/#{site}", force: true
49
+ puts "Enableing Site #{site} on #{node}"
50
+ end
51
+
52
+ def disable_site(site,node)
53
+ Dir.chdir ENV["CLUSTERLB_HOME"]
54
+ link_dir="#{config["clusterlb"]["sites_enabled"]}/#{node}"
55
+ FileUtils.rm("#{link_dir}/#{site}")
56
+ puts "Disableing Site #{site} on #{node}"
57
+ end
58
+
59
+ def matrix_list
60
+ table_config = [{:key=>:site, :size=>30, :title=>"Site"}]
61
+ config["clusterlb"]["lb_nodes"].each do |node|
62
+ table_config.push( {:key=>node.to_sym, :size=>7, :title=>node, :justify=>:center})
63
+ end
64
+ ConsoleTable.define(table_config) do |table|
65
+ Dir.glob("#{ENV["CLUSTERLB_HOME"]}/#{config["clusterlb"]["sites"]}/*").each do |full_path_file|
66
+ filename=full_path_file.split('/')[-1]
67
+ result={:site=>filename}
68
+ config["clusterlb"]["lb_nodes"].each do |node|
69
+ result[node.to_sym]="✓".colorize(:green) if File.exists?("#{ENV["CLUSTERLB_HOME"]}/#{config["clusterlb"]["sites_enabled"]}/#{node}/#{filename}")
70
+ end
71
+ table << result
72
+
73
+ end
74
+ end
75
+ # {
76
+ # :site=>"farts.sfdsdfsdf.sdfsdf",
77
+ # :lb01=>"✓".colorize(:green)
78
+ # }
79
+ end
80
+
81
+ private
82
+
83
+ def ensure_lb_sites_enabled_dir_exitsts
84
+ [
85
+ "#{ENV["CLUSTERLB_HOME"]}/#{config["clusterlb"]["sites_enabled"]}",
86
+ "#{ENV["CLUSTERLB_HOME"]}/#{config["clusterlb"]["sites"]}"
87
+ ].each do |dir_path|
88
+ FileUtils.mkdir dir_path if !File.directory?(dir_path)
89
+ end
90
+ config["clusterlb"]["lb_nodes"].each do |node|
91
+ node_dir="#{ENV["CLUSTERLB_HOME"]}/#{config["clusterlb"]["sites_enabled"]}/#{node}"
92
+ FileUtils.mkdir node_dir if !File.directory?(node_dir)
93
+ end
94
+ end
95
+
96
+ def envCheck
97
+ if ENV["CLUSTERLB_HOME"].nil?
98
+ puts "Please set your ENV 'CLUSTERLB_HOME' to point to the directory where your clusterlb lives"
99
+ exit 1
100
+ end
101
+ end
102
+
103
+ def writeSampleConfig(path)
104
+ FileUtils.mkdir config_dir if !File.directory?(config_dir)
105
+ example_config = {
106
+ :clusterlb => {
107
+ :sites => "sites",
108
+ :sites_enabled => "sites-enabled",
109
+ :lb_nodes => ["lb01","lb02","lb03"],
110
+ :nfs_mount => "/srv/clusterlb"
111
+ }
112
+ }
113
+ File.open(path,"w") do |f|
114
+ f.write(JSON.pretty_generate(example_config))
115
+ end
116
+ end
117
+
118
+
119
+
120
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clusterlb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dr. Ogg
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: console_table
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.3.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: fileutils
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 1.2.0
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '1.2'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 1.2.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: json
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '2.2'
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 2.2.0
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '2.2'
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 2.2.0
109
+ - !ruby/object:Gem::Dependency
110
+ name: openssl
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '2.1'
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 2.1.2
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '2.1'
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 2.1.2
129
+ description: Simple tools to manage a group of nginx lb's with shared nfs configs
130
+ email:
131
+ - ogg@sr375.com
132
+ executables:
133
+ - clusterlb-stectrl
134
+ extensions: []
135
+ extra_rdoc_files: []
136
+ files:
137
+ - ".gitignore"
138
+ - Gemfile
139
+ - Gemfile.lock
140
+ - LICENSE.txt
141
+ - README.md
142
+ - Rakefile
143
+ - bin/console
144
+ - bin/setup
145
+ - clusterlb.gemspec
146
+ - exe/clusterlb-stectrl
147
+ - lib/clusterlb.rb
148
+ - lib/clusterlb/version.rb
149
+ homepage:
150
+ licenses:
151
+ - MIT
152
+ metadata:
153
+ allowed_push_host: https://rubygems.org
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.6.13
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Simple tools to manage a group of nginx lb's
174
+ test_files: []