mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-21 04:12:37 +09:00
feature #2050: Add appflow-template update
This commit is contained in:
1 parent
3d53730748
commit
b5b33c2936
3 files changed
+77
No files matched your search
@@ -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
|
||||
@@ -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')
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user