You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ni...@apache.org on 2014/05/13 07:45:39 UTC
git commit: updated refs/heads/master to 9b6d430
Repository: cloudstack
Updated Branches:
refs/heads/master 0a62eb838 -> 9b6d43017
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<ni...@citrix.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9b6d4301
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9b6d4301
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9b6d4301
Branch: refs/heads/master
Commit: 9b6d430171627667e390efa7e8bfb69a3de7a0a0
Parents: 0a62eb8
Author: Amogh Vasekar <am...@citrix.com>
Authored: Mon May 12 22:43:06 2014 -0700
Committer: Nitin Mehta <ni...@citrix.com>
Committed: Mon May 12 22:45:24 2014 -0700
----------------------------------------------------------------------
.../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/9b6d4301/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 a3faca7..990d041 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -291,6 +291,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/9b6d4301/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/9b6d4301/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/9b6d4301/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/9b6d4301/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 3b05120..0518829 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
@@ -65,6 +73,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/9b6d4301/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 12d09b2..138a0aa 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -2890,6 +2890,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());
@@ -2906,6 +2907,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/9b6d4301/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 671de81..1342e7d 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);
}