diff --git a/src/sunstone/etc/sunstone-views/admin.yaml b/src/sunstone/etc/sunstone-views/admin.yaml index e5d149054a..18983a40c7 100644 --- a/src/sunstone/etc/sunstone-views/admin.yaml +++ b/src/sunstone/etc/sunstone-views/admin.yaml @@ -113,6 +113,7 @@ tabs: actions: VM.refresh: true VM.create_dialog: true + VM.easy_provision: false VM.chown: true VM.chgrp: true VM.chmod: true @@ -160,6 +161,7 @@ tabs: actions: Template.refresh: true Template.create_dialog: true + Template.easy_provision: false Template.update_dialog: true Template.instantiate_vms: true Template.chown: true diff --git a/src/sunstone/etc/sunstone-views/user.yaml b/src/sunstone/etc/sunstone-views/user.yaml index 8dea51c044..33fe45ba1c 100644 --- a/src/sunstone/etc/sunstone-views/user.yaml +++ b/src/sunstone/etc/sunstone-views/user.yaml @@ -114,6 +114,7 @@ tabs: actions: VM.refresh: true VM.create_dialog: true + VM.easy_provision: false VM.chown: false VM.chgrp: false VM.chmod: true @@ -161,6 +162,7 @@ tabs: actions: Template.refresh: true Template.create_dialog: true + Template.easy_provision: false Template.update_dialog: true Template.instantiate_vms: true Template.chown: false diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index 8d6bd32afc..bfb004a4a3 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -89,54 +89,203 @@ var vms_tab_content = '\ \ '; +//var create_vm_tmpl ='\ +//
\ +//

\ +// '+tr("Create Virtual Machine")+'\ +//

\ +//
\ +//
\ +//
\ +//
\ +// \ +//
\ +//
\ +// \ +//
\ +//
\ +//
'+tr("Defaults to template name when emtpy")+'.
\ +//
\ +//
\ +//
\ +//
\ +// \ +//
\ +//
\ +// \ +//
\ +//
\ +//
\ +//
\ +//
\ +//
\ +//
\ +// \ +//
\ +//
\ +// \ +//
\ +//
\ +//
'+tr("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")+'.
\ +//
\ +//
\ +//
\ +//
\ +// \ +// \ +//
\ +//×\ +//
'; + var create_vm_tmpl ='\ -
\ -

\ - '+tr("Create Virtual Machine")+'\ -

\ +
\ +

\ + '+tr("Create Virtual Machine")+'\ +

\ +
\ +
\ +
\ +
\ +
\ + '+tr("Step 1: Specify a name and the number of instances")+'\ +
\ +
\ + \ +
\ +
\ + \ +
\ +
\ +
'+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")+'.
\ +
\
\ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ -
'+tr("Defaults to template name when emtpy")+'.
\ -
\ +
\ +
\ + \
\ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ -
\ -
\ +
\ + \
\ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ -
'+tr("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")+'.
\ -
\ +
\ +
'+tr("Number of Virtual Machines that will be created using this template")+'.
\
\ -
\ -
\ - \ - \
\ -×\ -'; +
\ +
\ +
\ +
\ +
\ +
\ +
\ + '+tr("Step 2: Select a type of instance")+'\ +
\ +
\ + \ +
\ +
\ + \ +
\ +
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
'+tr("ID")+''+tr("Owner")+''+tr("Group")+''+tr("Name")+''+tr("Registration time")+'
\ + \ +
\ +
\ + '+tr("Please select a template from the list")+'\ + \ + \ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ + '+tr("Step 3: Select an operation system")+'\ +
\ +
\ + \ +
\ +
\ + \ +
\ +
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
'+tr("ID")+''+tr("Owner")+''+tr("Group")+''+tr("Name")+''+tr("Datastore")+''+tr("Size")+''+tr("Type")+''+tr("Registration time")+''+tr("Persistent")+''+tr("Status")+''+tr("#VMS")+''+tr("Target")+'
\ + \ +
\ +
\ + '+tr("Please select an image from the list")+'\ + \ + \ +
\ +
\ +
\ + \ + ×\ + \ +
'; var vmachine_list_json = {}; var dataTable_vMachines; @@ -157,7 +306,16 @@ var vm_actions = { "VM.create_dialog" : { type: "custom", - call: popUpCreateVMDialog + call: function(){ + popUpCreateVMDialog(false); + } + }, + + "VM.easy_provision" : { + type: "custom", + call: function(){ + popUpCreateVMDialog(true); + } }, "VM.list" : { @@ -692,6 +850,12 @@ var vm_buttons = { layout: "create", alwaysActive: true }, + "VM.easy_provision" : { + type: "action", + layout: "create", + text: tr("Launch"), + alwaysActive: true + }, "VM.chown" : { type: "confirm_with_select", text: tr("Change owner"), @@ -2732,28 +2896,123 @@ function setup_vm_snapshot_tab(){ // Sets up the create-template dialog and all the processing associated to it, // which is a lot. -function setupCreateVMDialog(){ +function setupCreateVMDialog(include_select_image){ dialogs_context.append('
'); //Insert HTML in place $create_vm_dialog = $('#create_vm_dialog') var dialog = $create_vm_dialog; dialog.html(create_vm_tmpl); + dialog.addClass("reveal-modal large max-height"); - //Prepare jquery dialog - //dialog.dialog({ - // autoOpen: false, - // modal: true, - // width: 400 - //}); - dialog.addClass("reveal-modal"); + var dataTable_template_templates = $('#template_templates_table', dialog).dataTable({ + "iDisplayLength": 4, + "bAutoWidth":false, + "sDom" : '<"H">t<"F"p>', + "aoColumnDefs": [ + { "sWidth": "35px", "aTargets": [0,1] }, + { "bVisible": false, "aTargets": [1,2,3,5]} + ], + "fnDrawCallback": function(oSettings) { + var nodes = this.fnGetNodes(); + $.each(nodes, function(){ + if ($(this).find("td:eq(1)").html() == $('#TEMPLATE_ID', dialog).val()) { + $("td", this).addClass('markrow'); + $('input.check_item', this).attr('checked','checked'); + } + }) + } + }); + + // Retrieve the images to fill the datatable + update_datatable_template_templates(dataTable_template_templates); + + $('#template_templates_table_search', dialog).keyup(function(){ + dataTable_template_templates.fnFilter( $(this).val() ); + }) + + $('#template_templates_table tbody', dialog).delegate("tr", "click", function(e){ + var aData = dataTable_template_templates.fnGetData(this); + + $("td.markrow", dataTable_template_templates).removeClass('markrow'); + $('tbody input.check_item', dataTable_template_templates).removeAttr('checked'); + + $('#template_selected', dialog).show(); + $('#select_template', dialog).hide(); + $('.alert-box', dialog).hide(); + + $("td", this).addClass('markrow'); + $('input.check_item', this).attr('checked','checked'); + + $('#TEMPLATE_NAME', dialog).text(aData[4]); + $('#TEMPLATE_ID', dialog).val(aData[1]); + return true; + }); + + $("#refresh_template_templates_table_button_class").die(); + $("#refresh_template_templates_table_button_class").live('click', function(){ + update_datatable_template_templates($('#template_templates_table').dataTable()); + }); + + if (include_select_image) { + $("#select_image_step", dialog).show(); + var dataTable_template_images = $('#template_images_table', dialog).dataTable({ + "iDisplayLength": 4, + "bAutoWidth":false, + "sDom" : '<"H">t<"F"p>', + "aoColumnDefs": [ + { "sWidth": "35px", "aTargets": [0,1] }, + { "bVisible": false, "aTargets": [2,3,7,8,5,9,12]} + ], + "fnDrawCallback": function(oSettings) { + var nodes = this.fnGetNodes(); + $.each(nodes, function(){ + if ($(this).find("td:eq(1)").html() == $('#IMAGE_ID', dialog).val()) { + $("td", this).addClass('markrow'); + $('input.check_item', this).attr('checked','checked'); + } + }) + } + }); + + // Retrieve the images to fill the datatable + update_datatable_template_images(dataTable_template_images); + + $('#template_images_table_search', dialog).keyup(function(){ + dataTable_template_images.fnFilter( $(this).val() ); + }) + + $('#template_images_table tbody', dialog).delegate("tr", "click", function(e){ + var aData = dataTable_template_images.fnGetData(this); + + $("td.markrow", dataTable_template_images).removeClass('markrow'); + $('tbody input.check_item', dataTable_template_images).removeAttr('checked'); + + $('#image_selected', dialog).show(); + $('#select_image', dialog).hide(); + $('.alert-box', dialog).hide(); + + $("td", this).addClass('markrow'); + $('input.check_item', this).attr('checked','checked'); + + $('#IMAGE_NAME', dialog).text(aData[4]); + $('#IMAGE_ID', dialog).val(aData[1]); + return true; + }); + + $("#refresh_template_images_table_button_class").die(); + $("#refresh_template_images_table_button_class").live('click', function(){ + update_datatable_template_images($('#template_images_table').dataTable()); + }); + } else { + $("#select_image_step", dialog).hide(); + } - //$('button',dialog).button(); setupTips(dialog); $('#create_vm_form',dialog).submit(function(){ var vm_name = $('#vm_name',this).val(); - var template_id = $('#template_id',this).val(); + var template_id = $('#TEMPLATE_ID',this).val(); var n_times = $('#vm_n_times',this).val(); var n_times_int=1; @@ -2766,29 +3025,40 @@ function setupCreateVMDialog(){ n_times_int=parseInt(n_times,10); }; - var extra_info = ""; + var extra_msg = ""; if (n_times_int > 1) { - extra_info = n_times_int+" times"; + extra_msg = n_times_int+" times"; } - notifySubmit("Template.instantiate",template_id, extra_info); + notifySubmit("Template.instantiate",template_id, extra_msg); + + var extra_info = {}; + if ($("#IMAGE_ID", this).val()) { + image_id = $("#IMAGE_ID", this).val(); + extra_info['template'] = { + 'disk': { + 'image_id': image_id + } + } + } if (!vm_name.length){ //empty name use OpenNebula core default for (var i=0; i< n_times_int; i++){ - Sunstone.runAction("Template.instantiate_quiet", template_id, ""); + extra_info['vm_name'] = ""; + Sunstone.runAction("Template.instantiate_quiet", template_id, extra_info); }; } else { - if (vm_name.indexOf("%i") == -1){ //no wildcard + if (vm_name.indexOf("%i") == -1){//no wildcard, all with the same name for (var i=0; i< n_times_int; i++){ - Sunstone.runAction("Template.instantiate_quiet", template_id, vm_name); + extra_info['vm_name'] = vm_name; + Sunstone.runAction("Template.instantiate_quiet", template_id, extra_info); }; } else { //wildcard present: replace wildcard - var name = ""; for (var i=0; i< n_times_int; i++){ - name = vm_name.replace(/%i/gi,i); - Sunstone.runAction("Template.instantiate_quiet", template_id, name); + extra_info['vm_name'] = vm_name.replace(/%i/gi,i); + Sunstone.runAction("Template.instantiate_quiet", template_id, extra_info); }; }; } @@ -2802,7 +3072,8 @@ function setupCreateVMDialog(){ } // Open creation dialog -function popUpCreateVMDialog(){ +function popUpCreateVMDialog(include_select_image){ + setupCreateVMDialog(include_select_image); $create_vm_dialog.reveal(); }