cdncontrol 0.0.9 → 0.0.10
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 +8 -8
- data/bin/cdncontrol +114 -89
- data/cdncontrol.gemspec +2 -1
- data/lib/cdncontrol/trafficmanager.rb +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzZjMmE3NzM0NjU1NDc0YjgwMmJjMTQ0MzA3ZTMzOTQyMzM5YTc5Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTk1YTA3ODk1ZTE0YmFkZDhlMjViYzE5ZTEzNTQ2ZDU0NDU2NmFmNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTc1MGI1YTQ1OWY5OTYyNjUzOWY0ZjE4YTQ1MDg4ZGRiODRhZGYwZjIxNTQ2
|
10
|
+
YTc0MmJlNzJlOGExMzEzZWY4N2Y4YzQ1ZTA1OWVjZTdmMjUwOGQwN2I4NGFk
|
11
|
+
MDEyYzA4MjIyOTAxMTA4YzFlMTljZDU0NGMyNzg3ZjBiMjJiMDA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmU3ODJiYmQ3M2Y3Y2JmNmU5NDYzZjUyMzZhZDI4YmUzY2Y5ZGZjNDQ5Y2Q5
|
14
|
+
Y2I5NzUzY2E4ZDkyNGQwMDJkN2NkMWY2ZTQwNTZlZGI4YjU0M2NiYzk4ZWRh
|
15
|
+
MDM0OWQ4MWRjMWFkNGE2MmJmZWNmZWM0NjU4ZjQ2MTBhOTVmNTQ=
|
data/bin/cdncontrol
CHANGED
@@ -1,91 +1,121 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'choice'
|
4
|
-
require 'json'
|
5
4
|
require 'yaml'
|
6
|
-
require 'pp'
|
7
5
|
require 'cdncontrol/trafficmanager'
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
VALID_MODES = CONFIG["valid_modes"] || [ "always", "obey", "remove", "no" ]
|
14
|
-
OUTPUT_PATH = CONFIG["output_path"] || "/tmp"
|
15
|
-
VALID_TARGETS = CONFIG["targets"].keys
|
16
|
-
options = { show: false, add: false, verbose: false }
|
17
|
-
|
18
|
-
Choice.options do
|
19
|
-
header "Please specify the command in one of the following formats:"
|
20
|
-
header ""
|
21
|
-
header "cdncontrol -t TARGET --show"
|
22
|
-
header "cdncontrol -t TARGET --write"
|
23
|
-
header "cdncontrol -t TARGET -p PROVIDER -w WEIGHT"
|
24
|
-
header "cdncontrol -t TARGET -p PROVIDER -m MODE"
|
25
|
-
header ""
|
26
|
-
header "Specific options:"
|
27
|
-
|
28
|
-
option :target, :required => false do
|
29
|
-
short '-t'
|
30
|
-
long '--target'
|
31
|
-
desc "The configuration to work on (one of #{VALID_TARGETS.join(",")})"
|
32
|
-
validate /^(#{VALID_TARGETS.join("|")})$/
|
33
|
-
end
|
34
|
-
|
35
|
-
option :provider, :required => false do
|
36
|
-
short '-p'
|
37
|
-
long '--provider'
|
38
|
-
desc "Provider to modify (one of #{VALID_PROVIDERS.join(",")})"
|
39
|
-
validate /^(#{VALID_PROVIDERS.join("|")})$/
|
40
|
-
end
|
7
|
+
def load_config(conf_file)
|
8
|
+
abort("Config file '#{conf_file}' not found!") unless File.exists? conf_file
|
9
|
+
return YAML.load_file(conf_file)
|
10
|
+
end
|
41
11
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
12
|
+
def validate_option(label, option, valid_options)
|
13
|
+
valid_choices = valid_options.join(', ')
|
14
|
+
return if option.nil?
|
15
|
+
abort "Invalid #{label} '#{option}' - choices are :#{valid_choices}" unless valid_options.include? option
|
16
|
+
end
|
48
17
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
validate /^(#{VALID_MODES.join("|")})$/
|
54
|
-
end
|
18
|
+
def validate_options(config, options)
|
19
|
+
validate_option('provider', options[:provider], config.fetch('valid_providers', []))
|
20
|
+
validate_option('mode', options[:mode], config.fetch('valid_modes', ["always", "obey", "remove", "no"]))
|
21
|
+
validate_option('target', options[:target], config.fetch('targets', {}).keys)
|
55
22
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
23
|
+
unless (options[:show] ||
|
24
|
+
options[:write] ||
|
25
|
+
(options[:provider] && options[:weight]) ||
|
26
|
+
(options[:provider] && options[:mode]))
|
27
|
+
Choice.help
|
60
28
|
end
|
29
|
+
return options
|
30
|
+
end
|
61
31
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
32
|
+
def parse_options
|
33
|
+
Choice.options do
|
34
|
+
header "Please specify the command in one of the following formats:"
|
35
|
+
header ""
|
36
|
+
header "cdncontrol -t TARGET --show"
|
37
|
+
header "cdncontrol -t TARGET --write"
|
38
|
+
header "cdncontrol -t TARGET -p PROVIDER -w WEIGHT"
|
39
|
+
header "cdncontrol -t TARGET -p PROVIDER -m MODE"
|
40
|
+
header ""
|
41
|
+
header "Specific options:"
|
42
|
+
|
43
|
+
option :target, :required => true do
|
44
|
+
short '-t'
|
45
|
+
long '--target'
|
46
|
+
desc "The configuration to work on"
|
47
|
+
end
|
48
|
+
|
49
|
+
option :provider do
|
50
|
+
short '-p'
|
51
|
+
long '--provider'
|
52
|
+
desc "Provider to modify"
|
53
|
+
end
|
54
|
+
|
55
|
+
option :weight do
|
56
|
+
short '-w'
|
57
|
+
long '--weight'
|
58
|
+
desc 'Weight of traffic to send to provider (value between 1 and 15)'
|
59
|
+
validate /^([1-9]|1[0-5])$/
|
60
|
+
end
|
61
|
+
|
62
|
+
option :mode do
|
63
|
+
short '-m'
|
64
|
+
long '--mode'
|
65
|
+
desc "Set the serve mode of the provider"
|
66
|
+
end
|
67
|
+
|
68
|
+
option :show do
|
69
|
+
short '-s'
|
70
|
+
long '--show'
|
71
|
+
desc 'Show current provider ratios'
|
72
|
+
end
|
73
|
+
|
74
|
+
option :config do
|
75
|
+
short '-c'
|
76
|
+
long '--config'
|
77
|
+
desc 'Path to config file'
|
78
|
+
default '/usr/local/etc/cdncontrol.conf'
|
79
|
+
end
|
80
|
+
|
81
|
+
option :output_dir do
|
82
|
+
short '-o'
|
83
|
+
long '--output-dir'
|
84
|
+
desc 'Path to output directory'
|
85
|
+
default '/tmp'
|
86
|
+
end
|
87
|
+
|
88
|
+
option :verbose do
|
89
|
+
short '-v'
|
90
|
+
long '--verbose'
|
91
|
+
desc 'Show me in excrutiating detail what is happening'
|
92
|
+
end
|
93
|
+
|
94
|
+
option :write do
|
95
|
+
long '--write'
|
96
|
+
desc 'Dump all weights out to JSON files for the dashboard'
|
97
|
+
end
|
66
98
|
end
|
67
99
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
100
|
+
options = {
|
101
|
+
:provider => Choice['provider'],
|
102
|
+
:target => Choice['target'],
|
103
|
+
:mode => Choice['mode'],
|
104
|
+
:weight => Choice['weight'],
|
105
|
+
:show => Choice['show'],
|
106
|
+
:verbose => Choice['verbose'],
|
107
|
+
:write => Choice['write'],
|
108
|
+
:config => Choice['config'],
|
109
|
+
:output_dir => Choice['output_dir'],
|
110
|
+
}
|
111
|
+
return options
|
73
112
|
end
|
74
113
|
|
75
|
-
|
76
|
-
options
|
77
|
-
options
|
78
|
-
|
79
|
-
options
|
80
|
-
options[:verbose] = Choice.choices[:verbose] unless !Choice.choices[:verbose]
|
81
|
-
options[:write] = Choice.choices[:write] unless !Choice.choices[:write]
|
82
|
-
|
83
|
-
unless (options.has_key?(:target) && options[:show]) ||
|
84
|
-
(options.has_key?(:target) && options.has_key?(:write)) ||
|
85
|
-
(options.has_key?(:target) && options.has_key?(:provider) && options.has_key?(:weight)) ||
|
86
|
-
(options.has_key?(:target) && options.has_key?(:provider) && options.has_key?(:mode))
|
87
|
-
Choice.help
|
88
|
-
end
|
114
|
+
|
115
|
+
# parse options and validate them
|
116
|
+
options = parse_options
|
117
|
+
config = load_config(options[:config])
|
118
|
+
validate_options(config, options)
|
89
119
|
|
90
120
|
# trap SIGINT and return a clean exit message rather than stack trace
|
91
121
|
Signal.trap('INT') {
|
@@ -93,36 +123,31 @@ Signal.trap('INT') {
|
|
93
123
|
exit
|
94
124
|
}
|
95
125
|
|
96
|
-
|
126
|
+
# action starts here
|
97
127
|
|
98
|
-
target =
|
128
|
+
target = config['targets'][options[:target]]
|
99
129
|
|
100
|
-
tm = CDNControl::TrafficManager.new(
|
130
|
+
tm = CDNControl::TrafficManager.new(config, target, options[:verbose])
|
101
131
|
|
102
|
-
if options[:show]
|
103
|
-
tm.show_balance
|
104
|
-
end
|
132
|
+
tm.show_balance if options[:show]
|
105
133
|
|
106
|
-
if options[:write]
|
107
|
-
tm.dump_weights(options[:target],OUTPUT_PATH)
|
108
|
-
end
|
134
|
+
tm.dump_weights(options[:target], options[:output_dir]) if options[:write]
|
109
135
|
|
110
|
-
if options
|
136
|
+
if options[:provider] && options[:weight]
|
111
137
|
tm.show_balance("CURRENT LIVE WEIGHTS")
|
112
138
|
tm.set_weight(options[:provider], options[:weight])
|
113
139
|
tm.show_balance("NODE WEIGHTS AFTER CHANGE")
|
114
|
-
tm.dump_weights(options[:target],
|
115
|
-
|
140
|
+
tm.dump_weights(options[:target], options[:output_dir])
|
116
141
|
end
|
117
142
|
|
118
|
-
if options
|
143
|
+
if options[:provider] && options[:mode]
|
119
144
|
tm.show_balance("CURRENT SERVE MODES AND WEIGHTS")
|
120
145
|
tm.set_serve_mode(options[:provider], options[:mode])
|
121
146
|
tm.show_balance("NODE SERVE MODES AFTER CHANGE")
|
122
|
-
tm.dump_weights(options[:target],
|
147
|
+
tm.dump_weights(options[:target], options[:output_dir])
|
123
148
|
end
|
124
149
|
|
125
150
|
# display a nag if configured
|
126
|
-
if options[:show]
|
127
|
-
puts "** NOTE: #{
|
151
|
+
if !options[:show] && target.has_key?('nag')
|
152
|
+
puts "** NOTE: #{target['nag']}"
|
128
153
|
end
|
data/cdncontrol.gemspec
CHANGED
@@ -2,12 +2,13 @@ $:.push File.expand_path('../lib', __FILE__)
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = 'cdn_control'
|
5
|
-
gem.version = '0.0.
|
5
|
+
gem.version = '0.0.10'
|
6
6
|
gem.authors = ["Jon Cowie", "Marcus Barczak"]
|
7
7
|
gem.email = 'jonlives@gmail.com'
|
8
8
|
gem.homepage = 'https://github.com/etsy/cdncontrol'
|
9
9
|
gem.summary = "Tool for managing multiple CDN balances on Dyn's GSLB"
|
10
10
|
gem.description = "Tool for managing multiple CDN balances on Dyn's GSLB"
|
11
|
+
gem.license = 'MIT'
|
11
12
|
|
12
13
|
gem.files = `git ls-files`.split($\)
|
13
14
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -120,7 +120,7 @@ module CDNControl
|
|
120
120
|
|
121
121
|
# Make a thread-local connection to dyn, so that we open many
|
122
122
|
# connections at once.
|
123
|
-
dyn_conn = DynectRest.new('
|
123
|
+
dyn_conn = DynectRest.new(@config['organization'], @config['username'], @config['password'], @zone)
|
124
124
|
pool = dyn_conn.get(path)
|
125
125
|
|
126
126
|
pool.each do |address|
|
@@ -294,4 +294,4 @@ module CDNControl
|
|
294
294
|
end
|
295
295
|
|
296
296
|
end
|
297
|
-
end
|
297
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cdncontrol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Cowie
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dynect_rest
|
@@ -70,7 +70,8 @@ files:
|
|
70
70
|
- cdncontrol.gemspec
|
71
71
|
- lib/cdncontrol/trafficmanager.rb
|
72
72
|
homepage: https://github.com/etsy/cdncontrol
|
73
|
-
licenses:
|
73
|
+
licenses:
|
74
|
+
- MIT
|
74
75
|
metadata: {}
|
75
76
|
post_install_message:
|
76
77
|
rdoc_options: []
|