Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -75,6 +81,14 @@ public Long getId() {
return id;
}

public String getHypervisor() {
return hypervisor;
}

public String getHypervisorVersion() {
return hypervisorVersion;
}

public Long getMaxGuestsLimit() {
return maxGuestsLimit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ public HypervisorCapabilitiesVO(HypervisorType hypervisorType, String hypervisor
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
*/
Expand Down
52 changes: 44 additions & 8 deletions server/src/main/java/com/cloud/server/ManagementServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5068,30 +5068,66 @@ public Pair<List<? extends HypervisorCapabilities>, Integer> listHypervisorCapab
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 ||
vmSnapshotEnabled != null;
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) {
Expand Down