1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

F #1692: Enable the option to add addons dynamically to Sunstone (#2067)

* Added ruby lib file

* Changed min name: main.js -> main-dist.js

* Added addons class
This commit is contained in:
Abel Coronado 2018-05-07 18:42:34 +02:00 committed by Tino Vázquez
parent 3bbd7b1922
commit b9fd1feb2d
5 changed files with 100 additions and 67 deletions

View File

@ -628,6 +628,7 @@ RUBY_LIB_FILES="src/mad/ruby/ActionManager.rb \
src/oca/ruby/deprecated/OpenNebula.rb \
src/oca/ruby/opennebula.rb \
src/sunstone/OpenNebulaVNC.rb \
src/sunstone/OpenNebulaAddons.rb \
src/vmm_mad/remotes/vcenter/vcenter_driver.rb \
src/vmm_mad/remotes/az/az_driver.rb \
src/vmm_mad/remotes/ec2/ec2_driver.rb \
@ -2041,6 +2042,11 @@ if [ "$INSTALL_ETC" = "yes" ] ; then
done
fi
if [ "$SUNSTONE" = "yes" ] || [ "$SUNSTONE_DEV" = "yes" ] ; then
mkdir $VAR_LOCATION/sunstone && touch $VAR_LOCATION/sunstone/main.js
ln -s $VAR_LOCATION/sunstone/main.js $SUNSTONE_LOCATION/public/dist/main.js
fi
# --- Set ownership or remove OpenNebula directories ---
if [ "$UNINSTALL" = "no" ] ; then

View File

@ -0,0 +1,89 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
require 'rubygems'
require 'json'
ADDONS_LOCATION = SUNSTONE_LOCATION + "/public/app/addons/dist/*"
MAIN_DIST_PATH = SUNSTONE_LOCATION + "/public/dist/main-dist.js"
MAIN_PATH = VAR_LOCATION + "/sunstone/main.js"
class OpenNebulaAddons
def initialize(logger)
@logger = logger
@main_folder = File.join(VAR_LOCATION, "sunstone")
begin
Dir.mkdir(@main_folder)
rescue Exception => e
@logger.error "Cannot create sunstone folder"
@logger.error e.message
end
main = File.open(MAIN_PATH, "w")
main_dist = File.new(MAIN_DIST_PATH)
files = Dir[ADDONS_LOCATION].select{ |f| File.file? f }
lines = main_dist.gets
while lines != nil
main << lines
if lines.include? "// start-addon-section //"
load_start_section(files, main)
end
if lines.include? "'addons/start'"
load_list_start(files, main)
end
lines = main_dist.gets
end
end
private
def load_start_section(files, tmp)
files.each do |file|
add = File.new(file)
boolist = false
add.each do |line|
if line.include? "// list-start //"
boolist = true
end
tmp << line if !boolist
end
add.close
end
end
def load_list_start(files, tmp)
files.each do |file|
add = File.new(file)
line = add.gets
while line != nil
if line.include? "// list-start //"
line = add.gets
while line != nil
tmp << line
line = add.gets
end
end
line = add.gets
end
add.close
end
end
end

View File

@ -20,6 +20,7 @@ require 'OpenNebulaJSON'
include OpenNebulaJSON
require 'OpenNebulaVNC'
require 'OpenNebulaAddons'
require 'OpenNebulaJSON/JSONUtils'
#include JSONUtils

View File

@ -21,6 +21,7 @@ import os
Import('env')
if env['sunstone']=='yes':
os.system("rm dist/main.js")
print "Generating Sunstone minified files\n"
exit_code=os.system("grunt --gruntfile ./Gruntfile.js sass")
if exit_code != 0:
@ -31,3 +32,4 @@ if env['sunstone']=='yes':
if exit_code != 0:
print "Error generating minifying Sunstone files\n"
exit(-1)
os.system("mv dist/main.js dist/main-dist.js")

View File

@ -42,10 +42,6 @@ CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-server.conf"
PLUGIN_CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-plugins.yaml"
LOGOS_CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-logos.yaml"
ADDONS_LOCATION = SUNSTONE_LOCATION+"/public/app/addons/dist/*"
MAIN_FILE_PATH = SUNSTONE_LOCATION+"/public/dist/main.js"
TMP_FILE = SUNSTONE_LOCATION+"/public/dist/main.tmp"
SUNSTONE_ROOT_DIR = File.dirname(__FILE__)
$: << RUBY_LIB_LOCATION
@ -199,6 +195,8 @@ configure do
set :erb, :trim => '-'
end
$addons = OpenNebulaAddons.new(logger)
DEFAULT_TABLE_ORDER = "desc"
DEFAULT_PAGE_LENGTH = 10
@ -354,68 +352,6 @@ helpers do
session.clear
return [204, ""]
end
def load_addons
tmp = File.open(TMP_FILE, "w")
main = File.new(MAIN_FILE_PATH)
files = Dir[ADDONS_LOCATION].select{ |f| File.file? f }
if files.length == 0 then
return ""
end
lines = main.gets
while lines != nil
tmp << lines
if lines.include? "// start-addon-section //"
load_start_section(files, tmp)
end
if lines.include? "'addons/start'"
load_list_start(files, tmp)
end
lines = main.gets
end
FileUtils.mv(TMP_FILE, MAIN_FILE_PATH)
files.each do |file|
FileUtils.rm(file)
end
end
def load_start_section(files, tmp)
files.each do |file|
add = File.new(file)
boolist = false
add.each do |line|
if line.include? "// list-start //"
boolist = true
end
tmp << line if !boolist
end
add.close
end
end
def load_list_start(files, tmp)
files.each do |file|
add = File.new(file)
line = add.gets
while line != nil
if line.include? "// list-start //"
line=add.gets
while line != nil
tmp<<line
line=add.gets
end
end
line=add.gets
end
add.close
end
end
end
before do
@ -520,7 +456,6 @@ end
# HTML Requests
##############################################################################
get '/' do
#load_addons
content_type 'text/html', :charset => 'utf-8'
if !authorized?
return erb :login