1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

Bug #5280: Solved bug linked clones (#463)

* B #5280 Added linked clone option for vCenter VM Templates

* Added options linked clones

* Added linked clones to VM Template

* Added js events

* B #5280 Solved bug linked clones
This commit is contained in:
Abel Coronado 2017-09-08 14:55:25 +02:00 committed by Tino Vázquez
parent 06e4e28bfb
commit 23bd00e642
3 changed files with 129 additions and 56 deletions

View File

@ -123,6 +123,24 @@ define(function(require) {
var trow = $(RowTemplate(opts)).appendTo(tbody);
$("#linked_clone_"+opts.id).on("change", function(){
if ($("#linked_clone_"+opts.id).is(":checked")){
$("#create_"+opts.id).show();
} else {
$("#create_"+opts.id).hide();
$("#create_copy_"+opts.id).prop("checked", false);
$("#name_"+opts.id).hide();
}
});
$("#create_copy_"+opts.id).on("change", function(){
if ($("#create_copy_"+opts.id).is(":checked")){
$("#name_"+opts.id).show();
} else {
$("#name_"+opts.id).hide();
}
});
$('.check_item', trow).data("import_data", element);
});
@ -353,13 +371,13 @@ define(function(require) {
});
}
if (disks_and_nets[index].type == "EXISTING_NIC") {
if (disks_and_nets[index] != undefined && disks_and_nets[index].type == "EXISTING_NIC") {
template += disks_and_nets[index].network_tmpl;
++index;
getNext();
}
if (disks_and_nets[index].type === "DUPLICATED_NIC") {
if (disks_and_nets[index] != undefined && disks_and_nets[index].type == "DUPLICATED_NIC") {
var network_id = duplicated_nics[disks_and_nets[index].network_name];
template += "NIC=[\n";
@ -394,6 +412,26 @@ define(function(require) {
var rpModify = $('.modify_rp', rpInput).val();
var rpInitial = $('.initial_rp', rpInput).val();
var rpParams = "";
var linkedClone = $('.linked_clone', rpInput).prop("checked");
var createCopy = $('.create_copy', rpInput).prop("checked");
var templateName = $('.template_name', rpInput).val();
var vcenter_ref = $(this).data("import_data").vcenter_ref;
if(linkedClone){
var linked = true;
if(createCopy && templateName != ""){
var copy = true;
var template_name = templateName;
} else {
var copy = false;
var template_name = "";
}
} else {
var template_name = "";
var linked = false;
var copy = false;
}
$.each($('.available_rps option:selected', rpInput), function(){
rpParams += $(this).val() + ",";
});
@ -428,11 +466,8 @@ define(function(require) {
var template_json = {
"vmtemplate": { "template_raw": template }
};
var vcenter_ref = $(this).data("import_data").vcenter_ref;
OpenNebulaTemplate.create({
timeout: true,
timeout: false,
data: template_json,
success: function(request, response) {
VCenterCommon.importLoading({
@ -445,7 +480,12 @@ define(function(require) {
$.ajax({
url: path,
type: "GET",
data: {timeout: false},
data: {
timeout: false,
use_linked_clones: linked,
create_copy: copy,
template_name: template_name
},
headers: {
"X-VCENTER-USER": that.opts.vcenter_user,
"X-VCENTER-PASSWORD": that.opts.vcenter_password,
@ -453,8 +493,29 @@ define(function(require) {
},
dataType: "json",
success: function(response){
var disks_and_nets = response.disks.concat(response.nics)
import_images_and_nets(disks_and_nets, row_context, template_id)
var disks_and_nets = response.disks.concat(response.nics);
var template_json = {
"vmtemplate": { "template_raw": response.one }
};
if(response.create_copy){
OpenNebulaTemplate.del({
timeout: true,
data : {
id : template_id
},
success: function(){
OpenNebulaTemplate.create({
timeout: false,
data: template_json,
success: function(request, response){
import_images_and_nets(disks_and_nets, row_context, response.VMTEMPLATE.ID);
}
});
}
});
} else {
import_images_and_nets(disks_and_nets, row_context, template_id);
}
},
error: function(response){
VCenterCommon.importFailure({

View File

@ -60,10 +60,33 @@
</label>
</div>
</div>
<div class="row">
<div class="large-11 large-centered columns" style="margin-top: 20px">
<div class="medium-2 columns">
<label>
{{tr "Linked clone"}}
<input type="checkbox" class="linked_clone" id="linked_clone_{{id}}"/>
</label>
</div>
<div class="medium-2 columns" id="create_{{id}}" hidden>
<label>
{{tr "Create copy"}}
<input type="checkbox" class="create_copy" id="create_copy_{{id}}"/>
</label>
</div>
<div class="medium-6 columns" id="name_{{id}}" hidden>
<label>
{{tr "Template name"}}
<input class="template_name" id="template_name_{{id}}"/>
</label>
</div>
</div>
</div>
{{/if}}
</div>
</div>
</div>
</div>
<div class="row vcenter_import_result_row" style="display:none">
<div class="large-11 large-centered columns">
<span class="vcenter_import_result">

View File

@ -234,7 +234,6 @@ post '/vcenter/wild_rollback/:vm_id' do
end
end
get '/vcenter/template/:vcenter_ref/:template_id' do
begin
t = {}
@ -246,6 +245,9 @@ get '/vcenter/template/:vcenter_ref/:template_id' do
ref = params[:vcenter_ref]
template_id = params[:template_id]
use_linked_clones = params[:use_linked_clones] || false
create_copy = params[:create_copy] || false
template_name = params[:template_name] || ""
if !ref || ref.empty?
msg = "No template ref specified"
@ -290,62 +292,50 @@ get '/vcenter/template/:vcenter_ref/:template_id' do
end
# POST params
if @request_body && !@request_body.empty?
body_hash = JSON.parse(@request_body)
use_linked_clones = body_hash['use_linked_clones'] || false
create_copy = body_hash['create_copy'] || false
template_name = body_hash['template_name'] || ""
if !use_linked_clones && (create_copy || !template_name.empty?)
msg = "Should not set create template copy or template copy name if not using linked clones"
logger.error("[vCenter] " + msg)
error = Error.new(msg)
error 403, error.to_json
end
if !use_linked_clones && (create_copy || !template_name.empty?)
msg = "Should not set create template copy or template copy name if not using linked clones"
logger.error("[vCenter] " + msg)
error = Error.new(msg)
error 403, error.to_json
end
if use_linked_clones && !create_copy && !template_name.empty?
msg = "Should not set template copy name if create template copy hasn't been selected"
logger.error("[vCenter] " + msg)
error = Error.new(msg)
error 403, error.to_json
end
if use_linked_clones && !create_copy && !template_name.empty?
msg = "Should not set template copy name if create template copy hasn't been selected"
logger.error("[vCenter] " + msg)
error = Error.new(msg)
error 403, error.to_json
end
if create_copy
if create_copy
lc_error, template_copy_ref = template.create_template_copy(template_name)
lc_error, template_copy_ref = template.create_template_copy(template_name)
if template_copy_ref
template = VCenterDriver::Template.new_from_ref(template_copy_ref, vcenter_client)
one_template = VCenterDriver::Template.get_xml_template(template, vc_uuid, vcenter_client, vcenter_client.vim.host)
if one_template
lc_error, use_lc = template.create_delta_disks
if !lc_error
one_template[:one] << "\nVCENTER_LINKED_CLONES=\"YES\"\n"
t = one_template
append = false # t[:one] replaces the current template
end
else
lc_error = "Could not obtain the info from the template's copy"
template.delete_template if template_copy_ref
if template_copy_ref
template = VCenterDriver::Template.new_from_ref(template_copy_ref, vcenter_client)
one_template = VCenterDriver::Template.get_xml_template(template, vc_uuid, vcenter_client, vcenter_client.vim.host, "Datacenter")
if one_template
lc_error, use_lc = template.create_delta_disks
if !lc_error
one_template[:one] << "\nVCENTER_LINKED_CLONES=\"YES\"\n"
one_template[:create_copy] = "YES"
t = one_template
append = false # t[:one] replaces the current template
end
else
lc_error = "Could not obtain the info from the template's copy"
template.delete_template if template_copy_ref
end
else
lc_error, use_lc = template.create_delta_disks
if !lc_error
append = true
t[:one] << "\nVCENTER_LINKED_CLONES=\"YES\"\n" if use_lc
end
end
else
lc_error, use_lc = template.create_delta_disks
if !lc_error
append = true
t[:one] << "\nVCENTER_LINKED_CLONES=\"YES\"\n" if use_lc
end
end
# Create images or get disks information for template
error, template_disks = template.import_vcenter_disks(vc_uuid, dpool, ipool, true, template_id)
if !error.empty?
append = false
template.delete_template if template_copy_ref
@ -387,7 +377,6 @@ get '/vcenter/template/:vcenter_ref/:template_id' do
t[:lc_error] = lc_error
t[:append] = append
[200, t.to_json]
rescue Exception => e
template.delete_template if template_copy_ref