Skip to content

Commit ee4ae2c

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

File tree

5 files changed

+65
-7
lines changed

5 files changed

+65
-7
lines changed

server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ public Map<String, String> getBackupDetailsFromVM(VirtualMachine vm) {
388388
details.put(ApiConstants.TEMPLATE_ID, template.getUuid());
389389
GuestOSVO guestOS = _guestOSDao.findById(guestOSId);
390390
if (guestOS != null) {
391-
details.put(ApiConstants.OS_ID, guestOS.getUuid());
391+
details.put(ApiConstants.OS_TYPE_ID, guestOS.getUuid());
392392
}
393393
}
394394

@@ -2113,8 +2113,8 @@ Map<String, String> getDetailsFromBackupDetails(Long backupId) {
21132113
details.put(ApiConstants.IS_ISO, String.valueOf(template.getFormat().equals(Storage.ImageFormat.ISO)));
21142114
}
21152115
}
2116-
if (details.containsKey(ApiConstants.OS_ID)) {
2117-
GuestOSVO guestOS = _guestOSDao.findByUuid(details.get(ApiConstants.OS_ID));
2116+
if (details.containsKey(ApiConstants.OS_TYPE_ID)) {
2117+
GuestOSVO guestOS = _guestOSDao.findByUuid(details.get(ApiConstants.OS_TYPE_ID));
21182118
if (guestOS != null) {
21192119
details.put(ApiConstants.OS_NAME, guestOS.getDisplayName());
21202120
}

server/src/test/java/org/apache/cloudstack/backup/BackupManagerTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.cloud.storage.VolumeApiService;
5050
import com.cloud.storage.VolumeVO;
5151
import com.cloud.storage.dao.DiskOfferingDao;
52+
import com.cloud.storage.dao.GuestOSDao;
5253
import com.cloud.storage.dao.VMTemplateDao;
5354
import com.cloud.storage.dao.VolumeDao;
5455
import com.cloud.user.Account;
@@ -234,6 +235,9 @@ public class BackupManagerTest {
234235
@Mock
235236
DomainDao domainDao;
236237

238+
@Mock
239+
private GuestOSDao _guestOSDao;
240+
237241
private Gson gson;
238242

239243
private String[] hostPossibleValues = {"127.0.0.1", "hostname"};

ui/src/components/view/BackupMetadata.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default {
9191
}
9292
const fieldOrder = [
9393
'templateid',
94-
'osid',
94+
'ostypeid',
9595
'hypervisor',
9696
'serviceofferingid',
9797
'nics',
@@ -112,9 +112,6 @@ export default {
112112
if (field === 'vmsettings') {
113113
return this.$t('label.settings')
114114
}
115-
if (field === 'osid') {
116-
return this.$t('label.ostypeid')
117-
}
118115
return this.$t('label.' + String(field).toLowerCase())
119116
},
120117
getTemplateDisplayName () {

ui/src/components/view/DeployVMFromBackup.vue

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@
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>
167170
<a-card
168171
:tabList="tabList"
169172
:activeTabKey="tabKey"
@@ -933,6 +936,7 @@ export default {
933936
dataPreFill: {},
934937
showDetails: false,
935938
showRootDiskSizeChanger: false,
939+
showTemplateOsIdWarning: false,
936940
showOverrideDiskOfferingOption: false,
937941
securitygroupids: [],
938942
rootDiskSizeFixed: 0,
@@ -975,6 +979,10 @@ export default {
975979
crossZoneInstanceCreationEnabled () {
976980
return this.dataPreFill.crosszoneinstancecreation
977981
},
982+
showTemplateOsIdWarning2 () {
983+
console.log('showTemplateOsIdWarning called with templateid:', this.form.templateid)
984+
return this.form.templateid && this.templateOsIdIsDifferent(this.form.templateid)
985+
},
978986
isNormalUserOrProject () {
979987
return ['User'].includes(this.$store.getters.userInfo.roletype) || store.getters.project.id
980988
},
@@ -1613,6 +1621,46 @@ export default {
16131621
{ id: 'storage_specific', description: 'storage_specific' }
16141622
]
16151623
},
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+
},
16161664
fetchInstaceGroups () {
16171665
this.options.instanceGroups = []
16181666
getAPI('listInstanceGroups', {
@@ -1658,6 +1706,13 @@ export default {
16581706
if (name === 'templateid') {
16591707
this.tabKey = 'templateid'
16601708
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+
}
16611716
this.form.isoid = null
16621717
this.resetFromTemplateConfiguration()
16631718
let template = ''

ui/src/views/storage/CreateVMFromBackup.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ export default {
123123
this.dataPreFill.zoneid = this.resource.zoneid
124124
this.dataPreFill.crosszoneinstancecreation = this.backupOffering?.crosszoneinstancecreation || this.backupOffering.provider === 'dummy'
125125
this.dataPreFill.isIso = (this.vmdetails.isiso === 'true')
126+
this.dataPreFill.ostypeid = this.resource.vmdetails.ostypeid
127+
this.dataPreFill.osname = this.resource.vmdetails.osname
126128
this.dataPreFill.backupid = this.resource.id
127129
this.dataPreFill.computeofferingid = this.vmdetails.serviceofferingid
128130
this.dataPreFill.templateid = this.vmdetails.templateid

0 commit comments

Comments
 (0)