mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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>
This commit is contained in:
parent
8b07b66f14
commit
de266a4cb8
@ -45,6 +45,12 @@ public class UpdateHypervisorCapabilitiesCmd extends BaseCmd {
|
||||
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = HypervisorCapabilitiesResponse.class, description = "ID of the hypervisor capability")
|
||||
private Long id;
|
||||
|
||||
@Parameter(name = ApiConstants.HYPERVISOR, type = CommandType.STRING, description = "the hypervisor for which the hypervisor capabilities are to be updated", since = "4.19.1")
|
||||
private String hypervisor;
|
||||
|
||||
@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")
|
||||
private String hypervisorVersion;
|
||||
|
||||
@Parameter(name = ApiConstants.SECURITY_GROUP_EANBLED, type = CommandType.BOOLEAN, description = "set true to enable security group for this hypervisor.")
|
||||
private Boolean securityGroupEnabled;
|
||||
|
||||
@ -75,6 +81,14 @@ public class UpdateHypervisorCapabilitiesCmd extends BaseCmd {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getHypervisor() {
|
||||
return hypervisor;
|
||||
}
|
||||
|
||||
public String getHypervisorVersion() {
|
||||
return hypervisorVersion;
|
||||
}
|
||||
|
||||
public Long getMaxGuestsLimit() {
|
||||
return maxGuestsLimit;
|
||||
}
|
||||
|
||||
@ -80,6 +80,18 @@ public class HypervisorCapabilitiesVO implements HypervisorCapabilities {
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public HypervisorCapabilitiesVO(HypervisorCapabilitiesVO source) {
|
||||
this.hypervisorType = source.getHypervisorType();
|
||||
this.hypervisorVersion = source.getHypervisorVersion();
|
||||
this.maxGuestsLimit = source.getMaxGuestsLimit();
|
||||
this.maxDataVolumesLimit = source.getMaxDataVolumesLimit();
|
||||
this.maxHostsPerCluster = source.getMaxHostsPerCluster();
|
||||
this.securityGroupEnabled = source.isSecurityGroupEnabled();
|
||||
this.storageMotionSupported = source.isStorageMotionSupported();
|
||||
this.vmSnapshotEnabled = source.isVmSnapshotEnabled();
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param hypervisorType the hypervisorType to set
|
||||
*/
|
||||
|
||||
@ -5065,22 +5065,51 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
||||
return new Pair<List<? extends HypervisorCapabilities>, Integer>(result.first(), result.second());
|
||||
}
|
||||
|
||||
protected HypervisorCapabilitiesVO getHypervisorCapabilitiesForUpdate(final Long id, final String hypervisorStr, final String hypervisorVersion) {
|
||||
if (id == null && StringUtils.isAllEmpty(hypervisorStr, hypervisorVersion)) {
|
||||
throw new InvalidParameterValueException("Either ID or hypervisor and hypervisor version must be specified");
|
||||
}
|
||||
if (id != null) {
|
||||
if (!StringUtils.isAllBlank(hypervisorStr, hypervisorVersion)) {
|
||||
throw new InvalidParameterValueException("ID can not be specified together with hypervisor and hypervisor version");
|
||||
}
|
||||
HypervisorCapabilitiesVO hpvCapabilities = _hypervisorCapabilitiesDao.findById(id, true);
|
||||
if (hpvCapabilities == null) {
|
||||
final InvalidParameterValueException ex = new InvalidParameterValueException("unable to find the hypervisor capabilities for specified id");
|
||||
ex.addProxyObject(id.toString(), "Id");
|
||||
throw ex;
|
||||
}
|
||||
return hpvCapabilities;
|
||||
}
|
||||
if (StringUtils.isAnyBlank(hypervisorStr, hypervisorVersion)) {
|
||||
throw new InvalidParameterValueException("Hypervisor and hypervisor version must be specified together");
|
||||
}
|
||||
HypervisorType hypervisorType = HypervisorType.getType(hypervisorStr);
|
||||
if (hypervisorType == HypervisorType.None) {
|
||||
throw new InvalidParameterValueException("Invalid hypervisor specified");
|
||||
}
|
||||
HypervisorCapabilitiesVO hpvCapabilities = _hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(hypervisorType, hypervisorVersion);
|
||||
if (hpvCapabilities == null) {
|
||||
final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find the hypervisor capabilities for specified hypervisor and hypervisor version");
|
||||
ex.addProxyObject(hypervisorStr, "hypervisor");
|
||||
ex.addProxyObject(hypervisorVersion, "hypervisorVersion");
|
||||
throw ex;
|
||||
}
|
||||
return hpvCapabilities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HypervisorCapabilities updateHypervisorCapabilities(UpdateHypervisorCapabilitiesCmd cmd) {
|
||||
final Long id = cmd.getId();
|
||||
Long id = cmd.getId();
|
||||
final String hypervisorStr = cmd.getHypervisor();
|
||||
final String hypervisorVersion = cmd.getHypervisorVersion();
|
||||
final Boolean securityGroupEnabled = cmd.getSecurityGroupEnabled();
|
||||
final Long maxGuestsLimit = cmd.getMaxGuestsLimit();
|
||||
final Integer maxDataVolumesLimit = cmd.getMaxDataVolumesLimit();
|
||||
final Boolean storageMotionSupported = cmd.getStorageMotionSupported();
|
||||
final Integer maxHostsPerClusterLimit = cmd.getMaxHostsPerClusterLimit();
|
||||
final Boolean vmSnapshotEnabled = cmd.getVmSnapshotEnabled();
|
||||
HypervisorCapabilitiesVO hpvCapabilities = _hypervisorCapabilitiesDao.findById(id, true);
|
||||
|
||||
if (hpvCapabilities == null) {
|
||||
final InvalidParameterValueException ex = new InvalidParameterValueException("unable to find the hypervisor capabilities for specified id");
|
||||
ex.addProxyObject(id.toString(), "Id");
|
||||
throw ex;
|
||||
}
|
||||
HypervisorCapabilitiesVO hpvCapabilities = getHypervisorCapabilitiesForUpdate(id, hypervisorStr, hypervisorVersion);
|
||||
|
||||
final boolean updateNeeded = securityGroupEnabled != null || maxGuestsLimit != null ||
|
||||
maxDataVolumesLimit != null || storageMotionSupported != null || maxHostsPerClusterLimit != null ||
|
||||
@ -5088,7 +5117,14 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
||||
if (!updateNeeded) {
|
||||
return hpvCapabilities;
|
||||
}
|
||||
if (StringUtils.isNotBlank(hypervisorVersion) && !hpvCapabilities.getHypervisorVersion().equals(hypervisorVersion)) {
|
||||
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()));
|
||||
HypervisorCapabilitiesVO copy = new HypervisorCapabilitiesVO(hpvCapabilities);
|
||||
copy.setHypervisorVersion(hypervisorVersion);
|
||||
hpvCapabilities = _hypervisorCapabilitiesDao.persist(copy);
|
||||
}
|
||||
|
||||
id = hpvCapabilities.getId();
|
||||
hpvCapabilities = _hypervisorCapabilitiesDao.createForUpdate(id);
|
||||
|
||||
if (securityGroupEnabled != null) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user