Skip to content

Commit de266a4

Browse files
shwstpprDaanHooglandhsato03vishesh92
authored
api,server: allow updating hypervisor capabilities with hypervisor and version (#8475)
* api,server: allow updating hypervisor capabilities with hypervisor and version hypervisor and hypervisorversion parameter added to the updateHypervisorCapabilities API. * param description * Update server/src/main/java/com/cloud/server/ManagementServerImpl.java Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> Co-authored-by: dahn <daan.hoogland@gmail.com> Co-authored-by: Henrique Sato <henriquesato2003@gmail.com> Co-authored-by: Vishesh <vishesh92@gmail.com>
1 parent 8b07b66 commit de266a4

File tree

3 files changed

+70
-8
lines changed

3 files changed

+70
-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 for which the hypervisor capabilities are to be updated", since = "4.19.1")
49+
private String hypervisor;
50+
51+
@Parameter(name = ApiConstants.HYPERVISOR_VERSION, type = CommandType.STRING, description = "the hypervisor version for which the hypervisor capabilities are to be updated", 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: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5065,30 +5065,66 @@ public Pair<List<? extends HypervisorCapabilities>, Integer> listHypervisorCapab
50655065
return new Pair<List<? extends HypervisorCapabilities>, Integer>(result.first(), result.second());
50665066
}
50675067

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

50855114
final boolean updateNeeded = securityGroupEnabled != null || maxGuestsLimit != null ||
50865115
maxDataVolumesLimit != null || storageMotionSupported != null || maxHostsPerClusterLimit != null ||
50875116
vmSnapshotEnabled != null;
50885117
if (!updateNeeded) {
50895118
return hpvCapabilities;
50905119
}
5120+
if (StringUtils.isNotBlank(hypervisorVersion) && !hpvCapabilities.getHypervisorVersion().equals(hypervisorVersion)) {
5121+
s_logger.debug(String.format("Hypervisor capabilities for hypervisor: %s and version: %s does not exist, creating a copy from the parent version: %s for update.", hypervisorStr, hypervisorVersion, hpvCapabilities.getHypervisorVersion()));
5122+
HypervisorCapabilitiesVO copy = new HypervisorCapabilitiesVO(hpvCapabilities);
5123+
copy.setHypervisorVersion(hypervisorVersion);
5124+
hpvCapabilities = _hypervisorCapabilitiesDao.persist(copy);
5125+
}
50915126

5127+
id = hpvCapabilities.getId();
50925128
hpvCapabilities = _hypervisorCapabilitiesDao.createForUpdate(id);
50935129

50945130
if (securityGroupEnabled != null) {

0 commit comments

Comments
 (0)