mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-20 14:03:36 +03:00
Feature #3748: Add Save as VM Template operation to admin view
This commit is contained in:
parent
135ba1cb24
commit
f7f7a0a783
@ -334,6 +334,9 @@ define(function(require) {
|
||||
"suspend": function(params) {
|
||||
OpenNebulaAction.simple_action(params, RESOURCE, "suspend");
|
||||
},
|
||||
"save_as_template": function(params) {
|
||||
OpenNebulaAction.simple_action(params, RESOURCE, "save_as_template");
|
||||
},
|
||||
"resume": function(params) {
|
||||
OpenNebulaAction.simple_action(params, RESOURCE, "resume");
|
||||
},
|
||||
|
@ -485,7 +485,7 @@ define(function(require) {
|
||||
},
|
||||
success: function(request, response){
|
||||
OpenNebula.Action.clear_cache("VMTEMPLATE");
|
||||
Notifier.notifyMessage(Locale.tr("Image") + ' ' + request.request.data[0][1].name + ' ' + Locale.tr("saved successfully"))
|
||||
Notifier.notifyMessage(Locale.tr("VM Template") + ' ' + request.request.data[0][1].name + ' ' + Locale.tr("saved successfully"))
|
||||
update_provision_vm_info(vm_id, context);
|
||||
button.removeAttr("disabled");
|
||||
},
|
||||
|
@ -17,7 +17,8 @@ define(function(require) {
|
||||
require('./vms-tab/dialogs/attach-nic'),
|
||||
require('./vms-tab/dialogs/snapshot'),
|
||||
require('./vms-tab/dialogs/vnc'),
|
||||
require('./vms-tab/dialogs/spice')
|
||||
require('./vms-tab/dialogs/spice'),
|
||||
require('./vms-tab/dialogs/saveas-template')
|
||||
];
|
||||
|
||||
var _panels = [
|
||||
|
@ -8,11 +8,12 @@ define(function(require) {
|
||||
var Spice = require('utils/spice');
|
||||
|
||||
var TAB_ID = require('./tabId');
|
||||
var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId');
|
||||
var DEPLOY_DIALOG_ID = require('./dialogs/deploy/dialogId');
|
||||
var MIGRATE_DIALOG_ID = require('./dialogs/migrate/dialogId');
|
||||
var VNC_DIALOG_ID = require('./dialogs/vnc/dialogId');
|
||||
var SPICE_DIALOG_ID = require('./dialogs/spice/dialogId');
|
||||
var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId');
|
||||
var DEPLOY_DIALOG_ID = require('./dialogs/deploy/dialogId');
|
||||
var MIGRATE_DIALOG_ID = require('./dialogs/migrate/dialogId');
|
||||
var VNC_DIALOG_ID = require('./dialogs/vnc/dialogId');
|
||||
var SPICE_DIALOG_ID = require('./dialogs/spice/dialogId');
|
||||
var SAVE_AS_TEMPLATE_DIALOG_ID = require('./dialogs/saveas-template/dialogId');
|
||||
|
||||
var XML_ROOT = "VM";
|
||||
var RESOURCE = "VM";
|
||||
@ -163,7 +164,18 @@ define(function(require) {
|
||||
Spice.unlock();
|
||||
},
|
||||
notify: true
|
||||
}
|
||||
},
|
||||
"VM.saveas_template" : {
|
||||
type: "single",
|
||||
call: function() {
|
||||
var dialog = Sunstone.getDialog(SAVE_AS_TEMPLATE_DIALOG_ID);
|
||||
dialog.show();
|
||||
},
|
||||
error: function(req, resp) {
|
||||
Notifier.onError(req, resp);
|
||||
},
|
||||
notify: false
|
||||
},
|
||||
};
|
||||
|
||||
return _actions;
|
||||
|
@ -39,7 +39,6 @@ define(function(require) {
|
||||
tip: Locale.tr("This will migrate the selected VMs to the chosen host"),
|
||||
layout: "vmsplanification_buttons",
|
||||
custom_classes : "state-dependent"
|
||||
|
||||
},
|
||||
"VM.migrate_live" : {
|
||||
type: "action",
|
||||
@ -194,7 +193,13 @@ define(function(require) {
|
||||
text: '<i class="fa fa-desktop" style="color: rgb(111, 111, 111)"/> ' + Locale.tr("SPICE"),
|
||||
custom_classes: "only-right-info spice-right-info",
|
||||
tip: Locale.tr("SPICE")
|
||||
}
|
||||
},
|
||||
"VM.saveas_template" : {
|
||||
type: "action",
|
||||
text: '<i class="fa fa-save"/>',
|
||||
tip: Locale.tr("This Virtual Machine will be saved in a new Template. You can then create a new Virtual Machine using this Template"),
|
||||
custom_classes : "state-dependent"
|
||||
},
|
||||
}
|
||||
|
||||
return Buttons;
|
||||
|
@ -0,0 +1,88 @@
|
||||
define(function(require) {
|
||||
/*
|
||||
DEPENDENCIES
|
||||
*/
|
||||
|
||||
var BaseDialog = require('utils/dialogs/dialog');
|
||||
var TemplateHTML = require('hbs!./saveas-template/html');
|
||||
var Sunstone = require('sunstone');
|
||||
var OpenNebula = require('opennebula');
|
||||
var Notifier = require('utils/notifier');
|
||||
var Tips = require('utils/tips');
|
||||
|
||||
/*
|
||||
CONSTANTS
|
||||
*/
|
||||
|
||||
var DIALOG_ID = require('./saveas-template/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;
|
||||
|
||||
return Dialog;
|
||||
|
||||
/*
|
||||
FUNCTION DEFINITIONS
|
||||
*/
|
||||
|
||||
function _html() {
|
||||
return TemplateHTML({
|
||||
'dialogId': this.dialogId
|
||||
});
|
||||
}
|
||||
|
||||
function _setup(context) {
|
||||
var that = this;
|
||||
|
||||
Tips.setup(context);
|
||||
|
||||
|
||||
$('#' + DIALOG_ID + 'Form', context).submit(function() {
|
||||
var template_name = $('#template_name', this).val();
|
||||
var vm_id = $("#vm_id", context).val();
|
||||
|
||||
OpenNebula.VM.save_as_template({
|
||||
data : {
|
||||
id: vm_id,
|
||||
extra_param: {
|
||||
name : template_name
|
||||
}
|
||||
},
|
||||
success: function(request, response){
|
||||
OpenNebula.Action.clear_cache("VMTEMPLATE");
|
||||
Notifier.notifyMessage(Locale.tr("VM Template") + ' ' + template_name + ' ' + Locale.tr("saved successfully"))
|
||||
},
|
||||
error: function(request, response){
|
||||
Notifier.onError(request, response);
|
||||
}
|
||||
})
|
||||
|
||||
Sunstone.getDialog(DIALOG_ID).hide();
|
||||
Sunstone.getDialog(DIALOG_ID).reset();
|
||||
return false;
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function _onShow(context) {
|
||||
$("#vm_id", context).val(Sunstone.getDataTable(TAB_ID).elements());
|
||||
$("#template_name", context).focus();
|
||||
return false;
|
||||
}
|
||||
});
|
@ -0,0 +1,3 @@
|
||||
define(function(require) {
|
||||
return 'saveAsTemplate';
|
||||
})
|
@ -0,0 +1,27 @@
|
||||
<div id="{{dialogId}}" class="reveal-modal small" role="dialog" data-reveal >
|
||||
<div class="row">
|
||||
<div class="large-12 columns">
|
||||
<h3 class="subheader" id="">{{tr "Save as Template"}}</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>
|
||||
<div class="row">
|
||||
<div class="large-12 columns">
|
||||
<label for="template_name">{{tr "Template name"}}:</label>
|
||||
<input type="text" name="template_name" id="template_name" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form_buttons">
|
||||
<button class="button radius right success" type="submit">{{tr "Save As Template"}}</button>
|
||||
</div>
|
||||
<a class="close-reveal-modal">×</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
@ -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.disk_saveas", "VM.disk_snapshot_create", "VM.disk_snapshot_revert", "VM.disk_snapshot_delete", "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.disk_snapshot_create", "VM.disk_snapshot_revert", "VM.disk_snapshot_delete", "VM.migrate", "VM.undeploy", "VM.undeploy_hard", "VM.shutdown_hard", "VM.saveas_template"];
|
||||
|
||||
STATE_ACTIONS[OpenNebulaVM.STATES.UNDEPLOYED] =
|
||||
["VM.delete", "VM.delete_recreate", "VM.resume", "VM.resize", "VM.deploy"];
|
||||
|
Loading…
x
Reference in New Issue
Block a user