Project

General

Profile

« Previous | Next » 

Revision 43c4bd72

Added by Marek Hulán over 9 years ago

Fixes #7456 - Extract primary interface from host

Contributions from:

All host must have at least one primary interface and one provision (can
be the same interface). Primary interface gives host a name so even
unamanaged host have primary interface (we skip validations of other
attributes for unamanged hosts though).

Host still have name attribute which is a cache of primary interface name.
Therefore we can use the host name in SQL queries, as a friendly_id etc.

- realm moved to the primary tab
- fqdn in nics table
- flags in nics table
- checkboxes for provision and primary flags
- modal resize fix
- original fields for primary NIC removed
- skipping validation for new resources
- warnings before switching flags and table update
- host name and primary interface name connected
- host domain name in the page title
- nics on host show page
- clearing modal window on cancel
- fixed domain validation in NIC::Base
- ip suggestion for all interfaces
- flags switchable from the overview table
- use icons instead of text for primary/provision on NICs overview tab
- attempt to fix sending NIC template
- fix fqdn algorithm
- ip addres in the overview table
- fix for class name collision
- better behavior of host name <-> primary name sync
- fix for subnet combobox values
- fix for modal poping up on form submission
- network partial for CRs moved from VM tab to modal
- fix ip suggestion race for ipam=db

View differences:

app/assets/javascripts/host_edit.js
$(document).on('AddedClass', function(event, link){load_puppet_class_parameters(link)});
$(document).on('click', '#params-tab', function() { resizeTextareas($('#params')); });
function update_nics(success_callback) {
var data = $('form').serialize().replace('method=put', 'method=post');
$('#network').html(spinner_placeholder(__('Loading interfaces information ...')));
$('#network_tab a').removeClass('tab-error');
var url = '/hosts/interfaces';
$.ajax({
type:'post',
url: url,
data: data,
complete: function(){},
error: function(jqXHR, status, error){
$('#network').html(Jed.sprintf(__("Error loading interfaces information: %s"), error));
$('#network_tab a').addClass('tab-error');
},
success: function(result){
$('#network').html(result);
if ($('#network').find('.alert-danger').length > 0)
$('#network_tab a').addClass('tab-error');
success_callback();
}
})
}
function computeResourceSelected(item){
var compute = $(item).val();
if (compute == '' && /compute_resource/.test($(item).attr('name'))) {
//Bare metal compute resource
$('#mac_address').show();
$("#model_name").show();
$('#compute_resource').empty();
$('#vm_details').empty();
......
update_capabilities('build');
} else {
//Real compute resource or any compute profile
$('#mac_address').hide();
$("#model_name").hide();
$("#compute_resource_tab").show();
$("#compute_profile").show();
......
}
})
}
update_nics(function() {
interface_subnet_selected(primary_nic_form().find('.interface_subnet'));
});
}
function update_capabilities(capabilities){
......
success: function(response) {
$('form').replaceWith(response);
multiSelectOnLoad();
$("[id$='subnet_id']").first().change();
// to handle case if def process_taxonomy changed compute_resource_id to nil
if( !$('#host_compute_resource_id').val() ) {
$('#host_compute_resource_id').change();
}
update_capabilities($('#host_compute_resource_id').val() ? $('#capabilities').val() : 'build');
$(document.body).trigger('ContentLoad');
}
})
}
function subnet_selected(element){
var ipam_text = $("#host_ip").parentsUntil('.clearfix').find(".help-block,.help-inline");
if (selectedSubnetHasIPAM()) {
ipam_text.removeClass('hide')
} else {
ipam_text.addClass('hide');
return false
}
var subnet_id = $(element).val();
if (subnet_id == '' || $('#host_ip').length == 0) return;
// We do not query the proxy if the host_ip field is filled in and contains an
// IP that is in the selected subnet
var drop_text = $(element).children(":selected").text();
if (drop_text.length !=0 && drop_text.search(/^.+ \([0-9\.\/]+\)/) != -1) {
var details = drop_text.replace(/^.+\(/, "").replace(")","").split("/");
if (subnet_contains(details[0], details[1], $('#host_ip').val()))
return;
}
var attrs = attribute_hash(["subnet_id", "host_mac", 'organization_id', 'location_id']);
$(element).indicator_show();
var url = $(element).data('url');
$.ajax({
data: attrs,
type:'post',
url: url,
complete: function(){ $(element).indicator_hide();},
success: function(data){
$('#host_ip').val(data.ip);
$(document.body).trigger('ContentLoad');
}
})
}
......
return integer;
}
function domain_selected(element){
var attrs = attribute_hash(['domain_id', 'organization_id', 'location_id']);
var url = $(element).data('url');
$(element).indicator_show();
$.ajax({
data: attrs,
type:'post',
url: url,
complete: function(){ $(element).indicator_hide();},
success: function(request) {
$('#subnet_select').html(request);
reload_host_params();
}
})
}
function architecture_selected(element){
var attrs = attribute_hash(['architecture_id', 'organization_id', 'location_id']);
var url = $(element).attr('data-url');
......
interface_domain_selected(this);
});
$(document).on('click', '#suggest_new_ip', function (e) {
$('#host_ip').val('')
interface_subnet_selected($('#host_subnet_id'));
$(document).on('click', '.suggest_new_ip', function (e) {
$(this).closest('fieldset').find('.interface_ip').val('');
interface_subnet_selected($(this).closest('fieldset').find('.interface_subnet'));
e.preventDefault();
});
......
subnet_options.append($("<option />").val(null).text(__('Please select')));
$.each(result, function () {
subnet_options.append($("<option />").val(this.subnet.id).text(this.subnet.name + ' (' + this.subnet.to_label + ')'));
subnet_options.append($("<option />").val(this.subnet.id).text(this.subnet.to_label));
});
if (subnet_options.find('option').length > 0) {
subnet_options.attr('disabled', false);
......
return;
}
}
var interface_mac = $(element).parentsUntil('.fields').parent().find('input[id$=_mac]')
var interface_mac = $(element).closest('fieldset').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 }
var taken_ips = $(active_interface_forms()).find('.interface_ip').map(function() {
return $(this).val();
}).get();
taken_ips.push(interface_ip.val());
var data = {
subnet_id: subnet_id,
host_mac: interface_mac.val(),
organization_id: org,
location_id: loc,
taken_ips: taken_ips
}
$.ajax({
data: data,
type:'post',
......
dataType:'json',
success:function (result) {
interface_ip.val(result['ip']);
update_interface_table();
},
complete:function () {
$(element).indicator_hide();
......
function interface_type_selected(element) {
var fieldset = $(element).closest("fieldset");
var data = fieldset.serializeArray();
data.push({
name: 'host[compute_resource_id]',
value: $('#host_compute_resource_id').val()
})
$.ajax({
data: fieldset.serialize(),
data: data,
type: 'GET',
url: fieldset.attr('data-url'),
dataType: 'script'

Also available in: Unified diff