mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-29 18:50:08 +03:00
Feature #872: Add clone operation to Sunstone templates
(cherry picked from commit 6aef096bf90a87994015e775d2a67819ba1126da)
This commit is contained in:
parent
dd6f8b22fa
commit
712bba5714
@ -48,6 +48,7 @@ module OpenNebulaJSON
|
||||
when "chown" then self.chown(action_hash['params'])
|
||||
when "chmod" then self.chmod_octet(action_hash['params'])
|
||||
when "instantiate" then self.instantiate(action_hash['params'])
|
||||
when "clone" then self.clone(action_hash['params'])
|
||||
else
|
||||
error_msg = "#{action_hash['perform']} action not " <<
|
||||
" available for this resource"
|
||||
@ -71,5 +72,9 @@ module OpenNebulaJSON
|
||||
super(params['vm_name'])
|
||||
end
|
||||
|
||||
def clone(params=Hash.new)
|
||||
super(params['name'])
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -849,12 +849,16 @@ var OpenNebula = {
|
||||
"unpublish" : function(params){
|
||||
OpenNebula.Action.simple_action(params,OpenNebula.Template.resource,"unpublish");
|
||||
},
|
||||
|
||||
"instantiate" : function(params) {
|
||||
var vm_name = params.data.extra_param ? params.data.extra_param : "";
|
||||
var action_obj = { "vm_name" : vm_name };
|
||||
OpenNebula.Action.simple_action(params,OpenNebula.Template.resource,
|
||||
"instantiate",action_obj);
|
||||
},
|
||||
"clone" : function(params) {
|
||||
var name = params.data.extra_param ? params.data.extra_param : "";
|
||||
var action_obj = { "name" : name };
|
||||
OpenNebula.Action.simple_action(params,OpenNebula.Template.resource, "clone", action_obj);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -781,7 +781,16 @@ var template_actions = {
|
||||
error: onError,
|
||||
notify: true
|
||||
},
|
||||
|
||||
"Template.clone_dialog" : {
|
||||
type: "custom",
|
||||
call: popUpTemplateCloneDialog
|
||||
},
|
||||
"Template.clone" : {
|
||||
type: "single",
|
||||
call: OpenNebula.Template.clone,
|
||||
error: onError,
|
||||
notify: true
|
||||
},
|
||||
"Template.help" : {
|
||||
type: "custom",
|
||||
call: function() {
|
||||
@ -824,7 +833,10 @@ var template_buttons = {
|
||||
tip: tr("Select the new group")+":",
|
||||
condition: mustBeAdmin
|
||||
},
|
||||
|
||||
"Template.clone_dialog" : {
|
||||
type: "action",
|
||||
text: tr("Clone"),
|
||||
},
|
||||
"Template.delete" : {
|
||||
type: "confirm",
|
||||
text: tr("Delete")
|
||||
@ -2137,6 +2149,78 @@ function popUpTemplateTemplateUpdateDialog(){
|
||||
|
||||
};
|
||||
|
||||
function setupTemplateCloneDialog(){
|
||||
//Append to DOM
|
||||
dialogs_context.append('<div id="template_clone_dialog" title="'+tr("Clone a template")+'"></div>');
|
||||
var dialog = $('#template_clone_dialog',dialogs_context);
|
||||
|
||||
//Put HTML in place
|
||||
|
||||
var html = '<form><fieldset>\
|
||||
<div class="clone_one">'+tr("Choose a new name for the template")+':</div>\
|
||||
<div class="clone_several">'+tr("Several templates are selected, please choose prefix to name the new copies")+':</div>\
|
||||
<br />\
|
||||
<label class="clone_one">'+tr("Name")+':</label>\
|
||||
<label class="clone_several">'+tr("Prefix")+':</label>\
|
||||
<input type="text" name="name"></input>\
|
||||
<div class="form_buttons">\
|
||||
<button class="button" id="template_clone_button" value="Template.clone">\
|
||||
'+tr("Clone")+'\
|
||||
</button>\
|
||||
</div></fieldset></form>\
|
||||
';
|
||||
|
||||
dialog.html(html);
|
||||
|
||||
//Convert into jQuery
|
||||
dialog.dialog({
|
||||
autoOpen:false,
|
||||
width:375,
|
||||
modal:true,
|
||||
resizable:false,
|
||||
});
|
||||
|
||||
$('button',dialog).button();
|
||||
|
||||
$('form',dialog).submit(function(){
|
||||
var name = $('input', this).val();
|
||||
var sel_elems = templateElements();
|
||||
if (!name || !sel_elems.length)
|
||||
notifyError('A name or prefix is needed!');
|
||||
if (sel_elems.length > 1){
|
||||
for (var i=0; i< sel_elems.length; i++)
|
||||
Sunstone.runAction('Template.clone',
|
||||
sel_elems[i],
|
||||
name+getTemplateName(sel_elems[i]));
|
||||
} else {
|
||||
Sunstone.runAction('Template.clone',sel_elems[0],name)
|
||||
};
|
||||
$(this).parents('#template_clone_dialog').dialog('close');
|
||||
setTimeout(function(){
|
||||
Sunstone.runAction('Template.refresh');
|
||||
}, 1500);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function popUpTemplateCloneDialog(){
|
||||
var dialog = $('#template_clone_dialog');
|
||||
var sel_elems = templateElements();
|
||||
//show different text depending on how many elements are selected
|
||||
if (sel_elems.length > 1){
|
||||
$('.clone_one',dialog).hide();
|
||||
$('.clone_several',dialog).show();
|
||||
$('input',dialog).val('Copy of ');
|
||||
}
|
||||
else {
|
||||
$('.clone_one',dialog).show();
|
||||
$('.clone_several',dialog).hide();
|
||||
$('input',dialog).val('Copy of '+getTemplateName(sel_elems[0]));
|
||||
};
|
||||
|
||||
$(dialog).dialog('open');
|
||||
}
|
||||
|
||||
// Set the autorefresh interval for the datatable
|
||||
function setTemplateAutorefresh() {
|
||||
setInterval(function(){
|
||||
@ -2182,6 +2266,7 @@ $(document).ready(function(){
|
||||
|
||||
setupCreateTemplateDialog();
|
||||
setupTemplateTemplateUpdateDialog();
|
||||
setupTemplateCloneDialog();
|
||||
setTemplateAutorefresh();
|
||||
|
||||
initCheckAllBoxes(dataTable_templates);
|
||||
|
@ -464,6 +464,13 @@ function getHostName(id){
|
||||
return id;
|
||||
};
|
||||
|
||||
function getTemplateName(id){
|
||||
if (typeof(dataTable_templates) != "undefined"){
|
||||
return getName(id,dataTable_templates,4);
|
||||
}
|
||||
return id;
|
||||
};
|
||||
|
||||
function getName(id,dataTable,name_col){
|
||||
var name = id;
|
||||
if (typeof(dataTable) == "undefined") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user