diff --git a/ui/src/utils/imageSelection.js b/ui/src/utils/imageSelection.js new file mode 100644 index 000000000000..59a6346f1426 --- /dev/null +++ b/ui/src/utils/imageSelection.js @@ -0,0 +1,36 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +export function getImageHypervisor (imageItems, imageType, imageId) { + if (imageType !== 'templateid' || !imageId) { + return null + } + + for (const group of Object.values(imageItems || {})) { + const templates = group?.template + if (!Array.isArray(templates)) { + continue + } + + const image = templates.find(item => item.id === imageId) + if (image) { + return image.hypervisor || null + } + } + + return null +} diff --git a/ui/src/views/compute/wizard/OsBasedImageSelection.vue b/ui/src/views/compute/wizard/OsBasedImageSelection.vue index 6a52eea207b0..767dedb401b3 100644 --- a/ui/src/views/compute/wizard/OsBasedImageSelection.vue +++ b/ui/src/views/compute/wizard/OsBasedImageSelection.vue @@ -130,6 +130,7 @@ import OsLogo from '@/components/widgets/OsLogo' import OsBasedImageSelectionSearchView from '@views/compute/wizard/OsBasedImageSelectionSearchView' import OsBasedImageRadioGroup from '@views/compute/wizard/OsBasedImageRadioGroup' import DiskSizeSelection from '@views/compute/wizard/DiskSizeSelection' +import { getImageHypervisor } from '@/utils/imageSelection' export default { name: 'OsBasedImageSelection', @@ -234,6 +235,20 @@ export default { watch: { selectedImageType (newValue) { this.localSelectedImageType = newValue + this.emitEffectiveHypervisor(newValue, this.selectedImageId) + }, + imageItems () { + this.emitEffectiveHypervisor( + this.localSelectedImageType, + this.selectedImageId, + false + ) + }, + 'preFillContent.hypervisor' () { + this.emitEffectiveHypervisor( + this.localSelectedImageType, + this.selectedImageId + ) }, guestOsCategories (newValue) { this.imageSearchFilters = {} @@ -285,9 +300,30 @@ export default { this.localSelectedGuestOsCategoryId = value this.$emit('change-guest-os-category', this.localSelectedGuestOsCategoryId) }, + emitEffectiveHypervisor (imageType, imageId, useFallback = true) { + const fallbackHypervisor = this.preFillContent?.hypervisor + if (!fallbackHypervisor) { + return + } + const imageHypervisor = getImageHypervisor( + this.imageItems, + imageType, + imageId + ) + if (imageHypervisor || useFallback) { + this.$emit( + 'update-image', + 'hypervisor', + imageHypervisor || fallbackHypervisor + ) + } + }, updateImage (decorator, id) { this.selectedImageId = id this.$emit('update-image', decorator, id) + if (decorator === 'templateid') { + this.emitEffectiveHypervisor(decorator, id) + } }, handleImageSearch (searchFilters) { this.imageSearchFilters = { diff --git a/ui/src/views/compute/wizard/TemplateIsoSelection.vue b/ui/src/views/compute/wizard/TemplateIsoSelection.vue index 4979068dac70..860d1b3eb470 100644 --- a/ui/src/views/compute/wizard/TemplateIsoSelection.vue +++ b/ui/src/views/compute/wizard/TemplateIsoSelection.vue @@ -51,6 +51,7 @@