mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-30 22:50:10 +03:00
Feature #4215: Select a VM Template from the VR create wizard
This commit is contained in:
parent
4c68cd7c9e
commit
59267f1f86
@ -167,6 +167,8 @@ define(function(require) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: VR edges with floating IPs
|
||||
|
||||
$.each(vrs, function(j,vr){
|
||||
var nodeId = "vr"+vr;
|
||||
|
||||
@ -226,6 +228,25 @@ define(function(require) {
|
||||
label = lease.IP;
|
||||
}
|
||||
|
||||
edges.push({from: vnetNodeId, to: nodeId, label: label});
|
||||
} else if (lease.VROUTER != undefined){
|
||||
var nodeId = "vr"+lease.VROUTER;
|
||||
|
||||
if (!nodeIndex[nodeId]){
|
||||
nodeIndex[nodeId] = true;
|
||||
nodes.push({
|
||||
id: nodeId,
|
||||
label: "VR "+vr,
|
||||
group: "vr"});
|
||||
}
|
||||
|
||||
var label = undefined;
|
||||
|
||||
// TODO: IPv6 IPs
|
||||
if (lease.IP != undefined){
|
||||
label = lease.IP;
|
||||
}
|
||||
|
||||
edges.push({from: vnetNodeId, to: nodeId, label: label});
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,13 @@ define(function(require) {
|
||||
var Locale = require('utils/locale');
|
||||
var Tips = require('utils/tips');
|
||||
var TemplateUtils = require('utils/template-utils');
|
||||
var UserInputs = require('utils/user-inputs');
|
||||
var WizardFields = require('utils/wizard-fields');
|
||||
var NicsSection = require('utils/nics-section');
|
||||
var TemplatesTable = require('tabs/templates-tab/datatable');
|
||||
var OpenNebulaVirtualRouter = require('opennebula/virtualrouter');
|
||||
var OpenNebulaTemplate = require('opennebula/template');
|
||||
var Notifier = require('utils/notifier');
|
||||
|
||||
/*
|
||||
TEMPLATES
|
||||
@ -53,14 +59,11 @@ define(function(require) {
|
||||
'title': Locale.tr("Create Virtual Router"),
|
||||
'buttonText': Locale.tr("Create"),
|
||||
'resetButton': true
|
||||
},
|
||||
'update': {
|
||||
'title': Locale.tr("Update Virtual Router"),
|
||||
'buttonText': Locale.tr("Update"),
|
||||
'resetButton': false
|
||||
}
|
||||
};
|
||||
|
||||
this.templatesTable = new TemplatesTable('vr_create', {'select': true});
|
||||
|
||||
BaseFormPanel.call(this);
|
||||
}
|
||||
|
||||
@ -72,7 +75,6 @@ define(function(require) {
|
||||
FormPanel.prototype.submitWizard = _submitWizard;
|
||||
FormPanel.prototype.submitAdvanced = _submitAdvanced;
|
||||
FormPanel.prototype.onShow = _onShow;
|
||||
FormPanel.prototype.fill = _fill;
|
||||
FormPanel.prototype.setup = _setup;
|
||||
|
||||
return FormPanel;
|
||||
@ -83,7 +85,8 @@ define(function(require) {
|
||||
|
||||
function _htmlWizard() {
|
||||
return TemplateWizardHTML({
|
||||
'formPanelId': this.formPanelId
|
||||
'formPanelId': this.formPanelId,
|
||||
'templatesTableHTML': this.templatesTable.dataTableHTML
|
||||
});
|
||||
}
|
||||
|
||||
@ -94,35 +97,115 @@ define(function(require) {
|
||||
function _setup(context) {
|
||||
var that = this;
|
||||
|
||||
NicsSection.insert({}, $(".nicsContext", context));
|
||||
|
||||
this.templatesTable.initialize();
|
||||
|
||||
this.templatesTable.idInput().attr("required", "");
|
||||
|
||||
this.templatesTable.idInput().on("change", function(){
|
||||
var templateId = $(this).val();
|
||||
|
||||
var inputs_div = $(".template_user_inputs", context);
|
||||
inputs_div.empty();
|
||||
|
||||
OpenNebulaTemplate.show({
|
||||
data : {
|
||||
id: templateId
|
||||
},
|
||||
timeout: true,
|
||||
success: function (request, template_json) {
|
||||
UserInputs.vmTemplateInsert(
|
||||
inputs_div,
|
||||
template_json,
|
||||
{text_header: '<i class="fa fa-gears fa-lg"></i> '+Locale.tr("Custom Attributes")});
|
||||
},
|
||||
error: Notifier.onError
|
||||
});
|
||||
});
|
||||
|
||||
$(".vr_attributes #name", context).on("input", function(){
|
||||
$('#vm_name', context).val("vr-"+$(this).val()+"-%i");
|
||||
});
|
||||
|
||||
Tips.setup();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function _submitWizard(context) {
|
||||
var virtual_router_json = WizardFields.retrieve($(".vr_attributes", context));
|
||||
|
||||
var name = $('#virtual_router_name', context).val();
|
||||
var description = $('#virtual_router_description', context).val();
|
||||
var nics = NicsSection.retrieve($(".nicsContext", context));
|
||||
if (nics.length > 0) {
|
||||
// TODO: Instead of a global checkbox, each vnet should have
|
||||
// its own checkbox to choose floating IP or not
|
||||
$.each(nics, function(){
|
||||
this["FLOATING_IP"] = virtual_router_json["FLOATING_IP"];
|
||||
});
|
||||
|
||||
var virtual_router_json = {
|
||||
"NAME" : name,
|
||||
"DESCRIPTION": description
|
||||
};
|
||||
virtual_router_json.NIC = nics;
|
||||
}
|
||||
|
||||
var tmplId = this.templatesTable.retrieveResourceTableSelect();
|
||||
|
||||
if (this.action == "create") {
|
||||
virtual_router_json = {
|
||||
"virtual_router" : virtual_router_json
|
||||
};
|
||||
|
||||
Sunstone.runAction("VirtualRouter.create",virtual_router_json);
|
||||
return false;
|
||||
} else if (this.action == "update") {
|
||||
delete virtual_router_json["NAME"];
|
||||
var vm_name = $('#vm_name', context).val();
|
||||
var n_times = parseInt($('#vm_n_times', context).val());
|
||||
|
||||
Sunstone.runAction(
|
||||
"VirtualRouter.update",
|
||||
this.resourceId,
|
||||
TemplateUtils.templateToString(virtual_router_json));
|
||||
if (isNaN(n_times)){
|
||||
n_times = 1;
|
||||
}
|
||||
|
||||
var hold = $('#hold', context).prop("checked");
|
||||
|
||||
OpenNebulaVirtualRouter.create({
|
||||
data : virtual_router_json,
|
||||
timeout: true,
|
||||
success: function (request, response) {
|
||||
|
||||
// TODO: close form panel only on instantiate success
|
||||
Sunstone.resetFormPanel(TAB_ID, FORM_PANEL_ID);
|
||||
Sunstone.hideFormPanel(TAB_ID);
|
||||
|
||||
var extra_msg = "";
|
||||
if (n_times > 1) {
|
||||
extra_msg = n_times + " times";
|
||||
}
|
||||
|
||||
Notifier.notifySubmit("Template.instantiate", tmplId, extra_msg);
|
||||
|
||||
var extra_info = {
|
||||
'hold': hold
|
||||
};
|
||||
|
||||
var tmpl = WizardFields.retrieve($(".template_user_inputs", context));
|
||||
tmpl["VROUTER_ID"] = response.VROUTER.ID;
|
||||
|
||||
extra_info['template'] = tmpl;
|
||||
|
||||
for (var i = 0; i < n_times; i++) {
|
||||
extra_info['vm_name'] = vm_name.replace(/%i/gi, i);
|
||||
|
||||
OpenNebulaTemplate.instantiate({
|
||||
data:{
|
||||
id: tmplId,
|
||||
extra_param: extra_info
|
||||
},
|
||||
timeout: true,
|
||||
error: Notifier.onError
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function(request, response) {
|
||||
Sunstone.hideFormPanelLoading(TAB_ID);
|
||||
Notifier.onError(request, response);
|
||||
},
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -134,29 +217,10 @@ define(function(require) {
|
||||
var virtual_router_json = {virtual_router: {virtual_router_raw: template}};
|
||||
Sunstone.runAction("VirtualRouter.create",virtual_router_json);
|
||||
return false;
|
||||
} else if (this.action == "update") {
|
||||
var template_raw = $('textarea#template', context).val();
|
||||
Sunstone.runAction("VirtualRouter.update", this.resourceId, template_raw);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function _onShow(context) {
|
||||
}
|
||||
|
||||
function _fill(context, element) {
|
||||
var that = this;
|
||||
|
||||
this.resourceId = element.ID;
|
||||
|
||||
// Populates the Avanced mode Tab
|
||||
$('#template', context).val(TemplateUtils.templateToString(element.TEMPLATE).replace(/^[\r\n]+$/g, ""));
|
||||
|
||||
$('#virtual_router_name',context).val(
|
||||
TemplateUtils.escapeDoubleQuotes(TemplateUtils.htmlDecode( element.NAME ))).
|
||||
prop("disabled", true);
|
||||
|
||||
$('#virtual_router_description', context).val(
|
||||
TemplateUtils.escapeDoubleQuotes(TemplateUtils.htmlDecode( element.TEMPLATE.DESCRIPTION )) );
|
||||
this.templatesTable.refreshResourceTableSelect();
|
||||
}
|
||||
});
|
||||
|
@ -16,18 +16,81 @@
|
||||
|
||||
<div id="create_virtual_router_form_wrapper">
|
||||
<form data-abide="ajax" id="{{formPanelId}}Wizard" class="custom creation">
|
||||
<div class="row">
|
||||
<div class="medium-4 columns">
|
||||
<label for="virtual_router_name">{{tr "Virtual Router Name"}}:</label>
|
||||
<input required type="text" name="virtual_router_name" id="virtual_router_name"/>
|
||||
<div class="vr_attributes">
|
||||
<div class="row">
|
||||
<div class="medium-6 columns">
|
||||
<label for="name" >
|
||||
{{tr "Name"}}:
|
||||
</label>
|
||||
<input type="text" wizard_field="NAME" required name="name" id="name"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="medium-8 columns">
|
||||
<label for="virtual_router_description">{{tr "Description"}}
|
||||
<span class="tip">{{tr "Description for the Virtual Router"}}</span>
|
||||
</label>
|
||||
<textarea type="text" id="virtual_router_description" name="virtual_router_description" style="height: 70px;"/>
|
||||
<div class="row">
|
||||
<div class="medium-6 columns">
|
||||
<label for="DESCRIPTION" >
|
||||
{{tr "Description"}}
|
||||
<span class="tip">{{tr "Description of the Virtual Router"}}</span>
|
||||
</label>
|
||||
<textarea type="text" wizard_field="DESCRIPTION" id="DESCRIPTION" name="DESCRIPTION"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="medium-6 columns">
|
||||
<label for="floating_ip">
|
||||
<input type="checkbox" wizard_field="FLOATING_IP" value="YES" name="floating_ip" id="floating_ip" />
|
||||
{{tr "Floating IPs"}}
|
||||
<span class="tip">
|
||||
{{tr "If checked, each Virtual Machine will have a floating IP added to its network interface."}}
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
<div class="row">
|
||||
<div class="large-12 columns nicsContext">
|
||||
<div class="provision_network_selector">
|
||||
</div>
|
||||
<br>
|
||||
</div>
|
||||
</div>
|
||||
<br/>
|
||||
<div class="row">
|
||||
{{{templatesTableHTML}}}
|
||||
</div>
|
||||
{{!TODO: duplicated html from templates-tab/form-panels/instantiate/html.hbs}}
|
||||
<div class="row nameContainer">
|
||||
<div class="medium-4 columns">
|
||||
<label for="vm_name">
|
||||
{{tr "VM Name"}}
|
||||
<span class="tip">
|
||||
{{tr "Defaults to template name when emtpy. You can use the wildcard %i. When creating several VMs, %i will be replaced with a different number starting from 0 in each of them"}}.
|
||||
</span>
|
||||
</label>
|
||||
<input type="text" name="vm_name" id="vm_name" />
|
||||
</div>
|
||||
<div class="medium-4 columns">
|
||||
<label for="vm_n_times">
|
||||
{{tr "Number of instances"}}
|
||||
<span class="tip">
|
||||
{{tr "Number of Virtual Machines that will be created using this template"}}.
|
||||
</span>
|
||||
</label>
|
||||
<input type="text" name="vm_n_times" id="vm_n_times" value="1">
|
||||
</div>
|
||||
<div class="medium-4 columns">
|
||||
<input type="checkbox" name="hold" id="hold"/>
|
||||
<label for="hold">
|
||||
{{tr "Hold"}}
|
||||
<span class="tip">
|
||||
{{tr "Sets the new VM to hold state, instead of pending. The scheduler will not deploy VMs in this state. It can be released later, or deployed manually."}}
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="large-12 columns large-centered template_user_inputs">
|
||||
</div>
|
||||
<br>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -30,22 +30,27 @@ define(function(require) {
|
||||
}
|
||||
|
||||
function _insert(template_json, context) {
|
||||
if (template_json.VMTEMPLATE.TEMPLATE.SUNSTONE_NETWORK_SELECT != "NO") {
|
||||
var template_nic = template_json.VMTEMPLATE.TEMPLATE.NIC
|
||||
var nics = []
|
||||
if ($.isArray(template_nic))
|
||||
nics = template_nic
|
||||
else if (!$.isEmptyObject(template_nic))
|
||||
nics = [template_nic]
|
||||
|
||||
try {
|
||||
if (template_json.VMTEMPLATE.TEMPLATE.SUNSTONE_NETWORK_SELECT != "NO") {
|
||||
var template_nic = template_json.VMTEMPLATE.TEMPLATE.NIC
|
||||
var nics = []
|
||||
if ($.isArray(template_nic))
|
||||
nics = template_nic
|
||||
else if (!$.isEmptyObject(template_nic))
|
||||
nics = [template_nic]
|
||||
|
||||
_generate_provision_network_accordion(
|
||||
$(".provision_network_selector", context));
|
||||
|
||||
$.each(nics, function(index, nic) {
|
||||
_generate_provision_network_table(
|
||||
$(".provision_nic_accordion", context),
|
||||
nic);
|
||||
})
|
||||
}
|
||||
} catch(err) {
|
||||
_generate_provision_network_accordion(
|
||||
$(".provision_network_selector", context));
|
||||
|
||||
$.each(nics, function(index, nic) {
|
||||
_generate_provision_network_table(
|
||||
$(".provision_nic_accordion", context),
|
||||
nic);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user