mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-26 06:50:09 +03:00
Refactor how oned.conf is retrieve in JS
This commit is contained in:
parent
9af73f66f8
commit
4a69c1e9e2
@ -53,8 +53,6 @@ define(function(require) {
|
||||
_setupCloseDropdownsOnClick();
|
||||
_insertUserAndZoneSelector();
|
||||
|
||||
Config.initOnedConf();
|
||||
|
||||
if (Config.isTabEnabled(PROVISION_TAB_ID)) {
|
||||
Sunstone.showTab(PROVISION_TAB_ID);
|
||||
$('#loading').hide();
|
||||
|
@ -1,114 +0,0 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2015, 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
define(function(require) {
|
||||
var OpenNebulaAction = require('./action');
|
||||
var Locale = require('utils/locale');
|
||||
var OpenNebulaError = require('./error');
|
||||
var OpenNebulaHelper = require('./helper');
|
||||
|
||||
|
||||
var onedconfCache;
|
||||
var onedconfWaiting = false;
|
||||
var onedconfCallbacks = [];
|
||||
|
||||
var CACHE_EXPIRE = 36000000; //ms
|
||||
|
||||
var _clearCache = function() {
|
||||
onedconfCache = null;
|
||||
//console.log("onedconf. Cache cleaned");
|
||||
};
|
||||
|
||||
var RESOURCE = "SYSTEM";
|
||||
|
||||
var System = {
|
||||
"resource": RESOURCE,
|
||||
"onedconf": function(params){
|
||||
var callback = params.success;
|
||||
var callbackError = params.error;
|
||||
var request = OpenNebulaHelper.request(RESOURCE, "onedconf");
|
||||
|
||||
if (onedconfCache &&
|
||||
onedconfCache["timestamp"] + CACHE_EXPIRE > new Date().getTime()) {
|
||||
|
||||
//console.log("onedconf. Cache used");
|
||||
|
||||
return callback ?
|
||||
callback(request, onedconfCache["pcis"]) : null;
|
||||
}
|
||||
|
||||
onedconfCallbacks.push({
|
||||
success : callback,
|
||||
error : callbackError
|
||||
});
|
||||
|
||||
//console.log("onedconf. Callback queued");
|
||||
|
||||
if (onedconfWaiting) {
|
||||
return;
|
||||
}
|
||||
|
||||
onedconfWaiting = true;
|
||||
|
||||
//console.log("onedconf. NO cache, calling ajax");
|
||||
|
||||
$.ajax({
|
||||
url: "onedconf",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(response) {
|
||||
onedconfCache = {
|
||||
timestamp : new Date().getTime(),
|
||||
onedConf : response
|
||||
};
|
||||
|
||||
onedconfWaiting = false;
|
||||
|
||||
for (var i = 0; i < onedconfCallbacks.length; i++) {
|
||||
var callback = onedconfCallbacks[i].success;
|
||||
|
||||
if (callback) {
|
||||
//console.log("onedconf. Callback called");
|
||||
callback(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
onedconfCallbacks = [];
|
||||
|
||||
return;
|
||||
},
|
||||
error: function(response) {
|
||||
onedconfWaiting = false;
|
||||
|
||||
for (var i = 0; i < onedconfCallbacks.length; i++) {
|
||||
var callback = onedconfCallbacks[i].error;
|
||||
|
||||
if (callback) {
|
||||
//console.log("onedconf. ERROR Callback called");
|
||||
callback(request, OpenNebulaError(response));
|
||||
}
|
||||
}
|
||||
|
||||
onedconfCallbacks = [];
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return System;
|
||||
})
|
@ -16,23 +16,10 @@
|
||||
|
||||
define(function(require) {
|
||||
require('jquery');
|
||||
var OpenNebulaSystem = require('opennebula/system');
|
||||
|
||||
// Clone the local config object in a private var
|
||||
var _config = $.extend(true, {}, config);
|
||||
|
||||
var _defaultCost = {
|
||||
cpuCost : 0,
|
||||
memoryCost : 0,
|
||||
diskCost : 0
|
||||
};
|
||||
|
||||
var _dsMadConf = {};
|
||||
var _imMadConf = {};
|
||||
var _vmMadConf = {};
|
||||
var _authMadConf = {};
|
||||
var _marketMadConf = {};
|
||||
|
||||
var Config = {
|
||||
'isTabEnabled': function(tabName) {
|
||||
var enabled = _config['view']['enabled_tabs'].indexOf(tabName) != -1;
|
||||
@ -157,55 +144,7 @@ define(function(require) {
|
||||
'logo': (_config['view']["small_logo"] || "images/one_small_logo.png"),
|
||||
'vmLogos': (_config['vm_logos']),
|
||||
'enabledTabs': _config['view']['enabled_tabs'],
|
||||
"defaultCost" : _defaultCost,
|
||||
'dsMadConf' : _dsMadConf,
|
||||
'imMadConf' : _imMadConf,
|
||||
'vmMadConf' : _vmMadConf,
|
||||
'authMadConf' : _authMadConf,
|
||||
'marketMadConf' : _marketMadConf,
|
||||
"initOnedConf" : function() {
|
||||
OpenNebulaSystem.onedconf({
|
||||
data : {},
|
||||
timeout: true,
|
||||
success: function (request, onedconf){
|
||||
if (onedconf.DEFAULT_COST != undefined){
|
||||
if (onedconf.DEFAULT_COST.CPU_COST != undefined){
|
||||
_defaultCost.cpuCost = parseInt(onedconf.DEFAULT_COST.CPU_COST);
|
||||
}
|
||||
if (onedconf.DEFAULT_COST.MEMORY_COST != undefined){
|
||||
_defaultCost.memoryCost = parseInt(onedconf.DEFAULT_COST.MEMORY_COST);
|
||||
}
|
||||
if (onedconf.DEFAULT_COST.DISK_COST != undefined){
|
||||
_defaultCost.diskCost = parseInt(onedconf.DEFAULT_COST.DISK_COST);
|
||||
}
|
||||
}
|
||||
|
||||
if (onedconf.DS_MAD_CONF != undefined){
|
||||
$.extend(true, _dsMadConf, onedconf.DS_MAD_CONF);
|
||||
}
|
||||
|
||||
if (onedconf.MARKET_MAD_CONF != undefined){
|
||||
$.extend(true, _marketMadConf, onedconf.MARKET_MAD_CONF);
|
||||
}
|
||||
|
||||
if (onedconf.IM_MAD != undefined){
|
||||
$.extend(true, _imMadConf, onedconf.IM_MAD);
|
||||
}
|
||||
|
||||
if (onedconf.VM_MAD != undefined){
|
||||
$.extend(true, _vmMadConf, onedconf.VM_MAD);
|
||||
}
|
||||
|
||||
if (onedconf.AUTH_MAD != undefined){
|
||||
$.extend(true, _authMadConf, onedconf.AUTH_MAD);
|
||||
}
|
||||
},
|
||||
error: function(request, error_json){
|
||||
console.error("There was an error requesting oned.conf: "+
|
||||
error_json.error.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
'onedConf': _config['oned_conf']
|
||||
}
|
||||
|
||||
return Config;
|
||||
|
@ -554,17 +554,19 @@ define(function(require) {
|
||||
$('[required_active]', dialog).removeAttr('required')
|
||||
.removeAttr('required_active');
|
||||
|
||||
$.each(Config.dsMadConf, function(i, e){
|
||||
if (e["NAME"] == mad) {
|
||||
if (!$.isEmptyObject(e["REQUIRED_ATTRS"])) {
|
||||
$.each(e["REQUIRED_ATTRS"].split(","), function(i, e){
|
||||
$('#' + e.toLowerCase(), dialog).attr('required', true).attr('required_active', '');
|
||||
});
|
||||
if (Config.onedConf.DS_MAD_CONF !== undefined) {
|
||||
$.each(Config.onedConf.DS_MAD_CONF, function(i, e){
|
||||
if (e["NAME"] == mad) {
|
||||
if (!$.isEmptyObject(e["REQUIRED_ATTRS"])) {
|
||||
$.each(e["REQUIRED_ATTRS"].split(","), function(i, e){
|
||||
$('#' + e.toLowerCase(), dialog).attr('required', true).attr('required_active', '');
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -65,15 +65,15 @@ define(function(require) {
|
||||
var that = this;
|
||||
|
||||
that.vmMadNameList = [];
|
||||
if (Config.vmMadConf !== undefined) {
|
||||
$.each(Config.vmMadConf, function(index, vmMad) {
|
||||
if (Config.onedConf.VM_MAD !== undefined) {
|
||||
$.each(Config.onedConf.VM_MAD, function(index, vmMad) {
|
||||
that.vmMadNameList.push(vmMad["NAME"]);
|
||||
});
|
||||
}
|
||||
|
||||
that.imMadNameList = [];
|
||||
if (Config.imMadConf !== undefined) {
|
||||
$.each(Config.imMadConf, function(index, imMad) {
|
||||
if (Config.onedConf.IM_MAD !== undefined) {
|
||||
$.each(Config.onedConf.IM_MAD, function(index, imMad) {
|
||||
that.imMadNameList.push(imMad["NAME"]);
|
||||
});
|
||||
}
|
||||
|
@ -145,18 +145,20 @@ define(function(require) {
|
||||
var pers_forced = false;
|
||||
|
||||
// Set the persistency
|
||||
$.each(Config.dsMadConf,function(i,e){
|
||||
if (e["NAME"] == mad && !$.isEmptyObject(e["PERSISTENT_ONLY"])) {
|
||||
if (e["PERSISTENT_ONLY"] != undefined &&
|
||||
e["PERSISTENT_ONLY"].toLowerCase() == "yes") {
|
||||
$('#img_persistent', context).prop('disabled', true);
|
||||
$('#img_persistent', context).prop('checked', true);
|
||||
pers_forced = true;
|
||||
return false;
|
||||
if (Config.onedConf.DS_MAD_CONF !== undefined) {
|
||||
$.each(Config.onedConf.DS_MAD_CONF, function(i,e){
|
||||
if (e["NAME"] == mad && !$.isEmptyObject(e["PERSISTENT_ONLY"])) {
|
||||
if (e["PERSISTENT_ONLY"] != undefined &&
|
||||
e["PERSISTENT_ONLY"].toLowerCase() == "yes") {
|
||||
$('#img_persistent', context).prop('disabled', true);
|
||||
$('#img_persistent', context).prop('checked', true);
|
||||
pers_forced = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
if (!pers_forced) {
|
||||
$('#img_persistent', context).prop('disabled', false);
|
||||
|
@ -137,8 +137,8 @@ define(function(require) {
|
||||
};
|
||||
|
||||
that.marketMadNameList = [];
|
||||
if (Config.marketMadConf !== undefined) {
|
||||
$.each(Config.marketMadConf, function(index, marketMad) {
|
||||
if (Config.onedConf.MARKET_MAD_CONF !== undefined) {
|
||||
$.each(Config.onedConf.MARKET_MAD_CONF, function(index, marketMad) {
|
||||
that.marketMadNameList.push(marketMad["NAME"]);
|
||||
});
|
||||
}
|
||||
@ -250,17 +250,19 @@ define(function(require) {
|
||||
|
||||
// Show attributes for the selected market mad and set the required ones
|
||||
$('.market-mad-attr-container.' + marketMADName).show();
|
||||
$.each(Config.marketMadConf, function(i, e){
|
||||
if (e["NAME"] == marketMADName) {
|
||||
if (!$.isEmptyObject(e["REQUIRED_ATTRS"])) {
|
||||
$.each(e["REQUIRED_ATTRS"].split(","), function(i, attrName){
|
||||
$('#' + attrName, dialog).attr('required', true);
|
||||
});
|
||||
if (Config.onedConf.MARKET_MAD_CONF !== undefined) {
|
||||
$.each(Config.onedConf.MARKET_MAD_CONF, function(i, e){
|
||||
if (e["NAME"] == marketMADName) {
|
||||
if (!$.isEmptyObject(e["REQUIRED_ATTRS"])) {
|
||||
$.each(e["REQUIRED_ATTRS"].split(","), function(i, attrName){
|
||||
$('#' + attrName, dialog).attr('required', true);
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -267,15 +267,15 @@ define(function(require) {
|
||||
var diskCost = capacity.DISK_COST;
|
||||
|
||||
if (cpuCost == undefined){
|
||||
cpuCost = Config.defaultCost.cpuCost;
|
||||
cpuCost = Config.onedConf.DEFAULT_COST.CPU_COST;
|
||||
}
|
||||
|
||||
if (memoryCost == undefined){
|
||||
memoryCost = Config.defaultCost.memoryCost;
|
||||
memoryCost = Config.onedConf.DEFAULT_COST.MEMORY_COST;
|
||||
}
|
||||
|
||||
if (diskCost == undefined){
|
||||
diskCost = Config.defaultCost.diskCost;
|
||||
diskCost = Config.onedConf.DEFAULT_COST.DISK_COST;
|
||||
}
|
||||
|
||||
if ((cpuCost != 0 || memoryCost != 0 || diskCost != 0) && Config.isFeatureEnabled("showback")) {
|
||||
@ -424,11 +424,11 @@ define(function(require) {
|
||||
var memoryCost = capacity.MEMORY_COST;
|
||||
|
||||
if (cpuCost == undefined){
|
||||
cpuCost = Config.defaultCost.cpuCost;
|
||||
cpuCost = Config.onedConf.DEFAULT_COST.CPU_COST;
|
||||
}
|
||||
|
||||
if (memoryCost == undefined){
|
||||
memoryCost = Config.defaultCost.memoryCost;
|
||||
memoryCost = Config.onedConf.DEFAULT_COST.MEMORY_COST;
|
||||
}
|
||||
|
||||
if ((cpuCost != 0 || memoryCost != 0) && Config.isFeatureEnabled("showback")) {
|
||||
|
@ -201,11 +201,11 @@ define(function(require) {
|
||||
var memoryCost = template_json.VMTEMPLATE.TEMPLATE.MEMORY_COST;
|
||||
|
||||
if (cpuCost == undefined){
|
||||
cpuCost = Config.defaultCost.cpuCost;
|
||||
cpuCost = Config.onedConf.DEFAULT_COST.CPU_COST;
|
||||
}
|
||||
|
||||
if (memoryCost == undefined){
|
||||
memoryCost = Config.defaultCost.memoryCost;
|
||||
memoryCost = Config.onedConf.DEFAULT_COST.MEMORY_COST;
|
||||
}
|
||||
|
||||
if ((cpuCost != 0 || memoryCost != 0) && Config.isFeatureEnabled("showback")) {
|
||||
|
@ -48,8 +48,8 @@ define(function(require) {
|
||||
this.options.auth_driver = true;
|
||||
}
|
||||
|
||||
if (Config.authMadConf !== undefined && Config.authMadConf['AUTHN'] !== undefined) {
|
||||
this.authMadNameList = Config.authMadConf['AUTHN'].split(',');
|
||||
if (Config.onedConf.AUTH_MAD !== undefined && Config.onedConf.AUTH_MAD['AUTHN'] !== undefined) {
|
||||
this.authMadNameList = Config.onedConf.AUTH_MAD['AUTHN'].split(',');
|
||||
} else {
|
||||
this.authMadNameList = []
|
||||
}
|
||||
|
@ -82,11 +82,11 @@ define(function(require) {
|
||||
var memoryCost = this.element.TEMPLATE.MEMORY_COST;
|
||||
|
||||
if (cpuCost == undefined){
|
||||
cpuCost = Config.defaultCost.cpuCost;
|
||||
cpuCost = Config.onedConf.DEFAULT_COST.CPU_COST;
|
||||
}
|
||||
|
||||
if (memoryCost == undefined){
|
||||
memoryCost = Config.defaultCost.memoryCost;
|
||||
memoryCost = Config.onedConf.DEFAULT_COST.MEMORY_COST;
|
||||
}
|
||||
|
||||
return TemplateInfo({
|
||||
|
@ -72,7 +72,7 @@ define(function(require) {
|
||||
var diskCost = this.element.TEMPLATE.DISK_COST;
|
||||
|
||||
if (diskCost == undefined){
|
||||
diskCost = Config.defaultCost.diskCost;
|
||||
diskCost = Config.onedConf.DEFAULT_COST.DISK_COST;
|
||||
}
|
||||
|
||||
return TemplateHtml({
|
||||
|
@ -77,7 +77,7 @@ define(function(require){
|
||||
var disk_cost = template_json.VMTEMPLATE.TEMPLATE.DISK_COST;
|
||||
|
||||
if (disk_cost == undefined) {
|
||||
disk_cost = Config.defaultCost.diskCost;
|
||||
disk_cost = Config.onedConf.DEFAULT_COST.DISK_COST;
|
||||
}
|
||||
|
||||
if (disk_cost != 0 && Config.isFeatureEnabled("showback")) {
|
||||
|
@ -56,6 +56,13 @@ GROUP_ADMIN_DEFAULT_VIEW_XPATH = 'TEMPLATE/SUNSTONE/GROUP_ADMIN_DEFAULT_VIEW'
|
||||
TABLE_DEFAULT_PAGE_LENGTH_XPATH = 'TEMPLATE/SUNSTONE/TABLE_DEFAULT_PAGE_LENGTH'
|
||||
LANG_XPATH = 'TEMPLATE/SUNSTONE/LANG'
|
||||
|
||||
# If no costs are defined in oned.conf these values will be used
|
||||
DEFAULT_COST = {
|
||||
'CPU_COST' => 0,
|
||||
'MEMORY_COST' => 0,
|
||||
'DISK_COST' => 0
|
||||
};
|
||||
|
||||
##############################################################################
|
||||
# Required libraries
|
||||
##############################################################################
|
||||
@ -388,9 +395,42 @@ get '/' do
|
||||
error 500, ""
|
||||
end
|
||||
|
||||
serveradmin_client = $cloud_auth.client(nil, session[:active_zone_endpoint])
|
||||
|
||||
rc = OpenNebula::System.new(serveradmin_client).get_configuration
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
logger.error { rc.message }
|
||||
error 500, ""
|
||||
end
|
||||
|
||||
oned_conf_template = rc.to_hash()['TEMPLATE']
|
||||
|
||||
keys = [
|
||||
:DEFAULT_COST,
|
||||
:DS_MAD_CONF,
|
||||
:MARKET_MAD_CONF,
|
||||
:VM_MAD,
|
||||
:IM_MAD,
|
||||
:AUTH_MAD
|
||||
]
|
||||
|
||||
oned_conf = {}
|
||||
keys.each do |key|
|
||||
if key == :DEFAULT_COST
|
||||
if oned_conf_template[key.to_s]
|
||||
oned_conf[key] = oned_conf_template[key.to_s]
|
||||
else
|
||||
oned_conf[key] = DEFAULT_COST
|
||||
end
|
||||
else
|
||||
oned_conf[key] = oned_conf_template[key.to_s]
|
||||
end
|
||||
end
|
||||
|
||||
response.set_cookie("one-user", :value=>"#{session[:user]}")
|
||||
|
||||
erb :index, :locals => {:logos_conf => logos_conf}
|
||||
erb :index, :locals => {:logos_conf => logos_conf, :oned_conf => oned_conf}
|
||||
end
|
||||
|
||||
get '/login' do
|
||||
@ -513,35 +553,6 @@ get '/infrastructure' do
|
||||
[200, infrastructure.to_json]
|
||||
end
|
||||
|
||||
get '/onedconf' do
|
||||
serveradmin_client = $cloud_auth.client(nil, session[:active_zone_endpoint])
|
||||
|
||||
rc = OpenNebula::System.new(serveradmin_client).get_configuration
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
logger.error { rc.message }
|
||||
error 500, ""
|
||||
end
|
||||
|
||||
onedconf_template = rc.to_hash()['TEMPLATE']
|
||||
|
||||
keys = [
|
||||
:DEFAULT_COST,
|
||||
:DS_MAD_CONF,
|
||||
:MARKET_MAD_CONF,
|
||||
:VM_MAD,
|
||||
:IM_MAD,
|
||||
:AUTH_MAD
|
||||
]
|
||||
|
||||
onedconf = {}
|
||||
keys.each do |key|
|
||||
onedconf[key] = onedconf_template[key.to_s]
|
||||
end
|
||||
|
||||
[200, onedconf.to_json]
|
||||
end
|
||||
|
||||
get '/vm/:id/log' do
|
||||
@SunstoneServer.get_vm_log(params[:id])
|
||||
end
|
||||
|
@ -43,7 +43,8 @@
|
||||
'zone_name' : '<%= session[:zone_name] %>',
|
||||
'instance_types' : JSON.parse('<%= cloud_view_instance_types().to_json %>'),
|
||||
'page_length' : '<%= session[:page_length] %>',
|
||||
'vm_logos' : <%= logos_conf.to_json %>
|
||||
'vm_logos' : <%= logos_conf.to_json %>,
|
||||
'oned_conf' : <%= oned_conf.to_json %>
|
||||
};
|
||||
</script>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user