Upload an XML template of libvirt. Response is the modified filename.
Signed-off-by: Ren Wen 15991987063@163.com --- container/assist-cci/routes.rb | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 container/assist-cci/routes.rb
diff --git a/container/assist-cci/routes.rb b/container/assist-cci/routes.rb new file mode 100755 index 0000000..0e71a75 --- /dev/null +++ b/container/assist-cci/routes.rb @@ -0,0 +1,37 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +require 'sinatra' +require 'digest/md5' + +configure do + set :bind, '0.0.0.0' + set :port, ENV['ASSIST_CCI_PORT'] +end + +LIBVIRT_XML_PATH = ENV['LIBVIRT_XML_PATH'] +VERSION = '0.1' + +get '/' do + "version: #{VERSION}" +end + +post '/upload' do + if params[:file] && (tempfile = params[:file][:tempfile]) && (filename = params[:file][:filename]) + dirname = File.basename(filename, '.xml') + content = tempfile.read + md5_filename = Digest::MD5.hexdigest(content) + '.xml' + + dir_path = "#{LIBVIRT_XML_PATH}/#{dirname}" + Dir.exist?(dir_path) || Dir.mkdir(dir_path) + + target = "#{dir_path}/#{md5_filename}" + File.open(target, 'wb') { |f| f.write content } + + File.join(dirname, md5_filename) + else + '' + end +end
+# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require 'sinatra' +require 'digest/md5'
+configure do
- set :bind, '0.0.0.0'
- set :port, ENV['ASSIST_CCI_PORT']
+end
four line above =>
set :bind, '0.0.0.0' set :port, ENV['ASSIST_CCI_PORT']
Thanks, Luan Shengde
+LIBVIRT_XML_PATH = ENV['LIBVIRT_XML_PATH'] +VERSION = '0.1'
On Fri, Jan 15, 2021 at 05:31:30PM +0800, Luan Shengde wrote:
+# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require 'sinatra' +require 'digest/md5'
+configure do
- set :bind, '0.0.0.0'
- set :port, ENV['ASSIST_CCI_PORT']
+end
four line above =>
set :bind, '0.0.0.0' set :port, ENV['ASSIST_CCI_PORT']
All work well.
Thanks, RenWen
Thanks, Luan Shengde
+LIBVIRT_XML_PATH = ENV['LIBVIRT_XML_PATH'] +VERSION = '0.1'
We should already have build-config upload functionality. How about reusing it?
CC Jiaxin.
Thanks, Fengguang
On Fri, Jan 15, 2021 at 05:20:58PM +0800, Ren Wen wrote:
Upload an XML template of libvirt. Response is the modified filename.
Signed-off-by: Ren Wen 15991987063@163.com
container/assist-cci/routes.rb | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 container/assist-cci/routes.rb
diff --git a/container/assist-cci/routes.rb b/container/assist-cci/routes.rb new file mode 100755 index 0000000..0e71a75 --- /dev/null +++ b/container/assist-cci/routes.rb @@ -0,0 +1,37 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require 'sinatra' +require 'digest/md5'
+configure do
- set :bind, '0.0.0.0'
- set :port, ENV['ASSIST_CCI_PORT']
+end
+LIBVIRT_XML_PATH = ENV['LIBVIRT_XML_PATH'] +VERSION = '0.1'
+get '/' do
- "version: #{VERSION}"
+end
+post '/upload' do
- if params[:file] && (tempfile = params[:file][:tempfile]) && (filename = params[:file][:filename])
- dirname = File.basename(filename, '.xml')
- content = tempfile.read
- md5_filename = Digest::MD5.hexdigest(content) + '.xml'
- dir_path = "#{LIBVIRT_XML_PATH}/#{dirname}"
- Dir.exist?(dir_path) || Dir.mkdir(dir_path)
- target = "#{dir_path}/#{md5_filename}"
- File.open(target, 'wb') { |f| f.write content }
- File.join(dirname, md5_filename)
- else
- ''
- end
+end
2.23.0
On Fri, Jan 15, 2021 at 06:07:32PM +0800, Wu Fengguang wrote:
We should already have build-config upload functionality. How about reusing it?
It's better to reuse. I'll have a look at it.
Thanks, RenWen
CC Jiaxin.
Thanks, Fengguang
On Fri, Jan 15, 2021 at 05:20:58PM +0800, Ren Wen wrote:
Upload an XML template of libvirt. Response is the modified filename.
Signed-off-by: Ren Wen 15991987063@163.com
container/assist-cci/routes.rb | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 container/assist-cci/routes.rb
diff --git a/container/assist-cci/routes.rb b/container/assist-cci/routes.rb new file mode 100755 index 0000000..0e71a75 --- /dev/null +++ b/container/assist-cci/routes.rb @@ -0,0 +1,37 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require 'sinatra' +require 'digest/md5'
+configure do
- set :bind, '0.0.0.0'
- set :port, ENV['ASSIST_CCI_PORT']
+end
+LIBVIRT_XML_PATH = ENV['LIBVIRT_XML_PATH'] +VERSION = '0.1'
+get '/' do
- "version: #{VERSION}"
+end
+post '/upload' do
- if params[:file] && (tempfile = params[:file][:tempfile]) && (filename = params[:file][:filename])
- dirname = File.basename(filename, '.xml')
- content = tempfile.read
- md5_filename = Digest::MD5.hexdigest(content) + '.xml'
- dir_path = "#{LIBVIRT_XML_PATH}/#{dirname}"
- Dir.exist?(dir_path) || Dir.mkdir(dir_path)
- target = "#{dir_path}/#{md5_filename}"
- File.open(target, 'wb') { |f| f.write content }
- File.join(dirname, md5_filename)
- else
- ''
- end
+end
2.23.0