mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-12 21:57:23 +03:00
Feature #4400: Instantiate persistent in sunstone
This commit is contained in:
parent
072deaf078
commit
9553c91471
@ -98,6 +98,8 @@ module OpenNebulaJSON
|
||||
end
|
||||
|
||||
def instantiate(params=Hash.new)
|
||||
persistent = (params['persistent'] == true)
|
||||
|
||||
if params['template']
|
||||
select_network = self['TEMPLATE/SUNSTONE/NETWORK_SELECT']
|
||||
if (select_network && select_network.upcase == "NO")
|
||||
@ -105,9 +107,9 @@ module OpenNebulaJSON
|
||||
end
|
||||
|
||||
template = template_to_str(params['template'])
|
||||
super(params['vm_name'], params['hold'], template)
|
||||
super(params['vm_name'], params['hold'], template, persistent)
|
||||
else
|
||||
super(params['vm_name'], params['hold'])
|
||||
super(params['vm_name'], params['hold'], "", persistent)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -66,6 +66,11 @@ define(function(require) {
|
||||
var action_obj = params.data.extra_param ? params.data.extra_param : {};
|
||||
OpenNebulaAction.simple_action(params, RESOURCE, "instantiate", action_obj);
|
||||
},
|
||||
"instantiate_persistent" : function(params) {
|
||||
var action_obj = params.data.extra_param ? params.data.extra_param : {};
|
||||
action_obj["persistent"] = true;
|
||||
OpenNebulaAction.simple_action(params, RESOURCE, "instantiate", action_obj);
|
||||
},
|
||||
"clone" : function(params) {
|
||||
var name = params.data.extra_param ? params.data.extra_param : "";
|
||||
var action_obj = {"name" : name};
|
||||
|
@ -72,22 +72,31 @@ define(function(require) {
|
||||
"Provision.instantiate" : {
|
||||
type: "single",
|
||||
call: OpenNebula.Template.instantiate,
|
||||
callback: function(){
|
||||
OpenNebula.Action.clear_cache("VM");
|
||||
ProvisionVmsList.show(0);
|
||||
var context = $("#provision_create_vm");
|
||||
$("#vm_name", context).val('');
|
||||
$(".provision_selected_networks").html("");
|
||||
$(".provision-pricing-table", context).removeClass("selected");
|
||||
$(".alert-box-error", context).hide();
|
||||
callback: _clearVMCreate,
|
||||
error: Notifier.onError
|
||||
},
|
||||
|
||||
$('#provision_vm_instantiate_templates_owner_filter').val('all').change();
|
||||
$('#provision_vm_instantiate_template_search').val('').trigger('input');
|
||||
},
|
||||
"Provision.instantiate_persistent" : {
|
||||
type: "single",
|
||||
call: OpenNebula.Template.instantiate_persistent,
|
||||
callback: _clearVMCreate,
|
||||
error: Notifier.onError
|
||||
}
|
||||
}
|
||||
|
||||
function _clearVMCreate(){
|
||||
OpenNebula.Action.clear_cache("VM");
|
||||
ProvisionVmsList.show(0);
|
||||
var context = $("#provision_create_vm");
|
||||
$("#vm_name", context).val('');
|
||||
$(".provision_selected_networks").html("");
|
||||
$(".provision-pricing-table", context).removeClass("selected");
|
||||
$(".alert-box-error", context).hide();
|
||||
|
||||
$('#provision_vm_instantiate_templates_owner_filter').val('all').change();
|
||||
$('#provision_vm_instantiate_template_search').val('').trigger('input');
|
||||
}
|
||||
|
||||
//$(document).foundation();
|
||||
|
||||
function generate_cardinality_selector(context, role_template, template_json) {
|
||||
@ -871,6 +880,22 @@ define(function(require) {
|
||||
ProvisionTemplatesList.updateDatatable(provision_vm_instantiate_templates_datatable);
|
||||
});
|
||||
|
||||
$("#provision_create_vm input.instantiate_pers").on("change", function(){
|
||||
var create_vm_context = $("#provision_create_vm");
|
||||
|
||||
var disksContext = $(".provision_disk_selector", create_vm_context);
|
||||
var template_json = disksContext.data("template_json");
|
||||
|
||||
if (template_json != undefined &&
|
||||
Config.provision.create_vm.isEnabled("disk_resize")) {
|
||||
|
||||
DisksResize.insert(
|
||||
template_json,
|
||||
disksContext,
|
||||
{force_persistent: $(this).prop('checked')});
|
||||
}
|
||||
});
|
||||
|
||||
tab.on("click", "#provision_create_vm .provision_select_template .provision-pricing-table.only-one" , function(){
|
||||
var create_vm_context = $("#provision_create_vm");
|
||||
|
||||
@ -909,8 +934,13 @@ define(function(require) {
|
||||
$(".provision_capacity_selector input[required]", create_vm_context).attr("oninvalid", "provisionInvalidCapacity(this)");
|
||||
|
||||
var disksContext = $(".provision_disk_selector", create_vm_context);
|
||||
disksContext.data("template_json", template_json);
|
||||
|
||||
if (Config.provision.create_vm.isEnabled("disk_resize")) {
|
||||
DisksResize.insert(template_json, disksContext);
|
||||
DisksResize.insert(
|
||||
template_json,
|
||||
disksContext,
|
||||
{force_persistent: $("input.instantiate_pers", create_vm_context).prop("checked")});
|
||||
} else {
|
||||
disksContext.html("");
|
||||
}
|
||||
@ -985,7 +1015,15 @@ define(function(require) {
|
||||
$.extend(extra_info.template, user_inputs_values)
|
||||
}
|
||||
|
||||
Sunstone.runAction("Provision.instantiate", template_id, extra_info);
|
||||
var action;
|
||||
|
||||
if ($("input.instantiate_pers", context).prop("checked")){
|
||||
action = "instantiate_persistent";
|
||||
}else{
|
||||
action = "instantiate";
|
||||
}
|
||||
|
||||
Sunstone.runAction("Provision."+action, template_id, extra_info);
|
||||
return false;
|
||||
})
|
||||
|
||||
|
@ -24,6 +24,11 @@
|
||||
<input type="text" id="vm_name" class="provision-input" placeholder="{{tr "Virtual Machine Name"}}"/>
|
||||
</div>
|
||||
<div class="large-3 columns">
|
||||
<label>
|
||||
<input type="checkbox" class="instantiate_pers"/>
|
||||
{{tr "Persistent copy"}}
|
||||
{{{tip (tr "Creates a private persistent copy of the template plus any image defined in DISK, and instantiates that copy")}}}
|
||||
</label>
|
||||
</div>
|
||||
<div class="large-3 columns">
|
||||
<button href="#" class="button success expanded" type="submit">{{tr "Create"}}</button>
|
||||
|
@ -185,6 +185,20 @@ define(function(require) {
|
||||
});
|
||||
}
|
||||
},
|
||||
"Template.instantiate_persistent":
|
||||
{
|
||||
type: "single",
|
||||
call: OpenNebulaResource.instantiate_persistent,
|
||||
callback: function(req) {
|
||||
Sunstone.hideFormPanel(TAB_ID);
|
||||
OpenNebulaAction.clear_cache("VM");
|
||||
},
|
||||
error: function(request, response){
|
||||
// without tab id param to work for both templates and vms tab
|
||||
Sunstone.hideFormPanelLoading();
|
||||
Notifier.onError(request, response);
|
||||
}
|
||||
},
|
||||
"Template.clone_dialog" : {
|
||||
type: "custom",
|
||||
call: function(){
|
||||
|
@ -80,7 +80,33 @@ define(function(require) {
|
||||
});
|
||||
}
|
||||
|
||||
function _setup(context) {
|
||||
function _setup(context) {
|
||||
var that = this;
|
||||
|
||||
$("input.instantiate_pers", context).on("change", function(){
|
||||
if($(this).prop('checked')){
|
||||
$("#vm_n_times_disabled", context).show();
|
||||
$("#vm_n_times", context).hide();
|
||||
|
||||
$.each(that.template_objects, function(index, template_json) {
|
||||
DisksResize.insert(
|
||||
template_json,
|
||||
$(".disksContext" + template_json.VMTEMPLATE.ID, context),
|
||||
{force_persistent: true});
|
||||
});
|
||||
|
||||
} else {
|
||||
$("#vm_n_times_disabled", context).hide();
|
||||
$("#vm_n_times", context).show();
|
||||
|
||||
$.each(that.template_objects, function(index, template_json) {
|
||||
DisksResize.insert(
|
||||
template_json,
|
||||
$(".disksContext" + template_json.VMTEMPLATE.ID, context),
|
||||
{force_persistent: false});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function _submitWizard(context) {
|
||||
@ -94,13 +120,22 @@ define(function(require) {
|
||||
var n_times = $('#vm_n_times', context).val();
|
||||
var n_times_int = 1;
|
||||
|
||||
if (n_times.length) {
|
||||
n_times_int = parseInt(n_times, 10);
|
||||
}
|
||||
|
||||
var hold = $('#hold', context).prop("checked");
|
||||
|
||||
$.each(this.selected_nodes, function(index, template_id) {
|
||||
if (n_times.length) {
|
||||
n_times_int = parseInt(n_times, 10);
|
||||
}
|
||||
var action;
|
||||
|
||||
if ($("input.instantiate_pers", context).prop("checked")){
|
||||
action = "instantiate_persistent";
|
||||
n_times_int = 1;
|
||||
}else{
|
||||
action = "instantiate_quiet";
|
||||
}
|
||||
|
||||
$.each(this.selected_nodes, function(index, template_id) {
|
||||
var extra_msg = "";
|
||||
if (n_times_int > 1) {
|
||||
extra_msg = n_times_int + " times";
|
||||
@ -128,31 +163,10 @@ define(function(require) {
|
||||
|
||||
extra_info['template'] = tmp_json;
|
||||
|
||||
if (!vm_name.length) { //empty name use OpenNebula core default
|
||||
for (var i = 0; i < n_times_int; i++) {
|
||||
extra_info['vm_name'] = "";
|
||||
Sunstone.runAction("Template.instantiate_quiet", template_id, extra_info);
|
||||
}
|
||||
} else {
|
||||
if (vm_name.indexOf("%i") == -1) {//no wildcard, all with the same name
|
||||
extra_info['vm_name'] = vm_name;
|
||||
for (var i = 0; i < n_times_int; i++) {
|
||||
extra_info['vm_name'] = vm_name.replace(/%i/gi, i); // replace wildcard
|
||||
|
||||
for (var i = 0; i < n_times_int; i++) {
|
||||
Sunstone.runAction(
|
||||
"Template.instantiate_quiet",
|
||||
template_id,
|
||||
extra_info);
|
||||
}
|
||||
} else { //wildcard present: replace wildcard
|
||||
for (var i = 0; i < n_times_int; i++) {
|
||||
extra_info['vm_name'] = vm_name.replace(/%i/gi, i);
|
||||
|
||||
Sunstone.runAction(
|
||||
"Template.instantiate_quiet",
|
||||
template_id,
|
||||
extra_info);
|
||||
}
|
||||
}
|
||||
Sunstone.runAction("Template."+action, template_id, extra_info);
|
||||
}
|
||||
});
|
||||
|
||||
@ -160,7 +174,10 @@ define(function(require) {
|
||||
}
|
||||
|
||||
function _setTemplateIds(context, selected_nodes) {
|
||||
var that = this;
|
||||
|
||||
this.selected_nodes = selected_nodes;
|
||||
this.template_objects = [];
|
||||
|
||||
var templatesContext = $(".list_of_templates", context);
|
||||
|
||||
@ -175,13 +192,18 @@ define(function(require) {
|
||||
},
|
||||
timeout: true,
|
||||
success: function (request, template_json) {
|
||||
that.template_objects.push(template_json);
|
||||
|
||||
templatesContext.append(
|
||||
TemplateRowHTML(
|
||||
{ element: template_json.VMTEMPLATE,
|
||||
capacityInputsHTML: CapacityInputs.html()
|
||||
}) );
|
||||
|
||||
DisksResize.insert(template_json, $(".disksContext" + template_json.VMTEMPLATE.ID, context));
|
||||
DisksResize.insert(
|
||||
template_json,
|
||||
$(".disksContext" + template_json.VMTEMPLATE.ID, context),
|
||||
{force_persistent: $("input.instantiate_pers", context).prop("checked")});
|
||||
|
||||
NicsSection.insert(template_json,
|
||||
$(".nicsContext" + template_json.VMTEMPLATE.ID, context),
|
||||
|
@ -19,6 +19,15 @@
|
||||
<div class="large-12 large-centered columns selectTemplateTable">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="large-12 large-centered columns">
|
||||
<label>
|
||||
<input type="checkbox" class="instantiate_pers"/>
|
||||
{{tr "Instantiate as persistent"}}
|
||||
{{{tip (tr "Creates a private persistent copy of the template plus any image defined in DISK, and instantiates that copy")}}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row nameContainer">
|
||||
<div class="medium-4 columns">
|
||||
<label for="vm_name">
|
||||
@ -36,7 +45,8 @@
|
||||
{{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">
|
||||
<input type="number" name="vm_n_times" id="vm_n_times" value="1">
|
||||
<input type="number" name="vm_n_times_disabled" id="vm_n_times_disabled" value="1" disabled>
|
||||
</div>
|
||||
<div class="medium-4 columns">
|
||||
<input type="checkbox" name="hold" id="hold"/>
|
||||
|
@ -28,7 +28,17 @@ define(function(require){
|
||||
'retrieve': _retrieve
|
||||
};
|
||||
|
||||
function _insert(template_json, disksContext) {
|
||||
/**
|
||||
* @param {Object} opts Options:
|
||||
* - force_persistent {bool}: mark all disks as if they
|
||||
* were persistent, disabling resize inputs
|
||||
*/
|
||||
function _insert(template_json, disksContext, opts) {
|
||||
|
||||
if (opts == undefined){
|
||||
opts = {};
|
||||
}
|
||||
|
||||
var template_disk = template_json.VMTEMPLATE.TEMPLATE.DISK
|
||||
var disks = []
|
||||
if ($.isArray(template_disk)) {
|
||||
@ -105,7 +115,8 @@ define(function(require){
|
||||
$("label", diskContext).text(Locale.tr("DISK") + ' ' + disk_id + ': ' + label);
|
||||
|
||||
var disabled =
|
||||
( (disk.PERSISTENT && disk.PERSISTENT.toUpperCase() == "YES") ||
|
||||
( opts.force_persistent ||
|
||||
(disk.PERSISTENT && disk.PERSISTENT.toUpperCase() == "YES") ||
|
||||
(disk.TYPE && OpenNebulaImage.TYPES[disk.TYPE] == OpenNebulaImage.TYPES.CDROM) );
|
||||
|
||||
var attr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user