Revision 95d70642
Added by Shimon Shtein over 8 years ago
app/assets/javascripts/host_edit.js | ||
---|---|---|
$(document).on('AddedClass', function(event, link){load_puppet_class_parameters(link)});
|
||
|
||
function update_nics(success_callback) {
|
||
var data = $('form').serialize().replace('method=put', 'method=post');
|
||
var data = serializeForm().replace('method=put', 'method=post');
|
||
$('#network').html(spinner_placeholder(__('Loading interfaces information ...')));
|
||
$('#network_tab a').removeClass('tab-error');
|
||
|
||
... | ... | |
$("#compute_resource_tab").show();
|
||
$("#compute_profile").show();
|
||
$('#vm_details').empty();
|
||
var data = $('form').serialize().replace('method=put', 'method=post');
|
||
var data = serializeForm().replace('method=put', 'method=post');
|
||
$('#compute_resource').html(spinner_placeholder(__('Loading virtual machine information ...')));
|
||
$('#compute_resource_tab a').removeClass('tab-error');
|
||
$(item).indicator_show();
|
||
... | ... | |
$.ajax({
|
||
type:'POST',
|
||
url: url,
|
||
data: $('form').serialize(),
|
||
data: serializeForm(),
|
||
success: function(response){
|
||
$('#' + resource + '-progress').hide();
|
||
$('#content').replaceWith($("#content", response));
|
||
... | ... | |
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');
|
||
var data = $("form").serialize().replace('method=put', 'method=post');
|
||
var data = serializeForm().replace('method=put', 'method=post');
|
||
if (url.match('hostgroups')) {
|
||
data = data + '&hostgroup_id=' + host_id
|
||
} else {
|
||
... | ... | |
function update_form(element, options) {
|
||
options = options || {};
|
||
var url = $(element).data('url');
|
||
var data = $('form').serialize().replace('method=put', 'method=post');
|
||
var data = serializeForm().replace('method=put', 'method=post');
|
||
if (options.data) data = data+options.data;
|
||
$(element).indicator_show();
|
||
$.ajax({
|
||
... | ... | |
})
|
||
}
|
||
|
||
//Serializes only those input elements from form that are set explicitly
|
||
function serializeForm() {
|
||
return $($('form')[0].elements).filter(isExplicit).serialize()
|
||
}
|
||
|
||
//This function decides for a given input element is it set explicitly by the user.
|
||
function isExplicit(index, element) {
|
||
if (element.nextSibling == undefined) return true;
|
||
if (element.nextSibling.children == undefined) return true;
|
||
if (element.nextSibling.children[0] == undefined) return true;
|
||
if (element.nextSibling.children[0].dataset == undefined) return true;
|
||
return element.nextSibling.children[0].dataset.explicit == 'true';
|
||
}
|
||
|
||
function subnet_contains(number, cidr, ip){
|
||
var int_ip = _to_int(ip);
|
||
var int_number = _to_int(number);
|
app/models/host/managed.rb | ||
---|---|---|
validates :medium_id, :presence => true, :if => Proc.new { |host| host.validate_media? }
|
||
validate :provision_method_in_capabilities
|
||
validate :short_name_periods
|
||
before_validation :set_compute_attributes, :on => :create
|
||
before_validation :set_compute_attributes, :on => :create, :if => Proc.new { compute_attributes.empty? }
|
||
validate :check_if_provision_method_changed, :on => :update, :if => Proc.new { |host| host.managed }
|
||
else
|
||
def fqdn
|
||
... | ... | |
def set_hostgroup_defaults
|
||
return unless hostgroup
|
||
assign_hostgroup_attributes(%w{domain_id compute_profile_id})
|
||
|
||
set_compute_attributes if compute_profile_id_changed?
|
||
|
||
if SETTINGS[:unattended] and (new_record? or managed?)
|
||
assign_hostgroup_attributes(%w{operatingsystem_id architecture_id})
|
||
assign_hostgroup_attributes(%w{medium_id ptable_id subnet_id}) if pxe_build?
|
||
... | ... | |
end
|
||
|
||
def set_compute_attributes
|
||
return unless compute_attributes.empty?
|
||
return unless compute_profile_id && compute_resource_id
|
||
self.compute_attributes = compute_resource.compute_profile_attributes_for(compute_profile_id)
|
||
end
|
app/views/hosts/_form.html.erb | ||
---|---|---|
be different from the defaults, or the defaults could have changed after the vm was created. %>
|
||
<div id="compute_profile" <%= display?(!@host.compute_resource_id) %> >
|
||
<%= select_f f, :compute_profile_id, ComputeProfile.visibles, :id, :name,
|
||
{ :disable_button => _(HostsAndHostgroupsHelper::INHERIT_TEXT),
|
||
{ :include_blank => true,
|
||
:disable_button => _(HostsAndHostgroupsHelper::INHERIT_TEXT),
|
||
:disable_button_enabled => inherited_by_default?(:compute_profile_id, @host),
|
||
:user_set => params[:host] && params[:host][:compute_profile_id]
|
||
},
|
test/unit/host_test.rb | ||
---|---|---|
end
|
||
end
|
||
|
||
context 'hostgroup defaults' do
|
||
setup do
|
||
@group1 = FactoryGirl.create(:hostgroup, :compute_profile => compute_profiles(:one))
|
||
@group2 = FactoryGirl.create(:hostgroup, :compute_profile => compute_profiles(:two))
|
||
end
|
||
|
||
test 'sets proper compute attributes on hostgroup change' do
|
||
host = FactoryGirl.create(:host, :managed, :compute_resource => compute_resources(:one), :hostgroup => @group1)
|
||
assert_not_equal 4, host.compute_attributes['cpus']
|
||
|
||
host.attributes = host.apply_inherited_attributes('hostgroup_id' => @group2.id)
|
||
host.set_hostgroup_defaults
|
||
assert_equal 4, host.compute_attributes['cpus']
|
||
end
|
||
end
|
||
|
||
private
|
||
|
||
def parse_json_fixture(relative_path)
|
Also available in: Unified diff
Fixes #12461 - Compute profile is properly selected.