foreman/app/assets/javascripts/host_edit.js @ 5f58478b
1e1b2f13 | Ohad Levy | $(document).on('ContentLoad', function(){onHostEditLoad()});
|
|
bd6ed217 | Joseph Magen | $(document).on('AddedClass', function(event, link){load_puppet_class_parameters(link)});
|
|
1e1b2f13 | Ohad Levy | ||
334d0359 | Amos Benari | function computeResourceSelected(item){
|
|
var compute = $(item).val();
|
|||
if(compute=='') { //Bare Metal
|
|||
$('#mac_address').show();
|
|||
c8d89c66 | Amos Benari | $("#model_name").show();
|
|
334d0359 | Amos Benari | $('#compute_resource').empty();
|
|
$('#vm_details').empty();
|
|||
$("#compute_resource_tab").hide();
|
|||
c6e02bd3 | Joseph Magen | $("#compute_profile").hide();
|
|
dd42df0a | Ohad Levy | update_capabilities('build');
|
|
334d0359 | Amos Benari | }
|
|
3f482b82 | Ohad Levy | else
|
|
{
|
|||
334d0359 | Amos Benari | $('#mac_address').hide();
|
|
c8d89c66 | Amos Benari | $("#model_name").hide();
|
|
334d0359 | Amos Benari | $("#compute_resource_tab").show();
|
|
c6e02bd3 | Joseph Magen | $("#compute_profile").show();
|
|
334d0359 | Amos Benari | $('#vm_details').empty();
|
|
66afbc33 | Joseph Mitchell Magen | var data = $('form').serialize().replace('method=put', 'method=post');
|
|
ad01d4d2 | Walden Raines | $('#compute_resource').html(spinner_placeholder(__('Loading virtual machine information ...')));
|
|
5d8ef4cb | Amos Benari | $('#compute_resource_tab a').removeClass('tab-error');
|
|
$(item).indicator_show();
|
|||
334d0359 | Amos Benari | var url = $(item).attr('data-url');
|
|
$.ajax({
|
|||
type:'post',
|
|||
url: url,
|
|||
66afbc33 | Joseph Mitchell Magen | data: data,
|
|
5d8ef4cb | Amos Benari | complete: function(){$(item).indicator_hide()},
|
|
error: function(jqXHR, status, error){
|
|||
ad01d4d2 | Walden Raines | $('#compute_resource').html(Jed.sprintf(__("Error loading virtual machine information: %s"), error));
|
|
5d8ef4cb | Amos Benari | $('#compute_resource_tab a').addClass('tab-error');
|
|
},
|
|||
334d0359 | Amos Benari | success: function(result){
|
|
dd42df0a | Ohad Levy | $('#compute_resource').html(result);
|
|
5d6ab0b1 | Amos Benari | if ($('#compute_resource').find('.alert-danger').length > 0) $('#compute_resource_tab a').addClass('tab-error');
|
|
dd42df0a | Ohad Levy | update_capabilities($('#capabilities').val());
|
|
334d0359 | Amos Benari | }
|
|
})
|
|||
}
|
|||
}
|
|||
dd42df0a | Ohad Levy | function update_capabilities(capabilities){
|
|
3d03e334 | Dominic Cleal | $('#image_provisioning').empty();
|
|
$('#image_selection').appendTo($('#image_provisioning'));
|
|||
update_provisioning_image();
|
|||
$('#manage_network').empty();
|
|||
$('#subnet_selection').appendTo($('#manage_network'));
|
|||
dd42df0a | Ohad Levy | var build = (/build/i.test(capabilities));
|
|
var image = (/image/i.test(capabilities));
|
|||
if (build){
|
|||
beed05de | Mark O'Shea | $('#manage_network_build').show();
|
|
dd42df0a | Ohad Levy | $('#host_provision_method_build').click();
|
|
3d03e334 | Dominic Cleal | build_provision_method_selected();
|
|
dd42df0a | Ohad Levy | } else {
|
|
beed05de | Mark O'Shea | $('#manage_network_build').hide();
|
|
dd42df0a | Ohad Levy | $('#host_provision_method_image').click();
|
|
3d03e334 | Dominic Cleal | image_provision_method_selected();
|
|
dd42df0a | Ohad Levy | }
|
|
if(build && image){
|
|||
$('#provisioning_method').show();
|
|||
}else{
|
|||
$('#provisioning_method').hide();
|
|||
}
|
|||
beed05de | Mark O'Shea | multiSelectOnLoad();
|
|
dd42df0a | Ohad Levy | }
|
|
var stop_pooling;
|
|||
92326dd2 | Amos Benari | function submit_host(){
|
|
614401fd | Amos Benari | var url = window.location.pathname.replace(/\/edit$|\/new$/,'');
|
|
5f75d98a | Ivan Necas | if(/\/clone$/.test(window.location.pathname)){ url = foreman_url('/hosts'); }
|
|
dd42df0a | Ohad Levy | $('#host_submit').attr('disabled', true);
|
|
stop_pooling = false;
|
|||
$("body").css("cursor", "progress");
|
|||
clear_errors();
|
|||
animate_progress();
|
|||
$.ajax({
|
|||
type:'POST',
|
|||
url: url,
|
|||
92326dd2 | Amos Benari | data: $('form').serialize(),
|
|
dd42df0a | Ohad Levy | success: function(response){
|
|
if(response.redirect){
|
|||
window.location.replace(response.redirect);
|
|||
}
|
|||
else{
|
|||
$("#host-progress").hide();
|
|||
$('#content').replaceWith($("#content", response));
|
|||
1e1b2f13 | Ohad Levy | $(document.body).trigger('ContentLoad');
|
|
5f58478b | Amos Benari | if($("[data-history-url]").exists()){
|
|
history.pushState({}, "Host show", $("[data-history-url]").data('history-url'));
|
|||
}
|
|||
dd42df0a | Ohad Levy | }
|
|
},
|
|||
error: function(response){
|
|||
$('#content').html(response.responseText);
|
|||
},
|
|||
complete: function(){
|
|||
stop_pooling = true;
|
|||
$("body").css("cursor", "auto");
|
|||
$('#host_submit').attr('disabled', false);
|
|||
}
|
|||
});
|
|||
return false;
|
|||
}
|
|||
function clear_errors(){
|
|||
bf4a13d3 | Walden Raines | $('.error').children().children('.help-block').remove();
|
|
dd42df0a | Ohad Levy | $('.error').removeClass('error');
|
|
$('.tab-error').removeClass('tab-error');
|
|||
5d6ab0b1 | Amos Benari | $('.alert-danger').remove();
|
|
dd42df0a | Ohad Levy | }
|
|
function animate_progress(){
|
|||
if (stop_pooling == true) return;
|
|||
setTimeout(function() {
|
|||
92326dd2 | Amos Benari | var url = $('#host_progress_report_id').data('url');
|
|
$.get(url, function (response){
|
|||
dd42df0a | Ohad Levy | update_progress(response);
|
|
animate_progress();
|
|||
})
|
|||
}, 1600);
|
|||
}
|
|||
function update_progress(data){
|
|||
var task_list_size = $('p',data).size();
|
|||
if (task_list_size == 0 || stop_pooling == true) return;
|
|||
bf4a13d3 | Walden Raines | var done_tasks = $('.glyphicon-check',data).size();
|
|
var failed_tasks = $('.glyphicon-remove',data).size();
|
|||
dd42df0a | Ohad Levy | ||
$("#host-progress").show();
|
|||
if(failed_tasks > 0) {
|
|||
5d6ab0b1 | Amos Benari | $('.progress-bar').addClass('progress-bar-danger');
|
|
dd42df0a | Ohad Levy | }else{
|
|
5d6ab0b1 | Amos Benari | $('.progress-bar').removeClass('progress-bar-danger');
|
|
dd42df0a | Ohad Levy | }
|
|
5d6ab0b1 | Amos Benari | $('.progress-bar').width(done_tasks/task_list_size * 100 + '%')
|
|
dd42df0a | Ohad Levy | $('#tasks_progress').replaceWith(data);
|
|
}
|
|||
298756ca | Amos Benari | function load_puppet_class_parameters(item) {
|
|
var id = $(item).attr('data-class-id');
|
|||
0ba99bba | Joseph Mitchell Magen | // host_id could be either host.id OR hostgroup.id depending on which form
|
|
8bfaec2a | Joseph Mitchell Magen | var host_id = $("form").data('id')
|
|
298756ca | Amos Benari | if ($('#puppetclass_' + id + '_params_loading').length > 0) return; // already loading
|
|
if ($('[id^="#puppetclass_' + id + '_params\\["]').length > 0) return; // already loaded
|
|||
var url = $(item).attr('data-url');
|
|||
1f1367d6 | Amos Benari | var data = $("form").serialize().replace('method=put', 'method=post');
|
|
8bfaec2a | Joseph Mitchell Magen | data = data + '&host_id=' + host_id
|
|
298756ca | Amos Benari | ||
if (url == undefined) return; // no parameters
|
|||
var placeholder = $('<tr id="puppetclass_'+id+'_params_loading">'+
|
|||
ad01d4d2 | Walden Raines | '<td colspan="5">' + spinner_placeholder(__('Loading parameters...')) + '</td></tr>');
|
|
298756ca | Amos Benari | $('#inherited_puppetclasses_parameters').append(placeholder);
|
|
$.ajax({
|
|||
url: url,
|
|||
a25add15 | Amos Benari | type: 'post',
|
|
298756ca | Amos Benari | data: data,
|
|
success: function(result, textstatus, xhr) {
|
|||
var params = $(result);
|
|||
placeholder.replaceWith(params);
|
|||
371c2e86 | Amos Benari | params.find('a[rel="popover"]').popover({html: true});
|
|
298756ca | Amos Benari | if (params.find('.error').length > 0) $('#params-tab').addClass('tab-error');
|
|
}
|
|||
});
|
|||
}
|
|||
017e1049 | Ohad Levy | function hostgroup_changed(element) {
|
|
c5e90813 | Greg Sutcliffe | var host_id = $("form").data('id');
|
|
var host_changed = $("form").data('type-changed');
|
|||
d592994b | Amos Benari | if (host_id) {
|
|
if (host_changed ){
|
|||
update_form(element,{data:"&host[id]="+host_id});
|
|||
} else { // edit host
|
|||
update_puppetclasses(element);
|
|||
reload_host_params();
|
|||
}
|
|||
c5e90813 | Greg Sutcliffe | } else { // a new host
|
|
update_form(element);
|
|||
017e1049 | Ohad Levy | }
|
|
}
|
|||
611f5bff | Amos Benari | function organization_changed(element) {
|
|
feacea35 | Amos Benari | update_form(element);
|
|
611f5bff | Amos Benari | }
|
|
function location_changed(element) {
|
|||
feacea35 | Amos Benari | update_form(element);
|
|
}
|
|||
c5e90813 | Greg Sutcliffe | function update_form(element, options) {
|
|
d592994b | Amos Benari | options = options || {};
|
|
feacea35 | Amos Benari | var url = $(element).data('url');
|
|
611f5bff | Amos Benari | var data = $('form').serialize().replace('method=put', 'method=post');
|
|
c5e90813 | Greg Sutcliffe | if (options.data) data = data+options.data;
|
|
89b9ecb0 | Amos Benari | $(element).indicator_show();
|
|
611f5bff | Amos Benari | $.ajax({
|
|
type: 'post',
|
|||
url: url,
|
|||
data: data,
|
|||
89b9ecb0 | Amos Benari | complete: function(){ $(element).indicator_hide();},
|
|
611f5bff | Amos Benari | success: function(response) {
|
|
0df38871 | Ohad Levy | $('form').replaceWith(response);
|
|
feacea35 | Amos Benari | $("[id$='subnet_id']").first().change();
|
|
66afbc33 | Joseph Mitchell Magen | // to handle case if def process_taxonomy changed compute_resource_id to nil
|
|
if( !$('#host_compute_resource_id').val() ) {
|
|||
$('#host_compute_resource_id').change();
|
|||
}
|
|||
beed05de | Mark O'Shea | update_capabilities($('#host_compute_resource_id').val() ? $('#capabilities').val() : 'build');
|
|
1e1b2f13 | Ohad Levy | $(document.body).trigger('ContentLoad');
|
|
611f5bff | Amos Benari | }
|
|
})
|
|||
}
|
|||
017e1049 | Ohad Levy | function subnet_selected(element){
|
|
var subnet_id = $(element).val();
|
|||
dd42df0a | Ohad Levy | if (subnet_id == '' || $('#host_ip').size() == 0) return;
|
|
fc782b06 | Paul Kelly | // We do not query the proxy if the host_ip field is filled in and contains an
|
|
// IP that is in the selected subnet
|
|||
ba303020 | Sander Hoentjen | var drop_text = $(element).children(":selected").text();
|
|
fc782b06 | Paul Kelly | if (drop_text.length !=0 && drop_text.search(/^.+ \([0-9\.\/]+\)/) != -1) {
|
|
3101210d | Mikael Fridh | var details = drop_text.replace(/^.+\(/, "").replace(")","").split("/");
|
|
fc782b06 | Paul Kelly | if (subnet_contains(details[0], details[1], $('#host_ip').val()))
|
|
dd42df0a | Ohad Levy | return;
|
|
fc782b06 | Paul Kelly | }
|
|
611f5bff | Amos Benari | var attrs = attribute_hash(["subnet_id", "host_mac", 'organization_id', 'location_id']);
|
|
89b9ecb0 | Amos Benari | $(element).indicator_show();
|
|
feacea35 | Amos Benari | var url = $(element).data('url');
|
|
017e1049 | Ohad Levy | $.ajax({
|
|
e89efb28 | Ohad Levy | data: attrs,
|
|
017e1049 | Ohad Levy | type:'post',
|
|
feacea35 | Amos Benari | url: url,
|
|
89b9ecb0 | Amos Benari | complete: function(){ $(element).indicator_hide();},
|
|
feacea35 | Amos Benari | success: function(data){
|
|
$('#host_ip').val(data.ip);
|
|||
}
|
|||
017e1049 | Ohad Levy | })
|
|
}
|
|||
fc782b06 | Paul Kelly | function subnet_contains(number, cidr, ip){
|
|
var int_ip = _to_int(ip);
|
|||
var int_number = _to_int(number);
|
|||
var shift = 32 - parseInt(cidr);
|
|||
return (int_ip >> shift == int_number >> shift);
|
|||
}
|
|||
function _to_int(str){
|
|||
var nibble = str.split(".");
|
|||
var integer = 0;
|
|||
dd42df0a | Ohad Levy | for(var i=0;i<=3;i++){
|
|
fc782b06 | Paul Kelly | integer = (integer * 256) + parseInt(nibble[i]);
|
|
}
|
|||
return integer;
|
|||
}
|
|||
017e1049 | Ohad Levy | function domain_selected(element){
|
|
611f5bff | Amos Benari | var attrs = attribute_hash(['domain_id', 'organization_id', 'location_id']);
|
|
feacea35 | Amos Benari | var url = $(element).data('url');
|
|
89b9ecb0 | Amos Benari | $(element).indicator_show();
|
|
017e1049 | Ohad Levy | $.ajax({
|
|
611f5bff | Amos Benari | data: attrs,
|
|
017e1049 | Ohad Levy | type:'post',
|
|
dd42df0a | Ohad Levy | url: url,
|
|
89b9ecb0 | Amos Benari | complete: function(){ $(element).indicator_hide();},
|
|
017e1049 | Ohad Levy | success: function(request) {
|
|
$('#subnet_select').html(request);
|
|||
8bfaec2a | Joseph Mitchell Magen | reload_host_params();
|
|
017e1049 | Ohad Levy | }
|
|
})
|
|||
}
|
|||
function architecture_selected(element){
|
|||
611f5bff | Amos Benari | var attrs = attribute_hash(['architecture_id', 'organization_id', 'location_id']);
|
|
dd42df0a | Ohad Levy | var url = $(element).attr('data-url');
|
|
89b9ecb0 | Amos Benari | $(element).indicator_show();
|
|
017e1049 | Ohad Levy | $.ajax({
|
|
611f5bff | Amos Benari | data: attrs,
|
|
017e1049 | Ohad Levy | type:'post',
|
|
dd42df0a | Ohad Levy | url: url,
|
|
89b9ecb0 | Amos Benari | complete: function(){ $(element).indicator_hide();},
|
|
017e1049 | Ohad Levy | success: function(request) {
|
|
$('#os_select').html(request);
|
|||
}
|
|||
})
|
|||
}
|
|||
function os_selected(element){
|
|||
1f1367d6 | Amos Benari | var attrs = attribute_hash(['operatingsystem_id', 'organization_id', 'location_id']);
|
|
dd42df0a | Ohad Levy | var url = $(element).attr('data-url');
|
|
89b9ecb0 | Amos Benari | $(element).indicator_show();
|
|
017e1049 | Ohad Levy | $.ajax({
|
|
611f5bff | Amos Benari | data: attrs,
|
|
017e1049 | Ohad Levy | type:'post',
|
|
dd42df0a | Ohad Levy | url: url,
|
|
89b9ecb0 | Amos Benari | complete: function(){ $(element).indicator_hide();},
|
|
017e1049 | Ohad Levy | success: function(request) {
|
|
$('#media_select').html(request);
|
|||
8bfaec2a | Joseph Mitchell Magen | reload_host_params();
|
|
017e1049 | Ohad Levy | }
|
|
dd42df0a | Ohad Levy | });
|
|
update_provisioning_image();
|
|||
}
|
|||
function update_provisioning_image(){
|
|||
var compute_id = $('[id$="_compute_resource_id"]').val();
|
|||
var arch_id = $('[id$="_architecture_id"]').val();
|
|||
var os_id = $('[id$="_operatingsystem_id"]').val();
|
|||
if((compute_id == undefined) || (compute_id == "") || (arch_id == "") || (os_id == "")) return;
|
|||
var term = 'operatingsystem=' + os_id + ' architecture=' + arch_id;
|
|||
511e8f78 | Ohad Levy | var image_options = $('#image_selection select').empty();
|
|
dd42df0a | Ohad Levy | $.ajax({
|
|
data:'search=' + encodeURIComponent(term),
|
|||
type:'get',
|
|||
5f75d98a | Ivan Necas | url: foreman_url('/compute_resources/'+compute_id+'/images'),
|
|
dd42df0a | Ohad Levy | dataType: 'json',
|
|
success: function(result) {
|
|||
$.each(result, function() {
|
|||
image_options.append($("<option />").val(this.image.uuid).text(this.image.name));
|
|||
});
|
|||
99527500 | Jimmi Dyson | if (image_options.find('option').length > 0) {
|
|
3d03e334 | Dominic Cleal | if ($('#host_provision_method_image')[0].checked) {
|
|
if ($('#provider').val() == 'Libvirt') {
|
|||
libvirt_image_selected(image_options);
|
|||
} else if ($('#provider').val() == 'Ovirt') {
|
|||
var template_select = $('#host_compute_attributes_template');
|
|||
if (template_select.length > 0) {
|
|||
template_select.val(image_options.val());
|
|||
ovirt_templateSelected(image_options);
|
|||
}
|
|||
99527500 | Jimmi Dyson | }
|
|
}
|
|||
}
|
|||
dd42df0a | Ohad Levy | }
|
|
})
|
|||
017e1049 | Ohad Levy | }
|
|
da6fa387 | Ohad Levy | ||
function medium_selected(element){
|
|||
dd42df0a | Ohad Levy | var url = $(element).attr('data-url');
|
|
da6fa387 | Ohad Levy | var type = $(element).attr('data-type');
|
|
var obj = (type == "hosts" ? "host" : "hostgroup");
|
|||
var attrs = {};
|
|||
attrs[obj] = attribute_hash(['medium_id', 'operatingsystem_id', 'architecture_id']);
|
|||
dc0f0f5f | Ohad Levy | attrs[obj]["use_image"] = $('*[id*=use_image]').attr('checked') == "checked";
|
|
da6fa387 | Ohad Levy | $.ajax({
|
|
data: attrs,
|
|||
type:'post',
|
|||
dd42df0a | Ohad Levy | url: url,
|
|
da6fa387 | Ohad Levy | success: function(request) {
|
|
$('#image_details').html(request);
|
|||
}
|
|||
})
|
|||
}
|
|||
function use_image_selected(element){
|
|||
dd42df0a | Ohad Levy | var url = $(element).attr('data-url');
|
|
da6fa387 | Ohad Levy | var type = $(element).attr('data-type');
|
|
var obj = (type == "hosts" ? "host" : "hostgroup");
|
|||
var attrs = {};
|
|||
attrs[obj] = attribute_hash(['medium_id', 'operatingsystem_id', 'architecture_id', 'model_id']);
|
|||
attrs[obj]['use_image'] = ($(element).attr('checked') == "checked");
|
|||
$.ajax({
|
|||
data: attrs,
|
|||
type: 'post',
|
|||
dd42df0a | Ohad Levy | url: url,
|
|
da6fa387 | Ohad Levy | success: function(response) {
|
|
var field = $('*[id*=image_file]');
|
|||
if (attrs[obj]["use_image"]) {
|
|||
if (field.val() == "") field.val(response["image_file"]);
|
|||
} else
|
|||
field.val("");
|
|||
field.attr("disabled", !attrs[obj]["use_image"]);
|
|||
}
|
|||
});
|
|||
}
|
|||
995b1748 | Amos Benari | function override_param(item){
|
|
298756ca | Amos Benari | var param = $(item).closest('tr');
|
|
var n = param.find('[id^=name_]').text();
|
|||
995b1748 | Amos Benari | var v = param.find('[id^=value_]').val();
|
|
298756ca | Amos Benari | $('#parameters').find('.btn-success').click();
|
|
2de7832d | Ohad Levy | var new_param = param.closest('.tab-pane').find('[id*=host_host_parameters]:visible').last().parent().parent();
|
|
995b1748 | Amos Benari | new_param.find('[id$=_name]').val(n);
|
|
new_param.find('[id$=_value]').val(v);
|
|||
mark_params_override();
|
|||
}
|
|||
298756ca | Amos Benari | function override_class_param(item){
|
|
var param = $(item).closest('tr[id^="puppetclass_"][id*="_params\\["][id$="\\]"]');
|
|||
var id = param.attr('id').replace(/puppetclass_\d+_params\[(\d+)\]/, '$1')
|
|||
var c = param.find('[data-property=class]').text();
|
|||
var n = param.find('[data-property=name]').text();
|
|||
var v = param.find('[data-property=value]').val();
|
|||
var t = param.find('[data-property=type]').text();
|
|||
$('#puppetclasses_parameters').find('.btn-success').click();
|
|||
d31eea8c | Amos Benari | var new_param = param.closest('.tab-pane').find('[id*=_lookup_values]:visible').last().parents('.form-group');
|
|
298756ca | Amos Benari | new_param.find('[data-property=lookup_key_id]').val(id);
|
|
new_param.find('[data-property=class]').val(c);
|
|||
new_param.find('[data-property=name]').val(n);
|
|||
new_param.find('[data-property=value]').val(v);
|
|||
new_param.find('[data-property=type]').val(t);
|
|||
mark_params_override();
|
|||
}
|
|||
8bfaec2a | Joseph Mitchell Magen | function reload_host_params(){
|
|
var host_id = $("form").data('id');
|
|||
feacea35 | Amos Benari | var url = $('#params-tab').data('url');
|
|
1f1367d6 | Amos Benari | var data = $("[data-submit='progress_bar']").serialize().replace('method=put', 'method=post');
|
|
8bfaec2a | Joseph Mitchell Magen | data = data + '&host_id=' + host_id;
|
|
298756ca | Amos Benari | load_with_placeholder('inherited_parameters', url, data)
|
|
8bfaec2a | Joseph Mitchell Magen | }
|
|
298756ca | Amos Benari | ||
8bfaec2a | Joseph Mitchell Magen | function reload_puppetclass_params(){
|
|
var host_id = $("form").data('id');
|
|||
feacea35 | Amos Benari | var url2 = $('#params-tab').data('url2');
|
|
8bfaec2a | Joseph Mitchell Magen | var data = $("[data-submit='progress_bar']").serialize().replace('method=put', 'method=post');
|
|
data = data + '&host_id=' + host_id
|
|||
298756ca | Amos Benari | load_with_placeholder('inherited_puppetclasses_parameters', url2, data)
|
|
}
|
|||
function load_with_placeholder(target, url, data){
|
|||
1f1367d6 | Amos Benari | if(url==undefined) return;
|
|
298756ca | Amos Benari | var placeholder = $('<tr id="' + target + '_loading" >'+
|
|
ad01d4d2 | Walden Raines | '<td colspan="4">'+ spinner_placeholder(__('Loading parameters...')) + '</td></tr>');
|
|
298756ca | Amos Benari | $('#' + target + ' tbody').replaceWith(placeholder);
|
|
$.ajax({
|
|||
5237d122 | Amos Benari | type:'post',
|
|
298756ca | Amos Benari | url: url,
|
|
data: data,
|
|||
success:
|
|||
function(result, textstatus, xhr) {
|
|||
placeholder.closest('#' + target ).replaceWith($(result));
|
|||
mark_params_override()
|
|||
}
|
|||
});
|
|||
995b1748 | Amos Benari | }
|
|
dd42df0a | Ohad Levy | function onHostEditLoad(){
|
|
30ae12bf | Ohad Levy | $("#host-conflicts-modal").modal({show: "true", backdrop: "static"});
|
|
dd42df0a | Ohad Levy | $('#host-conflicts-modal').click(function(){
|
|
$('#host-conflicts-modal').modal('hide');
|
|||
});
|
|||
$('#image_selection').appendTo($('#image_provisioning'));
|
|||
995b1748 | Amos Benari | $('#params-tab').on('shown', function(){mark_params_override()});
|
|
f9a77319 | Amos Benari | if ($('#supports_update') && !$('#supports_update').data('supports-update')) disable_vm_form_fields();
|
|
dd42df0a | Ohad Levy | }
|
|
8838eb42 | Ohad Levy | ||
92326dd2 | Amos Benari | $(document).on('submit',"[data-submit='progress_bar']", function() {
|
|
submit_host();
|
|||
return false;
|
|||
});
|
|||
3d03e334 | Dominic Cleal | function build_provision_method_selected() {
|
|
511e8f78 | Ohad Levy | $('#network_provisioning').show();
|
|
$('#image_provisioning').hide();
|
|||
99527500 | Jimmi Dyson | $('#image_selection select').attr('disabled', true);
|
|
if ($('#provider').val() == 'Ovirt')
|
|||
$('#host_compute_attributes_template').attr('disabled', false);
|
|||
3d03e334 | Dominic Cleal | }
|
|
$(document).on('change', '#host_provision_method_build', build_provision_method_selected);
|
|||
511e8f78 | Ohad Levy | ||
3d03e334 | Dominic Cleal | function image_provision_method_selected() {
|
|
511e8f78 | Ohad Levy | $('#network_provisioning').hide();
|
|
$('#image_provisioning').show();
|
|||
3d03e334 | Dominic Cleal | $('#network_selection select').attr('disabled', true);
|
|
99527500 | Jimmi Dyson | var image_options = $('#image_selection select');
|
|
image_options.attr('disabled', false);
|
|||
3d03e334 | Dominic Cleal | if ($('#provider').val() == 'Libvirt') {
|
|
libvirt_image_selected(image_options);
|
|||
} else if ($('#provider').val() == 'Ovirt') {
|
|||
99527500 | Jimmi Dyson | var template_options = $('#host_compute_attributes_template');
|
|
if (template_options.length > 0) {
|
|||
template_options.attr('disabled', true);
|
|||
template_options.val(image_options.val());
|
|||
ovirt_templateSelected(image_options);
|
|||
}
|
|||
}
|
|||
3d03e334 | Dominic Cleal | }
|
|
$(document).on('change', '#host_provision_method_image', image_provision_method_selected);
|
|||
511e8f78 | Ohad Levy | ||
8838eb42 | Ohad Levy | $(document).on('change', '.interface_domain', function () {
|
|
interface_domain_selected(this);
|
|||
});
|
|||
05ed57c1 | Sean Handley | $(document).on('click', '#suggest_new_ip', function (e) {
|
|
$('#host_ip').val('')
|
|||
interface_subnet_selected($('#host_subnet_id'));
|
|||
e.preventDefault();
|
|||
});
|
|||
8838eb42 | Ohad Levy | $(document).on('change', '.interface_subnet', function () {
|
|
interface_subnet_selected(this);
|
|||
});
|
|||
$(document).on('change', '.interface_type', function () {
|
|||
interface_type_selected(this);
|
|||
});
|
|||
function interface_domain_selected(element) {
|
|||
var domain_id = element.value;
|
|||
var subnet_options = $(element).parentsUntil('.fields').parent().find('[id$=_subnet_id]').empty();
|
|||
subnet_options.attr('disabled', true);
|
|||
if (domain_id == '') {
|
|||
ad01d4d2 | Walden Raines | subnet_options.append($("<option />").val(null).text(__('No subnets')));
|
|
8838eb42 | Ohad Levy | return false;
|
|
}
|
|||
89b9ecb0 | Amos Benari | $(element).indicator_show();
|
|
8838eb42 | Ohad Levy | ||
var url = $(element).attr('data-url');
|
|||
var org = $('#host_organization_id :selected').val();
|
|||
var loc = $('#host_location_id :selected').val();
|
|||
$.ajax({
|
|||
data:{domain_id: domain_id, organization_id:org, location_id: loc},
|
|||
type:'post',
|
|||
url:url,
|
|||
dataType:'json',
|
|||
success:function (result) {
|
|||
if (result.length > 1)
|
|||
ad01d4d2 | Walden Raines | subnet_options.append($("<option />").val(null).text(__('Please select')));
|
|
8838eb42 | Ohad Levy | ||
$.each(result, function () {
|
|||
subnet_options.append($("<option />").val(this.subnet.id).text(this.subnet.name + ' (' + this.subnet.to_label + ')'));
|
|||
});
|
|||
if (subnet_options.find('option').length > 0) {
|
|||
subnet_options.attr('disabled', false);
|
|||
subnet_options.change();
|
|||
}
|
|||
else {
|
|||
ad01d4d2 | Walden Raines | subnet_options.append($("<option />").text(__('No subnets')));
|
|
8838eb42 | Ohad Levy | subnet_options.attr('disabled', true);
|
|
}
|
|||
89b9ecb0 | Amos Benari | $(element).indicator_hide();
|
|
8838eb42 | Ohad Levy | }
|
|
});
|
|||
}
|
|||
function interface_subnet_selected(element) {
|
|||
var subnet_id = $(element).val();
|
|||
if (subnet_id == '') return;
|
|||
var interface_ip = $(element).parentsUntil('.fields').parent().find('input[id$=_ip]')
|
|||
interface_ip.attr('disabled', true);
|
|||
89b9ecb0 | Amos Benari | $(element).indicator_show();
|
|
8838eb42 | Ohad Levy | ||
// We do not query the proxy if the ip field is filled in and contains an
|
|||
// IP that is in the selected subnet
|
|||
var drop_text = $(element).children(":selected").text();
|
|||
// extracts network / cidr / ip
|
|||
if (drop_text.length != 0 && drop_text.search(/^.+ \([0-9\.\/]+\)/) != -1) {
|
|||
3101210d | Mikael Fridh | var details = drop_text.replace(/^.+\(/, "").replace(")","").split("/");
|
|
8838eb42 | Ohad Levy | var network = details[0];
|
|
var cidr = details[1];
|
|||
if (subnet_contains(network, cidr, interface_ip.val())) {
|
|||
interface_ip.attr('disabled', false);
|
|||
89b9ecb0 | Amos Benari | $(element).indicator_hide();
|
|
8838eb42 | Ohad Levy | return;
|
|
}
|
|||
}
|
|||
var interface_mac = $(element).parentsUntil('.fields').parent().find('input[id$=_mac]')
|
|||
var url = $(element).attr('data-url');
|
|||
var org = $('#host_organization_id :selected').val();
|
|||
var loc = $('#host_location_id :selected').val();
|
|||
var data = {subnet_id: subnet_id, host_mac: interface_mac.val(), organization_id:org, location_id:loc }
|
|||
$.ajax({
|
|||
data: data,
|
|||
type:'post',
|
|||
url: url,
|
|||
dataType:'json',
|
|||
success:function (result) {
|
|||
interface_ip.val(result['ip']);
|
|||
},
|
|||
complete:function () {
|
|||
89b9ecb0 | Amos Benari | $(element).indicator_hide();
|
|
8838eb42 | Ohad Levy | interface_ip.attr('disabled', false);
|
|
}
|
|||
});
|
|||
}
|
|||
function interface_type_selected(element) {
|
|||
var type = $(element).find('option:selected').text();
|
|||
var bmc_fields = $(element).parentsUntil('.fields').parent().find('#bmc_fields')
|
|||
if (type == 'BMC') {
|
|||
bmc_fields.find("input:disabled").prop('disabled',false);
|
|||
bmc_fields.removeClass("hide");
|
|||
} else {
|
|||
bmc_fields.find("input").prop('disabled',true);
|
|||
bmc_fields.addClass("hide");
|
|||
}
|
|||
}
|
|||
f9a77319 | Amos Benari | ||
function disable_vm_form_fields() {
|
|||
$("#update_not_supported").show();
|
|||
$("[id^=host_compute_attributes]").each(function () {
|
|||
$(this).attr("disabled", "disabled");
|
|||
});
|
|||
$("a.disable-unsupported").remove();
|
|||
ad01d4d2 | Walden Raines | }
|