lib/routes/main.rb in gaptool-server-0.2.4 vs lib/routes/main.rb in gaptool-server-0.3.0
- old
+ new
@@ -19,49 +19,10 @@
end
end
runlist.to_json
end
- put '/service/:role/:environment' do
- data = JSON.parse request.body.read
- count = $redis.incr("service:#{params[:role]}:#{params[:environment]}:#{data['name']}:count")
- key = "service:#{params[:role]}:#{params[:environment]}:#{data['name']}:#{count}"
- $redis.hset(key, 'name', data['name'])
- $redis.hset(key, 'keys', data['keys'])
- $redis.hset(key, 'weight', data['weight'])
- $redis.hset(key, 'role', params[:role])
- $redis.hset(key, 'environment', params[:environment])
- $redis.hset(key, 'run', data['enabled'])
- {
- :role => params[:role],
- :environment => params[:environment],
- :service => data['name'],
- :count => count,
- }.to_json
- end
-
- delete '/service/:role/:environment/:service' do
- if $redis.get("service:#{params[:role]}:#{params[:environment]}:#{params[:service]}:count") == '0'
- count = 0
- else
- count = $redis.decr("service:#{params[:role]}:#{params[:environment]}:#{params[:service]}:count")
- service = eval($redis.range("running", 0, -1).grep(/scoring/).last)
- runservice(service[:hostname], params[:role], params[:environment], params[:service], 'stop')
- $redis.del("service:#{params[:role]}:#{params[:environment]}:#{params[:service]}:#{count + 1}")
- end
- {
- :role => params[:role],
- :environment => params[:environment],
- :service => params[:service],
- :count => count,
- }.to_json
- end
-
- get '/services' do
- getservices().to_json
- end
-
post '/regenhosts' do
data = JSON.parse request.body.read
hostsgen(data['zone'])
hosts.to_json
end
@@ -181,13 +142,24 @@
out << $redis.hgetall(host)
end
out.to_json
end
+ get '/instance/:id' do
+ out = Array.new
+ $redis.hgetall($redis.keys("host:*:*:#{params[:id]}").first).to_json
+ end
+
get '/hosts/:role/:environment' do
out = Array.new
- $redis.keys("host:#{params[:role]}:#{params[:environment]}*").each do |host|
- out << $redis.hgetall(host)
+ unless params[:role] == "ALL"
+ $redis.keys("host:#{params[:role]}:#{params[:environment]}*").each do |host|
+ out << $redis.hgetall(host)
+ end
+ else
+ $redis.keys("host:*:#{params[:environment]}:*").each do |host|
+ out << $redis.hgetall(host)
+ end
end
out.to_json
end
get '/host/:role/:environment/:instance' do