Skip to content

Commit 308819c

Browse files
committed
api,server: allow updating hypervisor capabilities with hypervisor and
version hypervisor and hypervisorversion parameter added to the updateHypervisorCapabilities API. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent cadbb56 commit 308819c

File tree

3 files changed

+69
-8
lines changed

3 files changed

+69
-8
lines changed

api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateHypervisorCapabilitiesCmd.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public class UpdateHypervisorCapabilitiesCmd extends BaseCmd {
4545
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = HypervisorCapabilitiesResponse.class, description = "ID of the hypervisor capability")
4646
private Long id;
4747

48+
@Parameter(name = ApiConstants.HYPERVISOR, type = CommandType.STRING, description = "the hypervisor of the hypervisor capability", since = "4.19.1")
49+
private String hypervisor;
50+
51+
@Parameter(name = ApiConstants.HYPERVISOR_VERSION, type = CommandType.STRING, description = "the hypervisor version of the hypervisor capability", since = "4.19.1")
52+
private String hypervisorVersion;
53+
4854
@Parameter(name = ApiConstants.SECURITY_GROUP_EANBLED, type = CommandType.BOOLEAN, description = "set true to enable security group for this hypervisor.")
4955
private Boolean securityGroupEnabled;
5056

@@ -75,6 +81,14 @@ public Long getId() {
7581
return id;
7682
}
7783

84+
public String getHypervisor() {
85+
return hypervisor;
86+
}
87+
88+
public String getHypervisorVersion() {
89+
return hypervisorVersion;
90+
}
91+
7892
public Long getMaxGuestsLimit() {
7993
return maxGuestsLimit;
8094
}

engine/schema/src/main/java/com/cloud/hypervisor/HypervisorCapabilitiesVO.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ public HypervisorCapabilitiesVO(HypervisorType hypervisorType, String hypervisor
8080
this.uuid = UUID.randomUUID().toString();
8181
}
8282

83+
public HypervisorCapabilitiesVO(HypervisorCapabilitiesVO source) {
84+
this.hypervisorType = source.getHypervisorType();
85+
this.hypervisorVersion = source.getHypervisorVersion();
86+
this.maxGuestsLimit = source.getMaxGuestsLimit();
87+
this.maxDataVolumesLimit = source.getMaxDataVolumesLimit();
88+
this.maxHostsPerCluster = source.getMaxHostsPerCluster();
89+
this.securityGroupEnabled = source.isSecurityGroupEnabled();
90+
this.storageMotionSupported = source.isStorageMotionSupported();
91+
this.vmSnapshotEnabled = source.isVmSnapshotEnabled();
92+
this.uuid = UUID.randomUUID().toString();
93+
}
94+
8395
/**
8496
* @param hypervisorType the hypervisorType to set
8597
*/

server/src/main/java/com/cloud/server/ManagementServerImpl.java

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5068,31 +5068,66 @@ public Pair<List<? extends HypervisorCapabilities>, Integer> listHypervisorCapab
50685068
return new Pair<List<? extends HypervisorCapabilities>, Integer>(result.first(), result.second());
50695069
}
50705070

5071+
protected HypervisorCapabilitiesVO getHypervisorCapabilitiesForUpdate(final Long id, final String hypervisorStr, final String hypervisorVersion) {
5072+
if (id == null && StringUtils.isAllEmpty(hypervisorStr, hypervisorVersion)) {
5073+
throw new InvalidParameterValueException("Either ID or hypervisor and hypervisor version must be specified");
5074+
}
5075+
if (id != null) {
5076+
if (!StringUtils.isAllBlank(hypervisorStr, hypervisorVersion)) {
5077+
throw new InvalidParameterValueException("ID can not be specified together with hypervisor and hypervisor version");
5078+
}
5079+
HypervisorCapabilitiesVO hpvCapabilities = _hypervisorCapabilitiesDao.findById(id, true);
5080+
if (hpvCapabilities == null) {
5081+
final InvalidParameterValueException ex = new InvalidParameterValueException("unable to find the hypervisor capabilities for specified id");
5082+
ex.addProxyObject(id.toString(), "Id");
5083+
throw ex;
5084+
}
5085+
return hpvCapabilities;
5086+
}
5087+
if (StringUtils.isAnyBlank(hypervisorStr, hypervisorVersion)) {
5088+
throw new InvalidParameterValueException("Hypervisor and hypervisor version must be specified together");
5089+
}
5090+
HypervisorType hypervisorType = HypervisorType.getType(hypervisorStr);
5091+
if (hypervisorType == HypervisorType.None) {
5092+
throw new InvalidParameterValueException("Invalid hypervisor specified");
5093+
}
5094+
HypervisorCapabilitiesVO hpvCapabilities = _hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(hypervisorType, hypervisorVersion);
5095+
if (hpvCapabilities == null) {
5096+
final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find the hypervisor capabilities for specified hypervisor and hypervisor version");
5097+
ex.addProxyObject(hypervisorStr, "hypervisor");
5098+
ex.addProxyObject(hypervisorVersion, "hypervisorVersion");
5099+
throw ex;
5100+
}
5101+
return hpvCapabilities;
5102+
}
5103+
50715104
@Override
50725105
public HypervisorCapabilities updateHypervisorCapabilities(UpdateHypervisorCapabilitiesCmd cmd) {
50735106
final Long id = cmd.getId();
5107+
final String hypervisorStr = cmd.getHypervisor();
5108+
final String hypervisorVersion = cmd.getHypervisorVersion();
50745109
final Boolean securityGroupEnabled = cmd.getSecurityGroupEnabled();
50755110
final Long maxGuestsLimit = cmd.getMaxGuestsLimit();
50765111
final Integer maxDataVolumesLimit = cmd.getMaxDataVolumesLimit();
50775112
final Boolean storageMotionSupported = cmd.getStorageMotionSupported();
50785113
final Integer maxHostsPerClusterLimit = cmd.getMaxHostsPerClusterLimit();
50795114
final Boolean vmSnapshotEnabled = cmd.getVmSnapshotEnabled();
5080-
HypervisorCapabilitiesVO hpvCapabilities = _hypervisorCapabilitiesDao.findById(id, true);
5081-
5082-
if (hpvCapabilities == null) {
5083-
final InvalidParameterValueException ex = new InvalidParameterValueException("unable to find the hypervisor capabilities for specified id");
5084-
ex.addProxyObject(id.toString(), "Id");
5085-
throw ex;
5086-
}
5115+
HypervisorCapabilitiesVO hpvCapabilities = getHypervisorCapabilitiesForUpdate(id, hypervisorStr, hypervisorVersion);
50875116

50885117
final boolean updateNeeded = securityGroupEnabled != null || maxGuestsLimit != null ||
50895118
maxDataVolumesLimit != null || storageMotionSupported != null || maxHostsPerClusterLimit != null ||
50905119
vmSnapshotEnabled != null;
50915120
if (!updateNeeded) {
50925121
return hpvCapabilities;
50935122
}
5123+
if (StringUtils.isNotBlank(hypervisorVersion) && !hpvCapabilities.getHypervisorVersion().equals(hypervisorVersion)) {
5124+
s_logger.debug("Hypervisor capabilities for hypervisor: %s and version: %s does not exist, creating a copy from the parent version: %s for update");
5125+
HypervisorCapabilitiesVO copy = new HypervisorCapabilitiesVO(hpvCapabilities);
5126+
copy.setHypervisorVersion(hypervisorVersion);
5127+
hpvCapabilities = _hypervisorCapabilitiesDao.persist(copy);
5128+
}
50945129

5095-
hpvCapabilities = _hypervisorCapabilitiesDao.createForUpdate(id);
5130+
hpvCapabilities = _hypervisorCapabilitiesDao.createForUpdate(hpvCapabilities.getId());
50965131

50975132
if (securityGroupEnabled != null) {
50985133
hpvCapabilities.setSecurityGroupEnabled(securityGroupEnabled);

0 commit comments

Comments
 (0)