61 lines
1.9 KiB
Ruby
61 lines
1.9 KiB
Ruby
|
|
module Devops
|
|
module API2_0
|
|
module Routes
|
|
module DeployRoutes
|
|
|
|
def self.registered(app)
|
|
|
|
# Run chef-client on reserved server
|
|
#
|
|
# * *Request*
|
|
# - method : POST
|
|
# - headers :
|
|
# - Content-Type: application/json
|
|
# - body :
|
|
# {
|
|
# "names": [], -> array of servers names to run chef-client
|
|
# "tags": [], -> array of tags to apply on each server before running chef-client
|
|
# "trace": true -> return output in stream
|
|
# }
|
|
#
|
|
# * *Returns* : text stream
|
|
app.post_with_headers "/deploy", :headers => [:content_type] do
|
|
check_privileges("server", "x")
|
|
# TODO: send message
|
|
#broadcast(:devops_deploy, "deploy")
|
|
r = create_object_from_json_body
|
|
names = check_array(r["names"], "Parameter 'names' should be a not empty array of strings")
|
|
tags = check_array(r["tags"], "Parameter 'tags' should be an array of strings", String, true) || []
|
|
|
|
if r.key?("trace")
|
|
stream() do |out|
|
|
status = []
|
|
begin
|
|
Devops::API2_0::Handler::Deploy.new(request, params).deploy_stream(out, names, tags)
|
|
rescue IOError => e
|
|
logger.error e.message
|
|
break
|
|
end
|
|
end # stream
|
|
else
|
|
ids = Devops::API2_0::Handler::Deploy.new(request, params).deploy(names, tags)
|
|
sleep 1
|
|
ids.each do |jid|
|
|
logger.info "Job '#{jid}' has been queued"
|
|
uri.path = "#{DevopsConfig.config[:url_prefix]}/v2.0/report/" + jid
|
|
files.push uri.to_s
|
|
end
|
|
json files
|
|
end
|
|
|
|
end
|
|
|
|
puts "Deploy routes initialized"
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|
|
end
|