diff --git a/flow/client/bin/appflow-template b/flow/client/bin/appflow-template index bf1912e6f1..432b0fe08d 100755 --- a/flow/client/bin/appflow-template +++ b/flow/client/bin/appflow-template @@ -392,4 +392,60 @@ cmd=CommandParser::CmdParser.new(ARGV) do client.post("#{RESOURCE_PATH}/#{service_id}/action", json_action) } end + + update_desc = <<-EOT.unindent + Update the template contents. If a path is not provided the editor will + be launched to modify the current content. + EOT + + command :update, update_desc, :templateid, [:file, nil] do + template_id = args[0] + client = Service::Client.new( + :username => options[:username], + :password => options[:password], + :url => options[:server], + :user_agent => USER_AGENT) + + if args[1] + path = args[1] + else + require 'tempfile' + + tmp = Tempfile.new(template_id.to_s) + path = tmp.path + + response = client.get("#{RESOURCE_PATH}/#{template_id}") + + if CloudClient::is_error?(response) + exit_with_code response.code.to_i, response.to_s + else + document_hash = JSON.parse(response.body) + template = document_hash['DOCUMENT']['TEMPLATE']['BODY'] + + tmp << template.to_json + tmp.flush + + editor_path = ENV["EDITOR"] ? ENV["EDITOR"] : EDITOR_PATH + system("#{editor_path} #{path}") + + unless $?.exitstatus == 0 + puts "Editor not defined" + exit -1 + end + + tmp.close + end + end + + exit_code = 0 + + t_str = File.read(path) + response = client.put("#{RESOURCE_PATH}/#{template_id}", t_str) + if CloudClient::is_error?(response) + puts response.to_s + exit_code = response.code.to_i + end + + exit_code + end end \ No newline at end of file diff --git a/flow/client/lib/appflow_client.rb b/flow/client/lib/appflow_client.rb index 4d3fcc9d8b..5dde7b63a9 100644 --- a/flow/client/lib/appflow_client.rb +++ b/flow/client/lib/appflow_client.rb @@ -299,6 +299,13 @@ module Service do_request(req) end + def put(path, body) + req = Net::HTTP::Proxy(@host, @port)::Put.new(path) + req.body = body + + do_request(req) + end + def login req = Net::HTTP::Proxy(@host, @port)::Post.new('/login') diff --git a/flow/controllers/appflow-server.rb b/flow/controllers/appflow-server.rb index 7b868ccd62..a8be5c8cd5 100644 --- a/flow/controllers/appflow-server.rb +++ b/flow/controllers/appflow-server.rb @@ -286,6 +286,20 @@ delete '/service_template/:id' do status 201 end +put '/service_template/:id' do + service_template = OpenNebula::ServiceTemplate.new_with_id(params[:id], @client) + + rc = service_template.update(request.body.read) + if OpenNebula.is_error?(rc) + error CloudServer::HTTP_ERROR_CODE[rc.errno], rc.message + end + + service_template.info + + status 200 + body service_template.to_json +end + post '/service_template' do s_template = OpenNebula::ServiceTemplate.new( OpenNebula::ServiceTemplate.build_xml,