foreman/webpack/assets/javascripts/compute_resource/ovirt.js @ 04ae1269
a5a6b5df | Dan Seethaler | /* eslint-disable func-names */
|
|
9234d6c5 | Ohad Levy | import $ from 'jquery';
|
|
import { showSpinner } from '../foreman_tools';
|
|||
import { testConnection } from '../foreman_compute_resource';
|
|||
export function templateSelected(item) {
|
|||
const template = $(item).val();
|
|||
if (!item.disabled) {
|
|||
const url = $(item).attr('data-url');
|
|||
showSpinner();
|
|||
$.ajax({
|
|||
type: 'post',
|
|||
url,
|
|||
data: `template_id=${template}`,
|
|||
success(result) {
|
|||
9034d78e | Baptiste | // As Instance Type values will take precence over templates values,
|
|
// we don't update memory/cores values if instance type is already selected
|
|||
if (!$('#host_compute_attributes_instance_type').val()) {
|
|||
d6df46d1 | Shira Maximov | $('[id$=_memory]').val(result.memory).trigger('change');
|
|
9034d78e | Baptiste | $('[id$=_cores]').val(result.cores);
|
|
04ae1269 | Shira Maximov | $('[id$=_sockets]').val(result.sockets);
|
|
9034d78e | Baptiste | }
|
|
9234d6c5 | Ohad Levy | $('#network_interfaces').children('.fields').remove();
|
|
$.each(result.interfaces, function () {
|
|||
addNetworkInterface(this);
|
|||
});
|
|||
$('#storage_volumes .children_fields >.fields').remove();
|
|||
$.each(result.volumes, function () {
|
|||
9e81b2c4 | Baptiste | // Change variable name because 'interface' is a reserved keyword.
|
|
ca1f814a | Ohad Levy | this.disk_interface = this['interface'];
|
|
9234d6c5 | Ohad Levy | addVolume(this);
|
|
});
|
|||
const templateSelector = $('#host_compute_attributes_template');
|
|||
if (templateSelector.is(':disabled')) {
|
|||
templateSelector.val(result.id).trigger('change');
|
|||
}
|
|||
},
|
|||
complete() {
|
|||
// eslint-disable-next-line no-undef
|
|||
reloadOnAjaxComplete(item);
|
|||
a5a6b5df | Dan Seethaler | },
|
|
9234d6c5 | Ohad Levy | });
|
|
}
|
|||
}
|
|||
9034d78e | Baptiste | export function instanceTypeSelected(item) {
|
|
const instanceType = $(item).val();
|
|||
if (!item.disabled) {
|
|||
const url = $(item).attr('data-url');
|
|||
showSpinner();
|
|||
$.ajax({
|
|||
type: 'post',
|
|||
url,
|
|||
data: `instance_type_id=${instanceType}`,
|
|||
success(result) {
|
|||
d6df46d1 | Shira Maximov | $('[id$=_memory]').val(result.memory).trigger('change');
|
|
9034d78e | Baptiste | $('[id$=_cores]').val(result.cores);
|
|
04ae1269 | Shira Maximov | $('[id$=_sockets]').val(result.sockets);
|
|
9034d78e | Baptiste | const instanceTypeSelector = $('#host_compute_attributes_instance_type');
|
|
if (instanceTypeSelector.is(':disabled')) {
|
|||
instanceTypeSelector.val(result.id).trigger('change');
|
|||
}
|
|||
},
|
|||
complete() {
|
|||
// eslint-disable-next-line no-undef
|
|||
reloadOnAjaxComplete(item);
|
|||
},
|
|||
});
|
|||
}
|
|||
}
|
|||
9234d6c5 | Ohad Levy | // fill in the template interfaces.
|
|
function addNetworkInterface({ name, network }) {
|
|||
const nestedFields = $('#network_interfaces .add_nested_fields');
|
|||
// no network interfaces update when the network editing is not allowed by the compute resource
|
|||
9c9b7eb1 | orrabin | if (nestedFields.length > 0) {
|
|
9234d6c5 | Ohad Levy | // eslint-disable-next-line no-undef
|
|
const newId = add_child_node(nestedFields);
|
|||
$(`[id$=${newId}_name]`).val(name);
|
|||
$(`[id$=${newId}_network]`).val(network);
|
|||
}
|
|||
}
|
|||
// fill in the template volumes.
|
|||
// eslint-disable-next-line camelcase
|
|||
a5a6b5df | Dan Seethaler | function addVolume({
|
|
9e81b2c4 | Baptiste | size_gb, storage_domain, bootable, id, disk_interface, wipe_after_delete,
|
|
a5a6b5df | Dan Seethaler | }) {
|
|
9234d6c5 | Ohad Levy | // eslint-disable-next-line no-undef
|
|
const newId = add_child_node($('#storage_volumes .add_nested_fields'));
|
|||
disableElement($(`[id$=${newId}_size_gb]`).val(size_gb));
|
|||
disableElement($(`[id$=${newId}_storage_domain]`).val(storage_domain));
|
|||
9e81b2c4 | Baptiste | disableElement($(`[id$=${newId}_wipe_after_delete]`).val(wipe_after_delete));
|
|
disableElement($(`[id$=${newId}_interface]`).val(disk_interface));
|
|||
9234d6c5 | Ohad Levy | disableElement($(`[id$=${newId}_bootable_true]`).attr('checked', bootable));
|
|
if (id) {
|
|||
$(`[id$=${newId}_id]`).val(id);
|
|||
}
|
|||
$(`[id$=${newId}_storage_domain]`).next().hide();
|
|||
}
|
|||
function disableElement(element) {
|
|||
element.clone().attr('type', 'hidden').appendTo(element);
|
|||
element.attr('disabled', 'disabled');
|
|||
}
|
|||
export function bootableRadio(item) {
|
|||
a5a6b5df | Dan Seethaler | const disabled = $('[id$=_bootable_true]:disabled:checked:visible');
|
|
9234d6c5 | Ohad Levy | ||
$('[id$=_bootable_true]').prop('checked', false);
|
|||
if (disabled.length > 0) {
|
|||
disabled.prop('checked', true);
|
|||
} else {
|
|||
$(item).prop('checked', true);
|
|||
}
|
|||
}
|
|||
export function clusterSelected(item) {
|
|||
const cluster = $(item).val();
|
|||
const url = $(item).attr('data-url');
|
|||
showSpinner();
|
|||
$.ajax({
|
|||
type: 'post',
|
|||
url,
|
|||
data: `cluster_id=${cluster}`,
|
|||
success(result) {
|
|||
a5a6b5df | Dan Seethaler | const networkOptions = $('select[id$=_network]').empty();
|
|
9234d6c5 | Ohad Levy | ||
$.each(result, function () {
|
|||
networkOptions.append($('<option />').val(this.id).text(this.name));
|
|||
});
|
|||
},
|
|||
complete() {
|
|||
// eslint-disable-next-line no-undef
|
|||
reloadOnAjaxComplete(item);
|
|||
a5a6b5df | Dan Seethaler | },
|
|
9234d6c5 | Ohad Levy | });
|
|
}
|
|||
// used by test connection
|
|||
export function datacenterSelected(item) {
|
|||
// eslint-disable-next-line no-undef
|
|||
testConnection($('#test_connection_button'));
|
|||
}
|