cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject git commit: updated refs/heads/4.4 to a7bf66b
Date Tue, 13 May 2014 20:55:33 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/4.4 7a13afca0 -> a7bf66b9f


This patch disallows deleting / modifying system defined guest OS mappings

Local env
1. Create user defined mapping
2. Delete / modify user defined mapping. Should pass
3. Delete / modify system defined mapping. Should fail

Signed off by :- Nitin Mehta<nitin.mehta@citrix.com>


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

Branch: refs/heads/4.4
Commit: a7bf66b9f030d84bec298df857e92e805673130e
Parents: 7a13afc
Author: Amogh Vasekar <amogh.vasekar@citrix.com>
Authored: Mon May 12 22:43:06 2014 -0700
Committer: Daan Hoogland <daan@onecht.net>
Committed: Tue May 13 22:55:14 2014 +0200

----------------------------------------------------------------------
 .../org/apache/cloudstack/api/ApiConstants.java |  1 +
 .../api/response/GuestOSResponse.java           | 13 ++++++++++++
 .../api/response/GuestOsMappingResponse.java    | 12 +++++++++++
 .../cloud/storage/dao/GuestOSHypervisorDao.java |  2 ++
 .../storage/dao/GuestOSHypervisorDaoImpl.java   | 22 ++++++++++++++++++++
 server/src/com/cloud/api/ApiResponseHelper.java |  2 ++
 .../com/cloud/server/ManagementServerImpl.java  | 18 +++++++++++++++-
 7 files changed, 69 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a7bf66b9/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java
index 70e1984..850e67e 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -290,6 +290,7 @@ public class ApiConstants {
     public static final String SPECIFY_VLAN = "specifyvlan";
     public static final String IS_DEFAULT = "isdefault";
     public static final String IS_SYSTEM = "issystem";
+    public static final String IS_USER_DEFINED = "isuserdefined";
     public static final String AVAILABILITY = "availability";
     public static final String NETWORKRATE = "networkrate";
     public static final String HOST_TAGS = "hosttags";

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a7bf66b9/api/src/org/apache/cloudstack/api/response/GuestOSResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/GuestOSResponse.java b/api/src/org/apache/cloudstack/api/response/GuestOSResponse.java
index 9737d60..6822288 100644
--- a/api/src/org/apache/cloudstack/api/response/GuestOSResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/GuestOSResponse.java
@@ -39,6 +39,10 @@ public class GuestOSResponse extends BaseResponse {
     @Param(description = "the name/description of the OS type")
     private String description;
 
+    @SerializedName(ApiConstants.IS_USER_DEFINED)
+    @Param(description = "is the guest OS user defined")
+    private String isUserDefined;
+
     public String getId() {
         return id;
     }
@@ -62,4 +66,13 @@ public class GuestOSResponse extends BaseResponse {
     public void setDescription(String description) {
         this.description = description;
     }
+
+    public String getIsUserDefined() {
+        return isUserDefined;
+    }
+
+    public void setIsUserDefined(String isUserDefined) {
+        this.isUserDefined = isUserDefined;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a7bf66b9/api/src/org/apache/cloudstack/api/response/GuestOsMappingResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/GuestOsMappingResponse.java b/api/src/org/apache/cloudstack/api/response/GuestOsMappingResponse.java
index a0f7d1d..583768d 100644
--- a/api/src/org/apache/cloudstack/api/response/GuestOsMappingResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/GuestOsMappingResponse.java
@@ -52,6 +52,18 @@ public class GuestOsMappingResponse extends BaseResponse {
     @Param(description = "hypervisor specific name for the Guest OS")
     private String osNameForHypervisor;
 
+    @SerializedName(ApiConstants.IS_USER_DEFINED)
+    @Param(description = "is the mapping user defined")
+    private String isUserDefined;
+
+    public String getIsUserDefined() {
+        return isUserDefined;
+    }
+
+    public void setIsUserDefined(String isUserDefined) {
+        this.isUserDefined = isUserDefined;
+    }
+
     public String getId() {
         return id;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a7bf66b9/engine/schema/src/com/cloud/storage/dao/GuestOSHypervisorDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/GuestOSHypervisorDao.java b/engine/schema/src/com/cloud/storage/dao/GuestOSHypervisorDao.java
index 5b6e719..a777516 100644
--- a/engine/schema/src/com/cloud/storage/dao/GuestOSHypervisorDao.java
+++ b/engine/schema/src/com/cloud/storage/dao/GuestOSHypervisorDao.java
@@ -27,4 +27,6 @@ public interface GuestOSHypervisorDao extends GenericDao<GuestOSHypervisorVO,
Lo
     GuestOSHypervisorVO findByOsIdAndHypervisor(long guestOsId, String hypervisorType, String
hypervisorVersion);
 
     boolean removeGuestOsMapping(Long id);
+
+    GuestOSHypervisorVO findByOsIdAndHypervisorAndUserDefined(long guestOsId, String hypervisorType,
String hypervisorVersion, boolean isUserDefined);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a7bf66b9/engine/schema/src/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java
index b06cdfa..5a855b2 100644
--- a/engine/schema/src/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java
@@ -34,6 +34,7 @@ public class GuestOSHypervisorDaoImpl extends GenericDaoBase<GuestOSHypervisorVO
 
     protected final SearchBuilder<GuestOSHypervisorVO> guestOsSearch;
     protected final SearchBuilder<GuestOSHypervisorVO> mappingSearch;
+    protected final SearchBuilder<GuestOSHypervisorVO> userDefinedMappingSearch;
 
     protected GuestOSHypervisorDaoImpl() {
         guestOsSearch = createSearchBuilder();
@@ -45,6 +46,13 @@ public class GuestOSHypervisorDaoImpl extends GenericDaoBase<GuestOSHypervisorVO
         mappingSearch.and("hypervisor_type", mappingSearch.entity().getHypervisorType(),
SearchCriteria.Op.EQ);
         mappingSearch.and("hypervisor_version", mappingSearch.entity().getHypervisorVersion(),
SearchCriteria.Op.EQ);
         mappingSearch.done();
+
+        userDefinedMappingSearch = createSearchBuilder();
+        userDefinedMappingSearch.and("guest_os_id", userDefinedMappingSearch.entity().getGuestOsId(),
SearchCriteria.Op.EQ);
+        userDefinedMappingSearch.and("hypervisor_type", userDefinedMappingSearch.entity().getHypervisorType(),
SearchCriteria.Op.EQ);
+        userDefinedMappingSearch.and("hypervisor_version", userDefinedMappingSearch.entity().getHypervisorVersion(),
SearchCriteria.Op.EQ);
+        userDefinedMappingSearch.and("is_user_defined", userDefinedMappingSearch.entity().getIsUserDefined(),
SearchCriteria.Op.EQ);
+        userDefinedMappingSearch.done();
     }
 
     @Override
@@ -69,6 +77,20 @@ public class GuestOSHypervisorDaoImpl extends GenericDaoBase<GuestOSHypervisorVO
     }
 
     @Override
+    public GuestOSHypervisorVO findByOsIdAndHypervisorAndUserDefined(long guestOsId, String
hypervisorType, String hypervisorVersion, boolean isUserDefined) {
+        SearchCriteria<GuestOSHypervisorVO> sc = userDefinedMappingSearch.create();
+        String version = "default";
+        if (!(hypervisorVersion == null || hypervisorVersion.isEmpty())) {
+            version = hypervisorVersion;
+        }
+        sc.setParameters("guest_os_id", guestOsId);
+        sc.setParameters("hypervisor_type", hypervisorType);
+        sc.setParameters("hypervisor_version", version);
+        sc.setParameters("is_user_defined", isUserDefined);
+        return findOneBy(sc);
+    }
+
+    @Override
     public boolean removeGuestOsMapping(Long id) {
         GuestOSHypervisorVO guestOsHypervisor = findById(id);
         createForUpdate(id);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a7bf66b9/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index d8e26d8..7c342d8 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -3158,6 +3158,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         GuestOSResponse response = new GuestOSResponse();
         response.setDescription(guestOS.getDisplayName());
         response.setId(guestOS.getUuid());
+        response.setIsUserDefined(Boolean.valueOf(guestOS.getIsUserDefined()).toString());
         GuestOSCategoryVO category = ApiDBUtils.findGuestOsCategoryById(guestOS.getCategoryId());
         if (category != null) {
             response.setOsCategoryId(category.getUuid());
@@ -3174,6 +3175,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         response.setHypervisor(guestOSHypervisor.getHypervisorType());
         response.setHypervisorVersion(guestOSHypervisor.getHypervisorVersion());
         response.setOsNameForHypervisor((guestOSHypervisor.getGuestOsName()));
+        response.setIsUserDefined(Boolean.valueOf(guestOSHypervisor.getIsUserDefined()).toString());
         GuestOS guestOs = ApiDBUtils.findGuestOSById(guestOSHypervisor.getGuestOsId());
         if (guestOs != null) {
             response.setOsStdName(guestOs.getDisplayName());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a7bf66b9/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index da25298..4a4c74a 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -2029,7 +2029,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
             throw new InvalidParameterValueException("Unable to find the guest OS by name
or UUID");
         }
         //check for duplicates
-        GuestOSHypervisorVO duplicate = _guestOSHypervisorDao.findByOsIdAndHypervisor(guestOs.getId(),
hypervisorType.toString(), hypervisorVersion);
+        GuestOSHypervisorVO duplicate = _guestOSHypervisorDao.findByOsIdAndHypervisorAndUserDefined(guestOs.getId(),
hypervisorType.toString(), hypervisorVersion, true);
 
         if (duplicate != null) {
             throw new InvalidParameterValueException("Mapping from hypervisor : " + hypervisorType.toString()
+ ", version : " + hypervisorVersion + " and guest OS : "
@@ -2096,6 +2096,10 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
             throw new InvalidParameterValueException("Guest OS not found. Please specify
a valid ID for the Guest OS");
         }
 
+        if (!guestOsHandle.getIsUserDefined()) {
+            throw new InvalidParameterValueException("Unable to modify system defined guest
OS");
+        }
+
         //Check if update is needed
         if (displayName.equals(guestOsHandle.getDisplayName())) {
             return guestOsHandle;
@@ -2127,6 +2131,10 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
             throw new InvalidParameterValueException("Guest OS not found. Please specify
a valid ID for the Guest OS");
         }
 
+        if (!guestOs.getIsUserDefined()) {
+            throw new InvalidParameterValueException("Unable to remove system defined guest
OS");
+        }
+
         return _guestOSDao.remove(id);
     }
 
@@ -2143,6 +2151,10 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
             throw new InvalidParameterValueException("Guest OS Mapping not found. Please
specify a valid ID for the Guest OS Mapping");
         }
 
+        if (!guestOsHypervisorHandle.getIsUserDefined()) {
+            throw new InvalidParameterValueException("Unable to modify system defined Guest
OS mapping");
+        }
+
         GuestOSHypervisorVO guestOsHypervisor = _guestOSHypervisorDao.createForUpdate(id);
         guestOsHypervisor.setGuestOsName(osNameForHypervisor);
         if (_guestOSHypervisorDao.update(id, guestOsHypervisor)) {
@@ -2164,6 +2176,10 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
             throw new InvalidParameterValueException("Guest OS Mapping not found. Please
specify a valid ID for the Guest OS Mapping");
         }
 
+        if (!guestOsHypervisorHandle.getIsUserDefined()) {
+            throw new InvalidParameterValueException("Unable to remove system defined Guest
OS mapping");
+        }
+
         return _guestOSHypervisorDao.removeGuestOsMapping(id);
 
     }


Mime
View raw message