1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-23 22:50:09 +03:00

Feature #3782: Implement disk-saveas in sunstone

This commit is contained in:
Carlos Martín 2015-06-29 16:51:48 +02:00
parent 5f1305427a
commit cc686d39aa
14 changed files with 213 additions and 131 deletions

View File

@ -188,8 +188,7 @@ tabs:
VM.resize: true
VM.attachdisk: true
VM.detachdisk: true
VM.saveas: true
VM.disk_snapshot_cancel: true
VM.disk_saveas: true
VM.attachnic: true
VM.detachnic: true
VM.snapshot_create: true

View File

@ -188,8 +188,7 @@ tabs:
VM.resize: true
VM.attachdisk: true
VM.detachdisk: true
VM.saveas: false
VM.disk_snapshot_cancel: false
VM.disk_saveas: false
VM.attachnic: true
VM.detachnic: true
VM.snapshot_create: true

View File

@ -189,8 +189,7 @@ tabs:
VM.resize: true
VM.attachdisk: true
VM.detachdisk: true
VM.saveas: true
VM.disk_snapshot_cancel: true
VM.disk_saveas: true
VM.attachnic: true
VM.detachnic: true
VM.snapshot_create: true

View File

@ -54,7 +54,7 @@ module OpenNebulaJSON
when "stop" then self.stop
when "suspend" then self.suspend
when "reset" then self.reset
when "saveas" then self.save_as(action_hash['params'])
when "disk_saveas" then self.disk_saveas(action_hash['params'])
when "snapshot_create" then self.snapshot_create(action_hash['params'])
when "snapshot_revert" then self.snapshot_revert(action_hash['params'])
when "snapshot_delete" then self.snapshot_delete(action_hash['params'])
@ -106,8 +106,9 @@ module OpenNebulaJSON
super(params['host_id'], live, params['enforce'], params['ds_id'])
end
def save_as(params=Hash.new)
disk_saveas(params['disk_id'].to_i, params['image_name'], params['type'])
def disk_saveas(params=Hash.new)
super(params['disk_id'].to_i, params['image_name'],
params['type'], params['snapshot_id'].to_i)
end
def snapshot_create(params=Hash.new)

View File

@ -370,13 +370,9 @@ define(function(require) {
var action_obj = params.data.extra_param;
OpenNebulaAction.simple_action(params, RESOURCE, "migrate", action_obj);
},
"saveas": function(params) {
"disk_saveas": function(params) {
var action_obj = params.data.extra_param;
OpenNebulaAction.simple_action(params, RESOURCE, "saveas", action_obj);
},
"disk_snapshot_cancel": function(params) {
var action_obj = {"disk_id": params.data.extra_param};
OpenNebulaAction.simple_action(params, RESOURCE, "disk_snapshot_cancel", action_obj);
OpenNebulaAction.simple_action(params, RESOURCE, "disk_saveas", action_obj);
},
"snapshot_create": function(params) {
var action_obj = params.data.extra_param;

View File

@ -13,6 +13,7 @@ define(function(require) {
require('./vms-tab/dialogs/resize'),
require('./vms-tab/dialogs/attach-disk'),
require('./vms-tab/dialogs/disk-snapshot'),
require('./vms-tab/dialogs/disk-saveas'),
require('./vms-tab/dialogs/attach-nic'),
require('./vms-tab/dialogs/snapshot'),
require('./vms-tab/dialogs/vnc'),

View File

@ -62,7 +62,8 @@ define(function(require) {
"VM.disk_snapshot_create": _commonActions.singleAction('disk_snapshot_create'),
"VM.disk_snapshot_revert": _commonActions.singleAction('disk_snapshot_revert'),
"VM.disk_snapshot_delete": _commonActions.singleAction('disk_snapshot_delete'),
"VM.disk_saveas" : _commonActions.singleAction('disk_saveas'),
"VM.create_dialog" : {
type: "custom",
call: function() {
@ -162,50 +163,7 @@ define(function(require) {
Spice.unlock();
},
notify: true
},
//"VM.startspice" : {
// type: "custom",
// call: function() {
// popUpSPICE();
// }
//},
//"VM.startspice_action" : {
// type: "single",
// call: OpenNebula.VM.startvnc,
// callback: spiceCallback,
// error: function(req, resp) {
// onError(req, resp);
// spice_lock = false;
// },
// notify: true
//},
/*
"VM.saveas" : {
type: "single",
call: OpenNebula.VM.saveas,
callback: function(request) {
Sunstone.runAction("VM.show", request.request.data[0]);
OpenNebula.Helper.clear_cache("IMAGE");
},
error:onError,
notify: true
},
"VM.disk_snapshot_cancel" : {
type: "single",
call: OpenNebula.VM.disk_snapshot_cancel,
callback: function(request) {
Sunstone.runAction("VM.show", request.request.data[0]);
OpenNebula.Helper.clear_cache("IMAGE");
},
error:onError,
notify: true
},
*/
}
};
return _actions;

View File

@ -0,0 +1,101 @@
define(function(require) {
/*
DEPENDENCIES
*/
var BaseDialog = require('utils/dialogs/dialog');
var TemplateHTML = require('hbs!./disk-saveas/html');
var Sunstone = require('sunstone');
var Tips = require('utils/tips');
/*
CONSTANTS
*/
var DIALOG_ID = require('./disk-saveas/dialogId');
var TAB_ID = require('../tabId');
/*
CONSTRUCTOR
*/
function Dialog() {
this.dialogId = DIALOG_ID;
BaseDialog.call(this);
}
Dialog.DIALOG_ID = DIALOG_ID;
Dialog.prototype = Object.create(BaseDialog.prototype);
Dialog.prototype.constructor = Dialog;
Dialog.prototype.html = _html;
Dialog.prototype.onShow = _onShow;
Dialog.prototype.setup = _setup;
Dialog.prototype.setParams = _setParams;
return Dialog;
/*
FUNCTION DEFINITIONS
*/
function _html() {
return TemplateHTML({
'dialogId': this.dialogId
});
}
function _setup(context) {
var that = this;
if (that.snapshotId == -1){
//$(".snapshot_id_row", context).hide();
} else {
$(".snapshot_id_row", context).show();
}
Tips.setup(context);
$('#' + DIALOG_ID + 'Form', context).submit(function() {
var image_name = $('#image_name', this).val();
var obj = {
"disk_id" : that.diskId,
"image_name": image_name,
"type": "",
"snapshot_id": that.snapshotId,
};
Sunstone.runAction('VM.disk_saveas', that.element.ID, obj);
Sunstone.getDialog(DIALOG_ID).hide();
Sunstone.getDialog(DIALOG_ID).reset();
return false;
});
return false;
}
function _onShow(context) {
$("#vm_id", context).val(this.element.ID);
$("#disk_id", context).val(this.diskId);
$("#snapshot_id", context).val(this.snapshotId);
$("#image_name", context).focus();
return false;
}
/**
* @param {object} params
* - params.element : VM element
* - params.diskId : Disk ID to save as
* - params.snapshotId : Disk snapshot ID to save as. Can be undefined
*/
function _setParams(params) {
this.element = params.element;
this.diskId = params.diskId;
this.snapshotId = -1;
if(params.snapshotId){
this.snapshotId = params.snapshotId;
}
}
});

View File

@ -0,0 +1,3 @@
define(function(require) {
return 'diskSaveasVMDialog';
});

View File

@ -0,0 +1,37 @@
<div id="{{dialogId}}" class="reveal-modal small" role="dialog" data-reveal >
<div class="row">
<div class="large-12 columns">
<h3 class="subheader" id="">{{tr "Disk Saveas"}}</h3>
</div>
</div>
<div class="reveal-body">
<form id="{{dialogId}}Form" action="">
<div class="row">
<div class="large-6 columns">
<label for="vm_id">{{tr "Virtual Machine ID"}}:</label>
<input style="border-style: inset; background-color: lightgrey" type="text" name="vm_id" id="vm_id" disabled/>
</div>
<div class="large-6 columns">
<label for="disk_id">{{tr "Disk ID"}}:</label>
<input style="border-style: inset; background-color: lightgrey" type="text" name="disk_id" id="disk_id" disabled/>
</div>
</div>
<div class="row snapshot_id_row">
<div class="large-6 columns">
<label for="snapshot_id">{{tr "Snapshot ID"}}:</label>
<input style="border-style: inset; background-color: lightgrey" type="text" name="snapshot_id" id="snapshot_id" disabled/>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label for="image_name">{{tr "New Image name"}}:</label>
<input type="text" name="image_name" id="image_name" />
</div>
</div>
<div class="form_buttons">
<button class="button radius right success" type="submit">{{tr "Save as"}}</button>
</div>
<a class="close-reveal-modal">&#215;</a>
</form>
</div>
</div>

View File

@ -23,7 +23,7 @@
</div>
</div>
<div class="form_buttons">
<button class="button radius right success" id="snapshot_live_button" type="submit" value="VM.saveas">{{tr "Take snapshot"}}</button>
<button class="button radius right success" type="submit">{{tr "Take snapshot"}}</button>
</div>
<a class="close-reveal-modal">&#215;</a>
</form>

View File

@ -19,7 +19,7 @@
</div>
</div>
<div class="form_buttons">
<button class="button radius right success" id="snapshot_live_button" type="submit" value="VM.saveas">{{tr "Take snapshot"}}</button>
<button class="button radius right success" type="submit">{{tr "Take snapshot"}}</button>
</div>
<a class="close-reveal-modal">&#215;</a>
</form>

View File

@ -19,6 +19,7 @@ define(function(require) {
var PANEL_ID = require('./storage/panelId');
var ATTACH_DISK_DIALOG_ID = require('../dialogs/attach-disk/dialogId');
var DISK_SNAPSHOT_DIALOG_ID = require('../dialogs/disk-snapshot/dialogId');
var DISK_SAVEAS_DIALOG_ID = require('../dialogs/disk-saveas/dialogId');
var RESOURCE = "VM"
var XML_ROOT = "VM"
@ -59,17 +60,19 @@ define(function(require) {
<th>' + Locale.tr("Target") + '</th>\
<th>' + Locale.tr("Image / Format-Size") + '</th>\
<th>' + Locale.tr("Persistent") + '</th>\
<th>' + Locale.tr("Save as") + '</th>\
<th colspan="">' + Locale.tr("Actions") + '</th>\
<th>';
<th>' + Locale.tr("Actions");
if (Config.isTabActionEnabled("vms-tab", "VM.attachdisk")) {
if (StateActions.enabledStateAction("VM.attachdisk", that.element.STATE, that.element.LCM_STATE)) {
html += '\
<button id="attach_disk" class="button tiny success right radius" >' + Locale.tr("Attach disk") + '</button>'
<span class="right">\
<button id="attach_disk" class="button tiny success right radius" >' + Locale.tr("Attach disk") + '</button>\
</span>';
} else {
html += '\
<button id="attach_disk" class="button tiny success right radius" disabled="disabled">' + Locale.tr("Attach disk") + '</button>'
<span class="right">\
<button id="attach_disk" class="button tiny success right radius" disabled="disabled">' + Locale.tr("Attach disk") + '</button>\
</span>';
}
}
@ -152,23 +155,8 @@ define(function(require) {
for (var i = 0; i < disks.length; i++) {
var disk = disks[i];
var save_as;
// Snapshot deferred
// Save as
if (
(
that.element.STATE == OpenNebulaVM.STATES.ACTIVE) &&
(
that.element.LCM_STATE == OpenNebulaVM.LCM_STATES.HOTPLUG_SAVEAS ||
that.element.LCM_STATE == OpenNebulaVM.LCM_STATES.HOTPLUG_SAVEAS_POWEROFF ||
that.element.LCM_STATE == OpenNebulaVM.LCM_STATES.HOTPLUG_SAVEAS_SUSPENDED) &&
(
disk.SAVE_AS_ACTIVE == "YES")
) {
save_as = Locale.tr("in progress");
actions = Locale.tr('deferred snapshot in progress');
}
// Snapshot Hot
else if (
(
that.element.STATE == OpenNebulaVM.STATES.ACTIVE) &&
(
@ -178,8 +166,7 @@ define(function(require) {
(
disk.HOTPLUG_SAVE_AS_ACTIVE == "YES")
) {
save_as = (disk.SAVE_AS ? disk.SAVE_AS : '-');
actions = Locale.tr('hot snapshot in progress');
actions = Locale.tr('Save as in progress');
}
// Attach / Detach
else if (
@ -190,30 +177,21 @@ define(function(require) {
(
disk.ATTACH = "YES")
) {
save_as = (disk.SAVE_AS ? disk.SAVE_AS : '-');
actions = Locale.tr('attach/detach in progress');
} else {
save_as = (disk.SAVE_AS ? disk.SAVE_AS : '-');
actions = '';
if (disk.SAVE == "YES") {
/* TODO if (Config.isTabActionEnabled("vms-tab", "VM.disk_snapshot_cancel")) {
if (StateActions.enabledStateAction("VM.disk_snapshot_cancel", that.element.STATE, that.element.LCM_STATE)) {
actions += '<a href="VM.disk_snapshot_cancel" class="disk_snapshot_cancel" >\
<i class="fa fa-times"/></span>' + Locale.tr("Cancel Snapshot") + '</a> &emsp;'
}
} */
} else {
/* TODO if (Config.isTabActionEnabled("vms-tab", "VM.saveas")) {
// Check if it's volatile
if (disk.IMAGE_ID &&
StateActions.enabledStateAction("VM.saveas", that.element.STATE, that.element.LCM_STATE)) {
actions += '<a href="VM.saveas" class="saveas" ><i class="fa fa-save"/>' + Locale.tr("Snapshot") + '</a> &emsp;'
}
} */
if (Config.isTabActionEnabled("vms-tab", "VM.disk_saveas")) {
// Check if it's volatile
if (disk.IMAGE_ID &&
StateActions.enabledStateAction("VM.disk_saveas", that.element.STATE, that.element.LCM_STATE)) {
actions += '<a href="VM.disk_saveas" class="disk_saveas nowrap" >\
<i class="fa fa-save"></i>' + Locale.tr("Save as") + '</a> &emsp;';
}
}
if (Config.isTabActionEnabled("vms-tab", "VM.detachdisk")) {
if (StateActions.enabledStateAction("VM.detachdisk", that.element.STATE, that.element.LCM_STATE) && !disk.CONTEXT) {
actions += ('<a href="VM.detachdisk" class="detachdisk nowrap" >\
@ -238,7 +216,6 @@ define(function(require) {
TARGET : disk.TARGET,
IMAGE : (disk.IMAGE ? disk.IMAGE : (Humanize.sizeFromMB(disk.SIZE) + (disk.FORMAT ? (' - ' + disk.FORMAT) : ''))),
SAVE : ((disk.SAVE && disk.SAVE == 'YES') ? Locale.tr('YES') : Locale.tr('NO')),
SAVE_AS : save_as,
ACTIONS : actions,
SNAPSHOTS : snapshotsHtml[disk.DISK_ID]
});
@ -259,9 +236,7 @@ define(function(require) {
{"data": "TARGET", "defaultContent": ""},
{"data": "IMAGE", "defaultContent": "", "orderable": false},
{"data": "SAVE", "defaultContent": "", "orderable": false},
{"data": "SAVE_AS", "defaultContent": "", "orderable": false},
{"data": "ACTIONS", "defaultContent": "", "orderable": false},
{"defaultContent": "", "orderable": false}
{"data": "ACTIONS", "defaultContent": "", "orderable": false}
],
"fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
@ -298,32 +273,39 @@ define(function(require) {
}
});
/* TODO if (Config.isTabActionEnabled("vms-tab", "VM.saveas")) {
setupSaveAsDialog();
if (Config.isTabActionEnabled("vms-tab", "VM.disk_saveas")) {
context.off('click', '.disk_saveas');
context.on('click', '.disk_saveas', function() {
var disk_id = $(this).parents('tr').attr('disk_id');
$('a.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 dialog = Sunstone.getDialog(DISK_SAVEAS_DIALOG_ID);
dialog.setParams(
{ element: that.element,
diskId: disk_id
});
popUpSaveAsDialog(vm_id, disk_id);
//b.html(spinner);
return false;
dialog.reset();
dialog.show();
return false;
});
} */
/* TODO if (Config.isTabActionEnabled("vms-tab", "VM.disk_snapshot_cancel")) {
$('a.disk_snapshot_cancel').live('click', function(){
var b = $(this);
var vm_id = b.parents('form').attr('vmid');
var disk_id = b.parents('tr').attr('disk_id');
context.off('click', '.disk_snapshot_saveas');
context.on('click', '.disk_snapshot_saveas', function() {
var disk_id = $(this).parents('.snapshots').attr('disk_id');
var snapshot_id = $(this).parents('.snapshot_row').attr('snapshot_id');
Sunstone.runAction('VM.disk_snapshot_cancel', vm_id, disk_id);
var dialog = Sunstone.getDialog(DISK_SAVEAS_DIALOG_ID);
dialog.setParams(
{ element: that.element,
diskId: disk_id,
snapshotId: snapshot_id
});
return false;
dialog.reset();
dialog.show();
return false;
});
} */
}
if (Config.isTabActionEnabled("vms-tab", "VM.attachdisk")) {
context.off('click', '#attach_disk');
@ -355,6 +337,7 @@ define(function(require) {
diskId: disk_id
});
dialog.reset();
dialog.show();
return false;
});
@ -410,7 +393,7 @@ define(function(require) {
});
}
var html = '<div class="snapshot_row" snapshot_id='+snapshot.ID+'>';
var html = '<div class="snapshot_row nowrap" snapshot_id='+snapshot.ID+'>';
var active = (snapshot.ACTIVE == "YES");
@ -423,6 +406,11 @@ define(function(require) {
html += Humanize.prettyTime(snapshot.DATE) + SPACE +
(snapshot.TAG ? snapshot.TAG + SPACE : '');
if (Config.isTabActionEnabled("vms-tab", "VM.disk_saveas")) {
html += '<a href="" class="disk_snapshot_saveas" >\
<i class="fa fa-save"></i>' + Locale.tr("Save as") + '</a> &emsp;';
}
if(!active){
if (Config.isTabActionEnabled("vms-tab", "VM.disk_snapshot_revert")) {
html += '<a href="VM.disk_snapshot_revert" class="disk_snapshot_revert" ><i class="fa fa-reply"/>' + Locale.tr("Revert") + '</a> &emsp;';

View File

@ -19,7 +19,7 @@ define(function(require) {
["VM.delete", "VM.delete_recreate", "VM.resume", "VM.deploy"];
STATE_ACTIONS[OpenNebulaVM.STATES.SUSPENDED] =
["VM.delete", "VM.resume", "VM.saveas", "VM.disk_snapshot_cancel", "VM.stop", "VM.shutdown_hard"];
["VM.delete", "VM.resume", "VM.disk_saveas", "VM.stop", "VM.shutdown_hard"];
STATE_ACTIONS[OpenNebulaVM.STATES.DONE] =
[];
@ -28,7 +28,7 @@ define(function(require) {
["VM.delete", "VM.delete_recreate", "VM.resize"];
STATE_ACTIONS[OpenNebulaVM.STATES.POWEROFF] =
["VM.delete", "VM.resume", "VM.resize", "VM.attachdisk", "VM.detachdisk", "VM.attachnic", "VM.detachnic", "VM.saveas", "VM.disk_snapshot_cancel", "VM.migrate", "VM.undeploy", "VM.undeploy_hard", "VM.shutdown_hard"];
["VM.delete", "VM.resume", "VM.resize", "VM.attachdisk", "VM.detachdisk", "VM.attachnic", "VM.detachnic", "VM.disk_saveas", "VM.migrate", "VM.undeploy", "VM.undeploy_hard", "VM.shutdown_hard"];
STATE_ACTIONS[OpenNebulaVM.STATES.UNDEPLOYED] =
["VM.delete", "VM.delete_recreate", "VM.resume", "VM.resize", "VM.deploy"];
@ -39,7 +39,7 @@ define(function(require) {
LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.PROLOG ] = [];
LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.BOOT ] = [];
LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.RUNNING ] =
["VM.shutdown", "VM.shutdown_hard", "VM.stop", "VM.suspend", "VM.reboot", "VM.reboot_hard", "VM.resched", "VM.unresched", "VM.poweroff", "VM.poweroff_hard", "VM.undeploy", "VM.undeploy_hard", "VM.migrate", "VM.migrate_live", "VM.attachdisk", "VM.detachdisk", "VM.attachnic", "VM.detachnic", "VM.saveas", "VM.disk_snapshot_cancel"];
["VM.shutdown", "VM.shutdown_hard", "VM.stop", "VM.suspend", "VM.reboot", "VM.reboot_hard", "VM.resched", "VM.unresched", "VM.poweroff", "VM.poweroff_hard", "VM.undeploy", "VM.undeploy_hard", "VM.migrate", "VM.migrate_live", "VM.attachdisk", "VM.detachdisk", "VM.attachnic", "VM.detachnic", "VM.disk_saveas"];
LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.MIGRATE ] = [];
LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.SAVE_STOP ] = [];
LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.SAVE_SUSPEND ] = [];
@ -53,7 +53,7 @@ define(function(require) {
LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.FAILURE ] = [];
LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.CLEANUP_RESUBMIT ] = [];
LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.UNKNOWN ] =
["VM.shutdown", "VM.shutdown_hard", "VM.resched", "VM.unresched", "VM.poweroff", "VM.poweroff_hard", "VM.undeploy", "VM.undeploy_hard", "VM.migrate", "VM.migrate_live", "VM.disk_snapshot_cancel", "VM.resume"];
["VM.shutdown", "VM.shutdown_hard", "VM.resched", "VM.unresched", "VM.poweroff", "VM.poweroff_hard", "VM.undeploy", "VM.undeploy_hard", "VM.migrate", "VM.migrate_live", "VM.resume"];
LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.HOTPLUG ] = [];
LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.SHUTDOWN_POWEROFF ] = [];
LCM_STATE_ACTIONS[ OpenNebulaVM.LCM_STATES.BOOT_UNKNOWN ] = [];