varnish_rest_api_client 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/varnish_rest_api_client/client.rb +35 -42
- data/lib/varnish_rest_api_client/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5422fec6eb4cfd662bf62146794fd8524064f194
|
4
|
+
data.tar.gz: d4ee559a0ff5b37f10c191c65ed3c12f9d49ef3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1862b7be7601f34e66bd0b24f2e7509748298b437960d3a5b2b416c3c89f31e972b9febb2cc5002e149e6633721ecb90210b42feef8a5a7b0dcaa2062f5ac4b3
|
7
|
+
data.tar.gz: ce3004f6c2806e9aaddc525bbc7051f06edb52339bea1055b3c2b6e7d4ca0f49d9338a0880059815b5cc50f5b38aaad36aa04ab1c582b632c3770031f163ecae
|
@@ -8,7 +8,7 @@ module VarnishRestApiClient
|
|
8
8
|
|
9
9
|
class Client < Thor
|
10
10
|
class_option :varnish, :aliases => "V", :desc => "varnish server(s)", :type => :array
|
11
|
-
class_option :zkserver, :aliases => "z", :desc => "zookeeper server:port", :default => "
|
11
|
+
class_option :zkserver, :aliases => "z", :desc => "zookeeper server:port", :default => "autodeploy.mobile.rz:2181"
|
12
12
|
class_option :zkpath, :aliases => "P", :desc => "zookeeper varnish root path", :default => "/varnish"
|
13
13
|
|
14
14
|
# alternate use invoke
|
@@ -25,18 +25,12 @@ class Client < Thor
|
|
25
25
|
|
26
26
|
desc "out BACKEND", "set health of this varnish BACKEND to sick."
|
27
27
|
def out(backend)
|
28
|
-
|
29
|
-
p = call_rest(api)
|
30
|
-
puts p.call("#{backend}/out")
|
31
|
-
end
|
28
|
+
set_health(backend,"out")
|
32
29
|
end
|
33
30
|
|
34
31
|
desc "in BACKEND", "set health of this varnish BACKEND to auto"
|
35
32
|
def in(backend)
|
36
|
-
|
37
|
-
p = call_rest(api)
|
38
|
-
puts p.call("#{backend}/in")
|
39
|
-
end
|
33
|
+
set_health(backend,"in")
|
40
34
|
end
|
41
35
|
|
42
36
|
desc "show", "show varnish hosts registered with zookeeper"
|
@@ -45,24 +39,38 @@ class Client < Thor
|
|
45
39
|
end
|
46
40
|
|
47
41
|
desc "list PATTERN", "display all varnish backends"
|
48
|
-
def list(pattern=nil)
|
49
|
-
backends_found =
|
50
|
-
|
51
|
-
uri = pattern ? "list/#{pattern}" : "list"
|
52
|
-
p = call_rest(api)
|
53
|
-
result = p.call(uri)
|
54
|
-
next if result.empty?
|
55
|
-
if result.first.class != Hash
|
56
|
-
puts "error from #{api}: #{result}"
|
57
|
-
end
|
58
|
-
|
59
|
-
backends_found << result
|
60
|
-
end
|
61
|
-
puts backends_found.empty? ? "no backends found for pattern #{pattern}" : backends_found
|
42
|
+
def list(pattern=nil)
|
43
|
+
backends_found = list_backends(pattern)
|
44
|
+
puts backends_found.empty? ? "no backends found for pattern #{pattern}" : backends_found
|
62
45
|
end
|
63
46
|
|
64
47
|
no_commands do
|
65
48
|
|
49
|
+
def set_health(backend,action)
|
50
|
+
@varnishes = list_backends(backend).collect { |varnish| varnish['varnishhost']}
|
51
|
+
$stderr.puts "no backends found for pattern \"#{backend}\"" if @varnishes.empty?
|
52
|
+
@varnishes.each do |api|
|
53
|
+
p = call_rest(api)
|
54
|
+
puts p.call("#{backend}/#{action}")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def list_backends(pattern=nil)
|
59
|
+
backends_found = Array.new
|
60
|
+
@nodes.each do |api|
|
61
|
+
uri = pattern ? "list/#{pattern}" : "list"
|
62
|
+
p = call_rest(api)
|
63
|
+
result = p.call(uri)
|
64
|
+
next if result.empty?
|
65
|
+
if result.first.class != Hash
|
66
|
+
puts "error from #{api}: #{result}"
|
67
|
+
end
|
68
|
+
|
69
|
+
backends_found << result
|
70
|
+
end
|
71
|
+
backends_found.empty? ? [] : backends_found.flatten
|
72
|
+
end
|
73
|
+
|
66
74
|
def use_zookeeper
|
67
75
|
if options[:varnish].nil? || options[:varnish].empty?
|
68
76
|
return true
|
@@ -95,32 +103,17 @@ class Client < Thor
|
|
95
103
|
begin
|
96
104
|
buffer = open("http://#{node}/#{action}").read
|
97
105
|
result = JSON.parse(buffer)
|
98
|
-
result.collect! { |e| e["varnishhost"] = node ; e
|
106
|
+
result.collect! { |e| e["varnishhost"] = node ; e }
|
99
107
|
rescue SocketError => e
|
100
108
|
abort "problem connecting rest api at #{node}: #{e.message}"
|
101
109
|
rescue OpenURI::HTTPError => e
|
110
|
+
response = e.io
|
111
|
+
$stderr.puts response.string
|
102
112
|
abort "problem calling rest api at #{node}: #{e.message}"
|
103
113
|
end
|
104
114
|
end
|
105
115
|
end
|
106
|
-
|
107
|
-
def call_restb(url,node_name)
|
108
|
-
begin
|
109
|
-
buffer = open(url).read
|
110
|
-
result = JSON.parse(buffer)
|
111
|
-
result.collect! { |e| e["varnishhost"] = node_name ; e }
|
112
|
-
rescue SocketError => e
|
113
|
-
abort "problem connecting rest api at #{url}: #{e.message}"
|
114
|
-
rescue OpenURI::HTTPError => e
|
115
|
-
abort "problem calling rest api at #{url}: #{e.message}"
|
116
|
-
end
|
117
|
-
if block_given?
|
118
|
-
yield result
|
119
|
-
else
|
120
|
-
result
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
116
|
+
|
124
117
|
end
|
125
118
|
|
126
119
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: varnish_rest_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Colby
|
@@ -138,8 +138,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
version: '0'
|
139
139
|
requirements: []
|
140
140
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.4.
|
141
|
+
rubygems_version: 2.4.5
|
142
142
|
signing_key:
|
143
143
|
specification_version: 4
|
144
144
|
summary: A command line client for the varnish rest api.
|
145
145
|
test_files: []
|
146
|
+
has_rdoc:
|