Skip to content

Commit da3be68

Browse files
committed
show warning in create instance from backup form if guest os type is different
1 parent ee4ae2c commit da3be68

File tree

4 files changed

+38
-57
lines changed

4 files changed

+38
-57
lines changed

ui/public/locales/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,6 +2876,8 @@
28762876
"message.action.create.snapshot.from.vmsnapshot": "Please confirm that you want to create Snapshot from Instance Snapshot",
28772877
"message.action.create.instance.from.backup": "Please confirm that you want to create a new Instance from the given Backup.<br>Click on configure to edit the parameters for the new Instance before creation.",
28782878
"message.create.instance.from.backup.different.zone": "Creating Instance from Backup on a different Zone. Please ensure that the backup repository is accessible in the selected Zone.",
2879+
"message.template.ostype.different.from.backup": "Selected Template has a different OS type than the Backup. Please proceed with caution.",
2880+
"message.iso.ostype.different.from.backup": "Selected ISO has a different OS type than the Backup. Please proceed with caution.",
28792881
"message.action.delete.asnrange": "Please confirm the AS range that you want to delete",
28802882
"message.action.delete.autoscale.vmgroup": "Please confirm that you want to delete this autoscaling group.",
28812883
"message.action.delete.backup.offering": "Please confirm that you want to delete this backup offering?",

ui/src/components/view/BackupMetadata.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
{{ getTemplateDisplayName() }}
4343
</router-link>
4444
</div>
45-
<div v-else-if="item === 'osid'">
45+
<div v-else-if="item === 'ostypeid'">
4646
<router-link :to="{ path: '/guestos' + '/' + backupMetadata[item] }">
4747
{{ backupMetadata.osname }}
4848
</router-link>

ui/src/components/view/DeployVMFromBackup.vue

Lines changed: 34 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,26 @@
164164
:status="zoneSelected ? 'process' : 'wait'">
165165
<template #description>
166166
<div v-if="zoneSelected" style="margin-top: 15px">
167-
<div v-if="showTemplateOsIdWarning" style="color: red">
168-
{{ $t('message.create.instance.from.backup.template.osid.different') }}
169-
</div>
170167
<a-card
171168
:tabList="tabList"
172169
:activeTabKey="tabKey"
173170
@tabChange="key => onTabChange(key, 'tabKey')">
171+
<a-alert v-if="showOsTypeWarning">
172+
<template #message>
173+
<div v-if="selectedTemplateIso && dataPreFill.ostypename">
174+
{{ selectedTemplateIso.message }}<br>
175+
{{ selectedTemplateIso.label }} :
176+
<router-link :to="{ path: '/guestos/' + selectedTemplateIso.item.ostypeid }">
177+
{{ selectedTemplateIso.item.ostypename }}
178+
</router-link><br>
179+
{{ $t('label.backup') }} :
180+
<router-link :to="{ path: '/guestos/' + dataPreFill.ostypeid }">
181+
{{ dataPreFill.ostypename }}
182+
</router-link>
183+
</div>
184+
</template>
185+
</a-alert>
186+
<br v-if="showOsTypeWarning"/>
174187
<div v-if="tabKey === 'templateid'">
175188
{{ $t('message.template.desc') }}
176189
<div v-if="isZoneSelectedMultiArch" style="width: 100%; margin-top: 5px">
@@ -936,7 +949,7 @@ export default {
936949
dataPreFill: {},
937950
showDetails: false,
938951
showRootDiskSizeChanger: false,
939-
showTemplateOsIdWarning: false,
952+
showOsTypeWarning: false,
940953
showOverrideDiskOfferingOption: false,
941954
securitygroupids: [],
942955
rootDiskSizeFixed: 0,
@@ -979,13 +992,18 @@ export default {
979992
crossZoneInstanceCreationEnabled () {
980993
return this.dataPreFill.crosszoneinstancecreation
981994
},
982-
showTemplateOsIdWarning2 () {
983-
console.log('showTemplateOsIdWarning called with templateid:', this.form.templateid)
984-
return this.form.templateid && this.templateOsIdIsDifferent(this.form.templateid)
985-
},
986995
isNormalUserOrProject () {
987996
return ['User'].includes(this.$store.getters.userInfo.roletype) || store.getters.project.id
988997
},
998+
selectedTemplateIso () {
999+
if (this.tabKey === 'templateid' && this.template?.ostypeid) {
1000+
return { label: this.$t('label.template'), item: this.template, message: this.$t('message.template.ostype.different.from.backup') }
1001+
}
1002+
if (this.tabKey === 'isoid' && this.iso?.ostypeid) {
1003+
return { label: this.$t('label.iso'), item: this.iso, message: this.$t('message.iso.ostype.different.from.backup') }
1004+
}
1005+
return null
1006+
},
9891007
diskSize () {
9901008
const customRootDiskSize = _.get(this.instanceConfig, 'rootdisksize', null)
9911009
const customDataDiskSize = _.get(this.instanceConfig, 'size', null)
@@ -1621,46 +1639,6 @@ export default {
16211639
{ id: 'storage_specific', description: 'storage_specific' }
16221640
]
16231641
},
1624-
templateOsIdIsDifferent (templateid) {
1625-
console.log('templateOsIdIsDifferent called with templateid:', templateid)
1626-
console.log('dataPreFill:', this.dataPreFill)
1627-
if (!templateid) {
1628-
console.log('No templateid provided, returning false')
1629-
return false
1630-
}
1631-
if (!this.dataPreFill || !this.dataPreFill.osid) {
1632-
console.log('No dataPreFill.osid available, returning false')
1633-
return false
1634-
}
1635-
console.log('Looking for template with id:', templateid)
1636-
console.log('Available template options:', this.options.templates)
1637-
// Find the selected template by ID
1638-
let selectedTemplate = null
1639-
for (const key in this.options.templates) {
1640-
const templateList = _.get(this.options.templates[key], 'template', [])
1641-
console.log(`Searching in template category ${key}:`, templateList)
1642-
const template = _.find(templateList, (option) => option.id === templateid)
1643-
if (template) {
1644-
selectedTemplate = template
1645-
console.log('Found template:', selectedTemplate)
1646-
break
1647-
}
1648-
}
1649-
if (!selectedTemplate) {
1650-
console.log('Template not found with id:', templateid)
1651-
return false
1652-
}
1653-
if (!selectedTemplate.ostypeid) {
1654-
console.log('Selected template has no osid:', selectedTemplate)
1655-
return false
1656-
}
1657-
const isDifferent = selectedTemplate.ostypeid !== this.dataPreFill.osid
1658-
console.log('Template osid:', selectedTemplate.ostypeid)
1659-
console.log('DataPreFill osid:', this.dataPreFill.osid)
1660-
console.log('Are they different?', isDifferent)
1661-
// Return true if the template's osid is different from dataPreFill.osid
1662-
return isDifferent
1663-
},
16641642
fetchInstaceGroups () {
16651643
this.options.instanceGroups = []
16661644
getAPI('listInstanceGroups', {
@@ -1706,13 +1684,6 @@ export default {
17061684
if (name === 'templateid') {
17071685
this.tabKey = 'templateid'
17081686
this.form.templateid = value
1709-
if (this.templateOsIdIsDifferent(value)) {
1710-
console.log('Showing template osid warning')
1711-
this.showTemplateOsIdWarning = true
1712-
} else {
1713-
console.log('Hiding template osid warning')
1714-
this.showTemplateOsIdWarning = false
1715-
}
17161687
this.form.isoid = null
17171688
this.resetFromTemplateConfiguration()
17181689
let template = ''
@@ -1742,6 +1713,7 @@ export default {
17421713
this.form.iothreadsenabled = template.details && Object.prototype.hasOwnProperty.call(template.details, 'iothreads')
17431714
this.form.iodriverpolicy = template.details?.['io.policy']
17441715
this.form.keyboard = template.details?.keyboard
1716+
this.showOsTypeWarning = template.ostypeid !== this.dataPreFill.ostypeid
17451717
if (template.details['vmware-to-kvm-mac-addresses']) {
17461718
this.dataPreFill.macAddressArray = JSON.parse(template.details['vmware-to-kvm-mac-addresses'])
17471719
}
@@ -1755,6 +1727,13 @@ export default {
17551727
this.tabKey = 'isoid'
17561728
this.form.isoid = value
17571729
this.form.templateid = null
1730+
for (const key in this.options.isos) {
1731+
var iso = _.find(_.get(this.options.isos[key], 'iso', []), (option) => option.id === value)
1732+
if (iso) {
1733+
this.showOsTypeWarning = iso.ostypeid !== this.dataPreFill.ostypeid
1734+
break
1735+
}
1736+
}
17581737
} else if (['cpuspeed', 'cpunumber', 'memory'].includes(name)) {
17591738
this.vm[name] = value
17601739
this.form[name] = value

ui/src/views/storage/CreateVMFromBackup.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export default {
124124
this.dataPreFill.crosszoneinstancecreation = this.backupOffering?.crosszoneinstancecreation || this.backupOffering.provider === 'dummy'
125125
this.dataPreFill.isIso = (this.vmdetails.isiso === 'true')
126126
this.dataPreFill.ostypeid = this.resource.vmdetails.ostypeid
127-
this.dataPreFill.osname = this.resource.vmdetails.osname
127+
this.dataPreFill.ostypename = this.resource.vmdetails.osname
128128
this.dataPreFill.backupid = this.resource.id
129129
this.dataPreFill.computeofferingid = this.vmdetails.serviceofferingid
130130
this.dataPreFill.templateid = this.vmdetails.templateid

0 commit comments

Comments
 (0)