mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Feature #3748: Oneflow template instantiate
This commit is contained in:
parent
e02101156d
commit
dadf4737ce
@ -18,7 +18,8 @@ define(function(require) {
|
||||
];
|
||||
|
||||
var _formPanels = [
|
||||
require('./oneflow-templates-tab/form-panels/create')
|
||||
require('./oneflow-templates-tab/form-panels/create'),
|
||||
require('./oneflow-templates-tab/form-panels/instantiate')
|
||||
];
|
||||
|
||||
var Tab = {
|
||||
|
@ -7,7 +7,7 @@ define(function(require) {
|
||||
|
||||
var TAB_ID = require('./tabId');
|
||||
var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId');
|
||||
//var INSTANTIATE_DIALOG_ID = require('./dialogs/instantiate/dialogId');
|
||||
var INSTANTIATE_DIALOG_ID = require('./form-panels/instantiate/formPanelId');
|
||||
var XML_ROOT = "DOCUMENT";
|
||||
var RESOURCE = "ServiceTemplate";
|
||||
|
||||
@ -93,26 +93,39 @@ define(function(require) {
|
||||
}
|
||||
},
|
||||
|
||||
/* TODO
|
||||
|
||||
"ServiceTemplate.instantiate" : {
|
||||
type: "multiple",
|
||||
call: OpenNebula.ServiceTemplate.instantiate,
|
||||
callback: function(req){
|
||||
OpenNebula.Helper.clear_cache("SERVICE");
|
||||
},
|
||||
elements: serviceTemplateElements,
|
||||
error: onError,
|
||||
notify: true
|
||||
type: "multiple",
|
||||
call: OpenNebulaResource.instantiate,
|
||||
callback: function(request, response){
|
||||
Sunstone.hideFormPanel(TAB_ID);
|
||||
|
||||
// TODO
|
||||
//OpenNebulaHelper.clear_cache("SERVICE");
|
||||
},
|
||||
elements: function() {
|
||||
return Sunstone.getDataTable(TAB_ID).elements();
|
||||
},
|
||||
error: function(request, response){
|
||||
Sunstone.hideFormPanelLoading(TAB_ID);
|
||||
Notifier.onError(request, response);
|
||||
},
|
||||
notify: true
|
||||
},
|
||||
|
||||
"ServiceTemplate.instantiate_dialog" : {
|
||||
type: "custom",
|
||||
call: function(){
|
||||
popUpInstantiateServiceTemplateDialog();
|
||||
type: "custom",
|
||||
call: function() {
|
||||
var selected_nodes = Sunstone.getDataTable(TAB_ID).elements();
|
||||
if (selected_nodes.length != 1) {
|
||||
Notifier.notifyMessage("Please select one (and just one) template to instantiate.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Sunstone.resetFormPanel(TAB_ID, INSTANTIATE_DIALOG_ID);
|
||||
Sunstone.showFormPanel(TAB_ID, INSTANTIATE_DIALOG_ID, "instantiate");
|
||||
}
|
||||
},
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
return _actions;
|
||||
|
@ -0,0 +1,232 @@
|
||||
define(function(require) {
|
||||
/*
|
||||
DEPENDENCIES
|
||||
*/
|
||||
|
||||
require('foundation.tab');
|
||||
var BaseFormPanel = require('utils/form-panels/form-panel');
|
||||
var Sunstone = require('sunstone');
|
||||
var Locale = require('utils/locale');
|
||||
var Tips = require('utils/tips');
|
||||
var OpenNebulaServiceTemplate = require('opennebula/servicetemplate');
|
||||
var OpenNebulaTemplate = require('opennebula/template');
|
||||
var Notifier = require('utils/notifier');
|
||||
var WizardFields = require('utils/wizard-fields');
|
||||
var TemplateUtils = require('utils/template-utils');
|
||||
var UserInputs = require('utils/user-inputs');
|
||||
|
||||
/*
|
||||
TEMPLATES
|
||||
*/
|
||||
|
||||
var TemplateHTML = require('hbs!./instantiate/html');
|
||||
|
||||
/*
|
||||
CONSTANTS
|
||||
*/
|
||||
|
||||
var FORM_PANEL_ID = require('./instantiate/formPanelId');
|
||||
var TAB_ID = require('../tabId');
|
||||
|
||||
/*
|
||||
CONSTRUCTOR
|
||||
*/
|
||||
|
||||
function FormPanel() {
|
||||
this.formPanelId = FORM_PANEL_ID;
|
||||
this.tabId = TAB_ID;
|
||||
this.actions = {
|
||||
'instantiate': {
|
||||
'title': Locale.tr("Instantiate Service Template"),
|
||||
'buttonText': Locale.tr("Instantiate"),
|
||||
'resetButton': false
|
||||
}
|
||||
};
|
||||
|
||||
BaseFormPanel.call(this);
|
||||
}
|
||||
|
||||
FormPanel.FORM_PANEL_ID = FORM_PANEL_ID;
|
||||
FormPanel.prototype = Object.create(BaseFormPanel.prototype);
|
||||
FormPanel.prototype.constructor = FormPanel;
|
||||
FormPanel.prototype.htmlWizard = _html;
|
||||
FormPanel.prototype.submitWizard = _submitWizard;
|
||||
FormPanel.prototype.onShow = _onShow;
|
||||
FormPanel.prototype.fill = _fill;
|
||||
FormPanel.prototype.setup = _setup;
|
||||
|
||||
return FormPanel;
|
||||
|
||||
/*
|
||||
FUNCTION DEFINITIONS
|
||||
*/
|
||||
|
||||
function _html() {
|
||||
return TemplateHTML({
|
||||
'formPanelId': this.formPanelId
|
||||
});
|
||||
}
|
||||
|
||||
function _setup(context) {
|
||||
var that = this;
|
||||
|
||||
Tips.setup(context);
|
||||
return false;
|
||||
}
|
||||
|
||||
function _onShow(context) {
|
||||
var that = this;
|
||||
|
||||
Sunstone.disableFormPanelSubmit(TAB_ID);
|
||||
|
||||
var selected_nodes = Sunstone.getDataTable(TAB_ID).elements();
|
||||
var template_id = ""+selected_nodes[0];
|
||||
|
||||
this.service_template_json = {};
|
||||
|
||||
OpenNebulaServiceTemplate.show({
|
||||
data : {
|
||||
id: template_id
|
||||
},
|
||||
timeout: true,
|
||||
success: function (request, template_json){
|
||||
|
||||
that.service_template_json = template_json;
|
||||
|
||||
$("#instantiate_service_user_inputs", context).empty();
|
||||
|
||||
UserInputs.serviceTemplateInsert(
|
||||
$("#instantiate_service_user_inputs", context),
|
||||
template_json);
|
||||
|
||||
n_roles = template_json.DOCUMENT.TEMPLATE.BODY.roles.length;
|
||||
n_roles_done = 0;
|
||||
|
||||
$.each(template_json.DOCUMENT.TEMPLATE.BODY.roles, function(index, role){
|
||||
var div_id = "user_input_role_"+index;
|
||||
|
||||
$("#instantiate_service_role_user_inputs", context).append(
|
||||
'<div id="'+div_id+'" class="large-6 columns">\
|
||||
</div>'
|
||||
);
|
||||
|
||||
OpenNebulaTemplate.show({
|
||||
data : {
|
||||
id: role.vm_template
|
||||
},
|
||||
timeout: true,
|
||||
success: function (request, vm_template_json){
|
||||
|
||||
$("#"+div_id, context).empty();
|
||||
|
||||
UserInputs.vmTemplateInsert(
|
||||
$("#"+div_id, context),
|
||||
vm_template_json,
|
||||
{
|
||||
text_header: Locale.tr("Role") + " " + role.name
|
||||
}
|
||||
);
|
||||
|
||||
n_roles_done += 1;
|
||||
|
||||
if(n_roles_done == n_roles){
|
||||
Sunstone.enableFormPanelSubmit(TAB_ID);
|
||||
}
|
||||
},
|
||||
error: function(request,error_json, container){
|
||||
Notifier.onError(request,error_json, container);
|
||||
$("#instantiate_vm_user_inputs", context).empty();
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
error: function(request,error_json, container){
|
||||
Notifier.onError(request,error_json, container);
|
||||
$("#instantiate_service_user_inputs", context).empty();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function _submitWizard(context) {
|
||||
var that = this;
|
||||
|
||||
var service_name = $('#service_name',context).val();
|
||||
var n_times = $('#service_n_times',context).val();
|
||||
var n_times_int=1;
|
||||
|
||||
var template_id;
|
||||
if ($("#TEMPLATE_ID", context).val()) {
|
||||
template_id = $("#TEMPLATE_ID", context).val();
|
||||
} else {
|
||||
var selected_nodes = Sunstone.getDataTable(TAB_ID).elements();
|
||||
template_id = ""+selected_nodes[0];
|
||||
}
|
||||
|
||||
if (n_times.length){
|
||||
n_times_int=parseInt(n_times,10);
|
||||
}
|
||||
|
||||
var extra_msg = "";
|
||||
if (n_times_int > 1) {
|
||||
extra_msg = n_times_int+" times";
|
||||
}
|
||||
|
||||
var extra_info = {
|
||||
'merge_template': {}
|
||||
};
|
||||
|
||||
var tmp_json = WizardFields.retrieve($("#instantiate_service_user_inputs", context));
|
||||
|
||||
extra_info.merge_template.custom_attrs_values = tmp_json;
|
||||
|
||||
extra_info.merge_template.roles = [];
|
||||
|
||||
$.each(that.service_template_json.DOCUMENT.TEMPLATE.BODY.roles, function(index, role){
|
||||
var div_id = "user_input_role_"+index;
|
||||
|
||||
tmp_json = {};
|
||||
|
||||
$.extend( tmp_json, WizardFields.retrieve($("#"+div_id, context)) );
|
||||
|
||||
$.each(role.elasticity_policies, function(i, pol){
|
||||
pol.expression = TemplateUtils.htmlDecode(pol.expression);
|
||||
});
|
||||
|
||||
role.user_inputs_values = tmp_json;
|
||||
|
||||
extra_info.merge_template.roles.push(role);
|
||||
});
|
||||
|
||||
if (!service_name.length){ //empty name
|
||||
for (var i=0; i< n_times_int; i++){
|
||||
Sunstone.runAction("ServiceTemplate.instantiate", [template_id], extra_info);
|
||||
}
|
||||
} else {
|
||||
if (service_name.indexOf("%i") == -1){//no wildcard, all with the same name
|
||||
extra_info['merge_template']['name'] = service_name;
|
||||
|
||||
for (var i=0; i< n_times_int; i++){
|
||||
Sunstone.runAction(
|
||||
"ServiceTemplate.instantiate",
|
||||
[template_id], extra_info);
|
||||
}
|
||||
} else { //wildcard present: replace wildcard
|
||||
for (var i=0; i< n_times_int; i++){
|
||||
extra_info['merge_template']['name'] = service_name.replace(/%i/gi,i);
|
||||
|
||||
Sunstone.runAction(
|
||||
"ServiceTemplate.instantiate",
|
||||
[template_id], extra_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function _fill(context, element) {
|
||||
var that = this;
|
||||
}
|
||||
|
||||
});
|
@ -0,0 +1,3 @@
|
||||
define(function(require){
|
||||
return 'instantiateServiceTemplateForm';
|
||||
});
|
@ -0,0 +1,21 @@
|
||||
<form data-abide="ajax" id="{{formPanelId}}Wizard" class="custom creation">
|
||||
<div class="row">
|
||||
<div class="large-6 columns">
|
||||
<label for="service_name">{{tr "Service Name"}}
|
||||
<span class="tip">{{tr "Defaults to template name when emtpy. You can use the wildcard %i. When creating several Services, %i will be replaced with a different number starting from 0 in each of them"}}.</span>
|
||||
</label>
|
||||
<input type="text" name="service_name" id="service_name" />
|
||||
</div>
|
||||
<div class="large-6 columns">
|
||||
<label for="service_n_times">{{tr "Number of instances"}}
|
||||
<span class="tip">{{tr "Number of Services that will be created using this template"}}.</span>
|
||||
</label>
|
||||
<input type="text" name="service_n_times" id="service_n_times" value="1">
|
||||
</div>
|
||||
</div>
|
||||
<div id="instantiate_service_user_inputs">
|
||||
<i class="fa fa-spinner fa-spin"></i>
|
||||
</div>
|
||||
<div class="row" id="instantiate_service_role_user_inputs">
|
||||
</div>
|
||||
</form>
|
Loading…
x
Reference in New Issue
Block a user