1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-07 17:17:41 +03:00

F OpenNebula/one#6303: Add virtio-blk input in sunstone/fireedge (#2757)

Co-authored-by: Tino Vázquez <cvazquez@opennebula.io>
This commit is contained in:
Jorge Miguel Lobo Escalona 2023-09-26 13:36:36 +02:00 committed by GitHub
parent e4445ee823
commit a3697d3d30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 89 additions and 25 deletions

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { string, number } from 'yup'
import { number, string } from 'yup'
import { OPTION_SORTERS, Field, arrayToOptions } from 'client/utils'
import { T, INPUT_TYPES, HYPERVISORS } from 'client/constants'
import { HYPERVISORS, INPUT_TYPES, T } from 'client/constants'
import { Field, OPTION_SORTERS, arrayToOptions } from 'client/utils'
const { vcenter, lxc, firecracker } = HYPERVISORS
@ -29,6 +29,14 @@ const commonValidation = string()
.notRequired()
.default(() => undefined)
const optionsInputsVirtio = (vcpu) => {
const limit = vcpu ? 2 * vcpu : 4
const options = Array.from({ length: limit }, (_, i) => i + 1)
options.unshift('auto')
return arrayToOptions(options, { sorter: OPTION_SORTERS.unsort })
}
/** @type {Field} ACPI field */
export const ACPI = {
name: 'FEATURES.ACPI',
@ -98,14 +106,24 @@ export const GUEST_AGENT = {
/** @type {Field} Virtio-SCSI queues field */
export const VIRTIO_SCSI_QUEUES = {
name: 'FEATURES.VIRTIO_SCSI_QUEUES',
dependOf: '$general.VCPU',
label: T.VirtioQueues,
tooltip: T.VirtioQueuesConcept,
notOnHypervisors: [vcenter, lxc, firecracker],
type: INPUT_TYPES.SELECT,
values: arrayToOptions(
Array.from({ length: 16 }, (_, i) => i + 1),
OPTION_SORTERS.numeric
),
values: optionsInputsVirtio,
validation: commonValidation,
}
/** @type {Field} Virtio-BLK queues field */
export const VIRTIO_BLK_QUEUES = {
name: 'FEATURES.VIRTIO_BLK_QUEUES',
dependOf: '$general.VCPU',
label: T.VirtioBlkQueues,
tooltip: T.VirtioBlkQueuesConcept,
notOnHypervisors: [vcenter, lxc, firecracker],
type: INPUT_TYPES.SELECT,
values: optionsInputsVirtio,
validation: commonValidation,
}
@ -131,5 +149,6 @@ export const FEATURES_FIELDS = [
LOCALTIME,
GUEST_AGENT,
VIRTIO_SCSI_QUEUES,
VIRTIO_BLK_QUEUES,
IO_THREADS,
]

View File

@ -950,6 +950,9 @@ module.exports = {
VirtioQueues: 'Virtio-scsi Queues',
VirtioQueuesConcept: `Number of vCPU queues to use in the virtio-scsi controller.
Leave blank to use the default value`,
VirtioBlkQueues: 'Virtio-blk Queues',
VirtioBlkQueuesConcept: `Number of vCPU queues to use in the virtio-blk controller.
Leave blank to use the default value`,
IoThreads: 'Iothreads',
IoThreadsConcept: `
Number of iothreads for virtio disks.

View File

@ -145,6 +145,9 @@ define(function(require) {
return self.indexOf(value)===index;
};
var VCPU = ''
var cache = {}
/*
CONSTRUCTOR
*/
@ -199,12 +202,53 @@ define(function(require) {
}
function _onShow(context, panelForm) {
//fill Virtio Queues inputs
getValueVPU(context)
}
function getValueVPU(context, defaultValues){
var inputVcpu = $('#VCPU')
if(defaultValues){
cache = Object.assign({}, defaultValues)
}
fillInputsVirtioQueues(context, inputVcpu, defaultValues)
inputVcpu.off("input").on("input", function(){
fillInputsVirtioQueues(context, inputVcpu, defaultValues)
})
}
function fillInputsVirtioQueues(context, vpu, defaultValues){
var value = parseInt(vpu.val(), 10) * 2 || 4
var scsi = $('[wizard_field="VIRTIO_SCSI_QUEUES"]', context)
var blk = $('[wizard_field="VIRTIO_BLK_QUEUES"]', context)
var defValueBlk = (defaultValues && defaultValues.VIRTIO_BLK_QUEUES) || (cache && cache.VIRTIO_BLK_QUEUES) || ""
var defValueScsi = (defaultValues && defaultValues.VIRTIO_SCSI_QUEUES) || (cache && cache.VIRTIO_SCSI_QUEUES) || ""
var optionEmpty = '<option value> - </option>'
var optionAuto = '<option value="auto">Auto</option>'
var restOptions = '';
for(var i = 1; i <= value; i++){
restOptions += '<option value="'+i+'">'+i+'</option>';
}
scsi.empty().append(optionEmpty+optionAuto+restOptions)
scsi.val(defValueScsi)
blk.empty().append(optionEmpty+optionAuto+restOptions)
blk.val(defValueBlk)
}
function _setup(context) {
var that = this;
Foundation.reflow(context, "tabs");
//fill Virtio Queues inputs
getValueVPU(context)
context.on("click", "button.boot-order-up", function(){
var tr = $(this).closest("tr");
tr.prev().before(tr);
@ -442,8 +486,10 @@ define(function(require) {
}
function _fill(context, templateJSON) {
var featuresJSON = templateJSON["FEATURES"];
var osJSON = templateJSON["OS"];
var modelJSON = templateJSON["CPU_MODEL"];
if (osJSON) {
if (osJSON["KERNEL_DS"] === undefined && osJSON["KERNEL"] !== undefined){
$("input[value=\"kernel_path\"]", context).click();
@ -478,9 +524,10 @@ define(function(require) {
}
}
var featuresJSON = templateJSON["FEATURES"];
if (featuresJSON) {
getValueVPU(context, featuresJSON);
WizardFields.fill(context, featuresJSON);
delete templateJSON["FEATURES"];
}

View File

@ -275,23 +275,18 @@
{{tr "virtio-scsi Queues"}}
{{{tip (tr "Number of vCPU queues to use in the virtio-scsi controller. Leave blank to use the default value.")}}}
<select wizard_field="VIRTIO_SCSI_QUEUES">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value=""> - </option>
<option value="auto">Auto</option>
</select>
</label>
</div>
<div class="medium-6 columns">
<label>
{{tr "virtio-blk Queues"}}
{{{tip (tr "Number of vCPU queues to use in the virtio-blk controller. Leave blank to use the default value.")}}}
<select wizard_field="VIRTIO_BLK_QUEUES">
<option value=""> - </option>
<option value="auto">Auto</option>
</select>
</label>
</div>