cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From weiz...@apache.org
Subject git commit: updated refs/heads/master to 13205e6
Date Tue, 09 Dec 2014 07:22:13 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master f2fe12790 -> 13205e6be


CLOUDSTACK-8050: VM Guest OS type does not update if  template guestostype changes


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/13205e6b
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/13205e6b
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/13205e6b

Branch: refs/heads/master
Commit: 13205e6be119c4dbb5d3bc150190fae0c6edae50
Parents: f2fe127
Author: Wei Zhou <w.zhou@tech.leaseweb.com>
Authored: Tue Dec 9 08:21:35 2014 +0100
Committer: Wei Zhou <w.zhou@tech.leaseweb.com>
Committed: Tue Dec 9 08:21:35 2014 +0100

----------------------------------------------------------------------
 .../src/com/cloud/template/TemplateManagerImpl.java  | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/13205e6b/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index aac040b..f244673 100644
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -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) {


Mime
View raw message