mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-8050: VM Guest OS type does not update if template guestostype changes
This commit is contained in:
parent
f2fe127901
commit
13205e6be1
|
|
@ -168,6 +168,7 @@ import com.cloud.utils.component.ManagerBase;
|
|||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.EntityManager;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.TransactionCallbackNoReturn;
|
||||
import com.cloud.utils.db.TransactionStatus;
|
||||
|
|
@ -1832,6 +1833,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||
}
|
||||
|
||||
if (guestOSId != null) {
|
||||
long oldGuestOSId = template.getGuestOSId();
|
||||
GuestOSVO guestOS = _guestOSDao.findById(guestOSId);
|
||||
|
||||
if (guestOS == null) {
|
||||
|
|
@ -1839,6 +1841,19 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||
} else {
|
||||
template.setGuestOSId(guestOSId);
|
||||
}
|
||||
|
||||
if (guestOSId != oldGuestOSId) { // vm guest os type need to be updated if template guest os id changes.
|
||||
SearchCriteria<VMInstanceVO> sc = _vmInstanceDao.createSearchCriteria();
|
||||
sc.addAnd("templateId", SearchCriteria.Op.EQ, id);
|
||||
sc.addAnd("state", SearchCriteria.Op.NEQ, State.Expunging);
|
||||
List<VMInstanceVO> vms = _vmInstanceDao.search(sc, null);
|
||||
if (vms != null && !vms.isEmpty()) {
|
||||
for (VMInstanceVO vm: vms) {
|
||||
vm.setGuestOSId(guestOSId);
|
||||
_vmInstanceDao.update(vm.getId(), vm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (passwordEnabled != null) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue