diff --git a/src/cloud/occi/lib/ui/public/js/occi.js b/src/cloud/occi/lib/ui/public/js/occi.js
index b91c2dda6e..bdceef2429 100644
--- a/src/cloud/occi/lib/ui/public/js/occi.js
+++ b/src/cloud/occi/lib/ui/public/js/occi.js
@@ -500,6 +500,19 @@ var OCCI = {
},
"startvnc" : function(params){
OCCI.VM.vnc(params,"startvnc");
+ },
+
+ "attachdisk" : function(params){
+ var action_obj = {"disk_template": params.data.extra_param};
+ OCCI.Action.simple_action(params,OCCI.VM.resource,
+ "attachdisk",
+ params.data.extra_param);
+ },
+ "detachdisk" : function(params){
+ // extra param is disk id
+ var action_obj = ''
+ OCCI.Action.simple_action(params,OCCI.VM.resource,
+ "detachdisk", action_obj);
}
/*
"monitor" : function(params){
diff --git a/src/cloud/occi/lib/ui/public/js/plugins/compute.js b/src/cloud/occi/lib/ui/public/js/plugins/compute.js
index 05441efcf9..ed11ac8e09 100644
--- a/src/cloud/occi/lib/ui/public/js/plugins/compute.js
+++ b/src/cloud/occi/lib/ui/public/js/plugins/compute.js
@@ -241,14 +241,6 @@ var vm_actions = {
notify: true
},
- "VM.saveasmultiple" : {
- type: "custom",
- call: function(){
- var elems = vmElements();
- popUpSaveasDialog(elems);
- }
- },
-
"VM.saveas" : {
type: "single",
call: OCCI.VM.saveas,
@@ -256,13 +248,6 @@ var vm_actions = {
error:onError
},
- "VM.saveas_disks" : {
- type: "single",
- call: OCCI.VM.show,
- callback: saveasDisksCallback,
- error: onError
- },
-
"VM.getInstanceTypes" : {
type: "list",
call: OCCI.Instance_type.list,
@@ -286,6 +271,26 @@ var vm_actions = {
callback: vncCallback,
error: onError,
notify: true
+ },
+
+ "VM.attachdisk" : {
+ type: "single",
+ call: OCCI.VM.attachdisk,
+ callback: updateVMachineElement,
+ error: onError,
+ notify: true
+ },
+
+ "VM.detachdisk" : {
+ type: "single",
+ call: OCCI.VM.detachdisk,
+ callback: function(req,res){
+ setTimeout(function(req,res){
+ Sunstone.runAction("VM.show", req.request.data[0][0])
+ },1000,req);
+ },
+ error: onError,
+ notify: true
}
/*
@@ -382,8 +387,8 @@ var vm_info_panel = {
title: tr("Compute resource"),
content: ""
},
- "vm_disks_tab" : {
- title: tr("Disks"),
+ "vm_hotplugging_tab" : {
+ title: tr("Disks & Hotplugging"),
content: ""
},
"vm_networks_tab" : {
@@ -464,6 +469,11 @@ function updateVMachineElement(request, vm_json){
var id = vm_json.COMPUTE.ID;
var element = vMachineElementArray(vm_json);
updateSingleElement(element,dataTable_vMachines,'#vm_'+id)
+
+ //we update this too, even if it is not shown.
+ var $hotplugging_tab = $('div#vm_info_panel div#vm_hotplugging_tab');
+ $('#hotplugging_form',
+ $hotplugging_tab).replaceWith(printDisks(vm_json.COMPUTE));
}
// Callback to delete a single element from the list
@@ -562,47 +572,9 @@ function updateVMInfo(request,vm){
'
};
- var disks_str = '
\
-\
-
'+tr("Disks information")+'
\
-';
-
- var disks = vm_info.DISK;
- if (disks){
- if (disks.constructor != Array) // 1lease
- disks = [disks];
-
- for (var i=0;i\
-
'+tr("ID")+'
\
-
'+disks[i].id+'
\
-\
-
\
-
'+tr("Name")+'
\
-
'+disks[i].STORAGE.name+'
\
-
\
-
\
-
'+tr("Target")+'
\
-
'+disks[i].TARGET+'
\
-
\
-
\
-
'+tr("Type")+'
\
-
'+disks[i].TYPE+'
\
-
';
- };
-
- } else {
- disks_str += '
'+
- tr("No disks defined")+'
';
- };
-
- disks_str += '
\
-
\
-
';
-
- var disks_tab = {
- title : tr("Disks"),
- content : disks_str
+ var hotplugging_tab = {
+ title : tr("Disks & Hotplugging"),
+ content : printDisks(vm_info)
};
var networks_str = '
\
@@ -658,7 +630,7 @@ function updateVMInfo(request,vm){
*/
Sunstone.updateInfoPanelTab("vm_info_panel","vm_info_tab",info_tab);
- Sunstone.updateInfoPanelTab("vm_info_panel","vm_disks_tab",disks_tab);
+ Sunstone.updateInfoPanelTab("vm_info_panel","vm_hotplugging_tab",hotplugging_tab);
Sunstone.updateInfoPanelTab("vm_info_panel","vm_networks_tab",networks_tab);
//Sunstone.updateInfoPanelTab("vm_info_panel","vm_monitoring_tab",monitoring_tab);
@@ -675,6 +647,150 @@ function updateVMInfo(request,vm){
// };
}
+
+// Generates the HTML for the hotplugging tab
+// This is a list of disks with the save_as, detach options.
+// And a form to attach a new disk to the VM, if it is running.
+function printDisks(vm_info){
+ var im_sel = makeSelectOptions(dataTable_images,
+ 1, //id col
+ 2, //name col
+ [],
+ []
+ );
+ var html ='\
+ ';
+ return html;
+ }
+
+ // Attach disk form
+ html += '
\
+ \
+
'+tr("Attach disk to running VM")+'
\
+ \
+ \
+
\
+
\
+ \
+
\
+
\
+
\
+
\
+ \
+
\
+
\
+
\
+
\
+ \
+
\
+
\
+ \
+
';
+
+ return html;
+}
+
+// Listeners to the disks operations (detach, saveas, attach)
+function hotpluggingOps(){
+ $('button.detachdisk').live('click', function(){
+ var b = $(this);
+ var vm_id = b.parents('form').attr('vmid');
+ var disk_id = b.parents('tr').attr('disk_id');
+
+ Sunstone.runAction('VM.detachdisk', vm_id, disk_id);
+
+ b.html(spinner);
+ return false;
+ });
+
+ $('button.saveas').live('click', function(){
+ var b = $(this);
+ var vm_id = b.parents('form').attr('vmid');
+ var disk_id = b.parents('tr').attr('disk_id');
+ var parent = b.parent();
+ var image_name = $('input[name="saveas_name"]',parent).val();
+ if (!image_name){
+ notifyError('Please provide a name for the new image');
+ return false;
+ }
+
+ var obj = {
+ disk_id : disk_id,
+ image_name : image_name,
+ };
+
+ Sunstone.runAction('VM.saveas', vm_id, obj);
+
+ b.html(spinner);
+ return false;
+ });
+
+ $('#hotplugging_form').live('submit',function(){
+ var vm_id = $(this).attr('vmid');
+ var disk_obj = {};
+ var im_id = $('select[name="IMAGE_ID"]',this).val();
+ if (!im_id) {
+ notifyError(tr("Please select an image to attach"));
+ return false;
+ }
+ var image_id = $('select[name="IMAGE_ID"]',this).val();
+ var url = location.protocol + "//" + location.host;
+ var href = url + '/storage/' + image_id
+ var target = $('input[name="TARGET"]',this).val();
+
+ var str = '';
+ if (target) str += ''+target+'';
+
+ Sunstone.runAction("VM.attachdisk", vm_id, str);
+ return false;
+ });
+}
+
// Open creation dialog
function popUpCreateVMDialog(){
Sunstone.popUpInfoPanel("vm_create_panel");
@@ -813,131 +929,6 @@ function popUpCreateVMDialog(){
});
}
-
-//Prepares a dialog to saveas a VM
-function setupSaveasDialog(){
- //Append to DOM
- dialogs_context.append('');
- $saveas_vm_dialog = $('#saveas_vm_dialog',dialogs_context);
- var dialog = $saveas_vm_dialog;
-
- //Put HTML in place
- dialog.html('\
- ');
-
- dialog.dialog({
- autoOpen:false,
- width:600,
- modal:true,
- height:350,
- resizable:true
- });
-
- $('#saveas_vm_form',dialog).submit(function(){
- var elems = $('#saveas_tabs div.saveas_tab',this);
- var args = [];
- $.each(elems,function(){
- var id = $('#vm_id',this).text();
- var disk_id = $('#vm_disk_id',this).val();
- var image_name = $('#image_name',this).val();
-
- if (!id.length || !disk_id.length || !image_name.length) {
- notifyError(tr("Skipping VM ")+id+". "+
- tr("No disk id or image name specified"));
- }
- else {
- var obj = {
- disk_id : disk_id,
- image_name : image_name
- };
- args.push(id);
- Sunstone.runAction("VM.saveas",id,obj);
- }
- });
- if (args.length > 0){
- notifySubmit("VM.saveas",args);
- }
-
- $saveas_vm_dialog.dialog('close');
- return false;
- });
-
- $('#vm_saveas_cancel',dialog).click(function(){
- $saveas_vm_dialog.dialog('close');
- return false;
- });
-
-}
-
-function popUpSaveasDialog(elems){
- var dialog = $saveas_vm_dialog;
- $('#saveas_tabs',dialog).tabs('destroy');
- $('#saveas_tabs',dialog).empty();
- $('#saveas_tabs',dialog).html('