mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-22 22:03:39 +03:00
Signed-off-by: Jorge Lobo <jlobo@opennebula.io>
This commit is contained in:
parent
648fe67f15
commit
d81478e7e9
@ -38,9 +38,9 @@ define(function(require) {
|
||||
|
||||
function FormPanel() {
|
||||
InstantiateTemplateFormPanel.call(this);
|
||||
|
||||
this.formPanelId = FORM_PANEL_ID;
|
||||
this.tabId = TAB_ID;
|
||||
this.display_vmgroups = true;
|
||||
this.actions = {
|
||||
'create': {
|
||||
'title': Locale.tr("Create Service"),
|
||||
@ -48,7 +48,6 @@ define(function(require) {
|
||||
'resetButton': true
|
||||
}
|
||||
};
|
||||
|
||||
this.templatesTable = new TemplatesTable('service_create', {'select': true});
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ define(function(require) {
|
||||
var Sunstone = require("sunstone");
|
||||
var Locale = require("utils/locale");
|
||||
var Tips = require("utils/tips");
|
||||
var OpenNebulaAction = require('opennebula/action');
|
||||
var OpenNebulaServiceTemplate = require("opennebula/servicetemplate");
|
||||
var OpenNebulaTemplate = require("opennebula/template");
|
||||
var Notifier = require("utils/notifier");
|
||||
@ -45,6 +46,7 @@ define(function(require) {
|
||||
|
||||
var FORM_PANEL_ID = require("./instantiate/formPanelId");
|
||||
var TAB_ID = require("../tabId");
|
||||
var vm_group = "VM_GROUP";
|
||||
|
||||
/*
|
||||
CONSTRUCTOR
|
||||
@ -53,6 +55,7 @@ define(function(require) {
|
||||
function FormPanel() {
|
||||
this.formPanelId = FORM_PANEL_ID;
|
||||
this.tabId = TAB_ID;
|
||||
this.display_vmgroups = false;
|
||||
this.actions = {
|
||||
"instantiate": {
|
||||
"title": Locale.tr("Instantiate Service Template"),
|
||||
@ -87,12 +90,15 @@ define(function(require) {
|
||||
|
||||
function _setup(context) {
|
||||
var that = this;
|
||||
|
||||
Tips.setup(context);
|
||||
return false;
|
||||
}
|
||||
|
||||
function _onShow(context) {
|
||||
var vmgroups = OpenNebulaAction.cache(vm_group)
|
||||
if(!vmgroups){
|
||||
Sunstone.runAction("VMGroup.list");
|
||||
}
|
||||
}
|
||||
|
||||
function _setTemplateId(context, templateId) {
|
||||
@ -116,10 +122,20 @@ define(function(require) {
|
||||
n_roles = template_json.DOCUMENT.TEMPLATE.BODY.roles.length;
|
||||
n_roles_done = 0;
|
||||
var total_cost = 0;
|
||||
var vmgroup_title = Locale.tr("Associate VM Group to Service");
|
||||
var setDisplayTitle = function(value=""){
|
||||
vmgroup_title = value
|
||||
}
|
||||
$.each(template_json.DOCUMENT.TEMPLATE.BODY.roles, function(index, role){
|
||||
var div_id = "user_input_role_"+index;
|
||||
if(vmgroup_title && that.display_vmgroups){
|
||||
$("#instantiate_service_role_user_inputs", context).empty().prepend(
|
||||
$("<legend/>").text(vmgroup_title)
|
||||
);
|
||||
setDisplayTitle("");
|
||||
}
|
||||
$("#instantiate_service_role_user_inputs", context).append(
|
||||
"<div id=\""+div_id+"\" class=\"large-6 columns\"></div>"
|
||||
$("<div/>",{id:div_id, class:"large-6 columns"})
|
||||
);
|
||||
OpenNebulaTemplate.show({
|
||||
data : {
|
||||
@ -168,12 +184,26 @@ define(function(require) {
|
||||
$(".total_cost_div", context).show();
|
||||
$(".total_cost_div .cost_value", context).text((total_cost).toFixed(4));
|
||||
}
|
||||
|
||||
var opts = {
|
||||
text_header: Locale.tr("Role") + " " + role.name
|
||||
};
|
||||
//vmgroups
|
||||
if(that.display_vmgroups){
|
||||
var vmgroups = OpenNebulaAction.cache(vm_group);
|
||||
if(vmgroups && vmgroups.data){
|
||||
opts.vmgroups = vmgroups.data;
|
||||
opts.role = role.name;
|
||||
if(!Array.isArray(vmgroups.data)){
|
||||
opts.vmgroups = [vmgroups.data];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UserInputs.vmTemplateInsert(
|
||||
$("#"+div_id, context),
|
||||
vm_template_json,
|
||||
{
|
||||
text_header: Locale.tr("Role") + " " + role.name
|
||||
}
|
||||
opts
|
||||
);
|
||||
n_roles_done += 1;
|
||||
if(n_roles_done === n_roles){
|
||||
@ -206,21 +236,40 @@ define(function(require) {
|
||||
|
||||
var extra_info = ServiceUtils.getExtraInfo(context);
|
||||
|
||||
$.each(that.service_template_json.DOCUMENT.TEMPLATE.BODY.roles, function(index, role){
|
||||
var div_id = "user_input_role_"+index;
|
||||
var tmp_json = {};
|
||||
var stringCustomValues = TemplateUtils.templateToString(extra_info.merge_template.custom_attrs_values);
|
||||
|
||||
$.extend( tmp_json, WizardFields.retrieve($("#"+div_id, context)) );
|
||||
role.user_inputs_values = tmp_json;
|
||||
if (stringCustomValues) {
|
||||
(role.vm_template_contents)
|
||||
? role.vm_template_contents += stringCustomValues
|
||||
: role.vm_template_contents = stringCustomValues;
|
||||
}
|
||||
extra_info.merge_template.roles.push(role);
|
||||
});
|
||||
|
||||
if(
|
||||
that &&
|
||||
that.service_template_json &&
|
||||
that.service_template_json.DOCUMENT &&
|
||||
that.service_template_json.DOCUMENT.TEMPLATE &&
|
||||
that.service_template_json.DOCUMENT.TEMPLATE.BODY &&
|
||||
that.service_template_json.DOCUMENT.TEMPLATE.BODY.roles
|
||||
){
|
||||
$.each(that.service_template_json.DOCUMENT.TEMPLATE.BODY.roles, function(index, role){
|
||||
var temp_role = role;
|
||||
var div_id = "user_input_role_"+index;
|
||||
var tmp_json = {};
|
||||
var stringCustomValues = TemplateUtils.templateToString(extra_info.merge_template.custom_attrs_values);
|
||||
$.extend( tmp_json, WizardFields.retrieve($("#"+div_id, context)) );
|
||||
role.user_inputs_values = tmp_json;
|
||||
if (stringCustomValues) {
|
||||
(temp_role.vm_template_contents)
|
||||
? temp_role.vm_template_contents += stringCustomValues
|
||||
: temp_role.vm_template_contents = stringCustomValues;
|
||||
}
|
||||
$("#instantiate_service_role_user_inputs").find("select").each(function(key, vm_group){
|
||||
var element = $(vm_group);
|
||||
rolevm_group = element.attr("data-role");
|
||||
vm_group_value = element.children("option:selected").val();
|
||||
if(rolevm_group && role.name && rolevm_group === role.name && vm_group_value){
|
||||
if(temp_role.vm_template_contents === undefined){
|
||||
temp_role.vm_template_contents = "";
|
||||
}
|
||||
temp_role.vm_template_contents += TemplateUtils.templateToString({VMGROUP:{ROLE:role.name,VMGROUP_ID:vm_group_value}});
|
||||
}
|
||||
});
|
||||
extra_info.merge_template.roles.push(temp_role);
|
||||
});
|
||||
}
|
||||
if (!service_name.length){ //empty name
|
||||
for (var i=0; i< n_times_int; i++){
|
||||
Sunstone.runAction("ServiceTemplate.instantiate", that.templateId, extra_info);
|
||||
|
@ -43,7 +43,7 @@
|
||||
<div id="instantiate_service_user_inputs">
|
||||
<i class="fas fa-spinner fa-spin"></i>
|
||||
</div>
|
||||
<div class="row" id="instantiate_service_role_user_inputs">
|
||||
</div>
|
||||
<fieldset class="row" id="instantiate_service_role_user_inputs">
|
||||
</fieldset>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -27,9 +27,10 @@ define(function(require) {
|
||||
|
||||
var network_attrs = [];
|
||||
var custom_attrs = [];
|
||||
var vmgroups_attrs = [];
|
||||
var network_attrs_class = "network_attrs_class";
|
||||
var custom_attr_class = "custom_attr_class";
|
||||
|
||||
var vmgroups_attr_class = "vmgroups_class";
|
||||
|
||||
//==============================================================================
|
||||
// VM & Service user inputs
|
||||
@ -292,7 +293,8 @@ define(function(require) {
|
||||
var div = opts.div;
|
||||
var networks = opts && opts.networks ? opts.networks : null;
|
||||
var customs = opts && opts.customs ? opts.customs : null;
|
||||
var check = {networks:false, customs:false};
|
||||
var vmgroups = opts && opts.vmgroups ? opts.vmgroups : null;
|
||||
var check = {networks:false, customs:false, vmgroups:false};
|
||||
|
||||
var defaults = opts.defaults;
|
||||
if (defaults == undefined){
|
||||
@ -314,6 +316,10 @@ define(function(require) {
|
||||
opts.network_header = Locale.tr("Network");
|
||||
}
|
||||
|
||||
if (opts.vmgroups_header == undefined && vmgroups) {
|
||||
opts.vmgroups_header = Locale.tr("Vm group");
|
||||
}
|
||||
|
||||
function checkItemInArray(object={}, list=[], index="name") {
|
||||
var rtn = true;
|
||||
if(typeof object === "object" && Array.isArray(list)){
|
||||
@ -346,6 +352,10 @@ define(function(require) {
|
||||
|
||||
addInVar(networks, network_attrs);
|
||||
addInVar(customs, custom_attrs);
|
||||
if(vmgroups){
|
||||
vmgroups_attrs = vmgroups;
|
||||
check.vmgroups = true;
|
||||
}
|
||||
|
||||
// Render networks
|
||||
if (network_attrs.length > 0) {
|
||||
@ -537,9 +547,37 @@ define(function(require) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//render Vmgroups_attr_values
|
||||
if (vmgroups_attrs.length > 0 && opts.role) {
|
||||
var options = '<option value="">'+Locale.tr("Without VM Group")+'</option>';
|
||||
vmgroups_attrs.map(function(vmgroup){
|
||||
if(
|
||||
vmgroup &&
|
||||
vmgroup.VM_GROUP &&
|
||||
vmgroup.VM_GROUP.GNAME &&
|
||||
vmgroup.VM_GROUP.ID &&
|
||||
vmgroup.VM_GROUP.TEMPLATE &&
|
||||
typeof vmgroup.VM_GROUP.TEMPLATE.DESCRIPTION !== 'undefined'
|
||||
){
|
||||
options += "<option value='"+vmgroup.VM_GROUP.ID+"'>"+vmgroup.VM_GROUP.GNAME+" ("+vmgroup.VM_GROUP.TEMPLATE.DESCRIPTION+")</option>"
|
||||
}
|
||||
});
|
||||
|
||||
if (opts && opts.text_header && opts.text_header.length > 0) {
|
||||
html += "<div>"+opts.text_header+"</div>";
|
||||
}
|
||||
html += "<div class='"+vmgroups_attr_class+"'>";
|
||||
html += "<select data-role='"+opts.role+"'>"+options+"</select>";
|
||||
html += "</div>";
|
||||
div.append(html);
|
||||
html = "";
|
||||
}
|
||||
|
||||
network_attrs = [];
|
||||
custom_attrs = [];
|
||||
return (check.networks || check.customs);
|
||||
vmgroups_attrs = [];
|
||||
return (check.networks || check.customs || check.vmgroups);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user