Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 of the hypervisor capability", since = "4.19.1")
Comment thread
shwstppr marked this conversation as resolved.
Outdated
private String hypervisor;

@Parameter(name = ApiConstants.HYPERVISOR_VERSION, type = CommandType.STRING, description = "the hypervisor version of the hypervisor capability", since = "4.19.1")
Comment thread
shwstppr marked this conversation as resolved.
Outdated
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
51 changes: 43 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,31 +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();
Comment thread
vishesh92 marked this conversation as resolved.
Outdated
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)) {
Comment thread
JoaoJandre marked this conversation as resolved.
s_logger.debug("Hypervisor capabilities for hypervisor: %s and version: %s does not exist, creating a copy from the parent version: %s for update");
Comment thread
shwstppr marked this conversation as resolved.
Outdated
HypervisorCapabilitiesVO copy = new HypervisorCapabilitiesVO(hpvCapabilities);
copy.setHypervisorVersion(hypervisorVersion);
hpvCapabilities = _hypervisorCapabilitiesDao.persist(copy);
}

hpvCapabilities = _hypervisorCapabilitiesDao.createForUpdate(id);
hpvCapabilities = _hypervisorCapabilitiesDao.createForUpdate(hpvCapabilities.getId());
Copy link
Copy Markdown
Member

@vishesh92 vishesh92 Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to set id = hpvCapabilities.getId().
id is being used in L5156 to update the hypervisor capabilities. If id is not passed in the request, update is not getting triggered if the value already exists because id is null. This is also resulting in not getting any output.

(localcloud) __ > update hypervisorcapabilities hypervisor=VMware hypervisorversion="8.0.0.15" maxdatavolumeslimit=640
__ Error: (HTTP 530, error code 9999) Failed to update hypervisor capabilities

Executing this for the first time creates an entry which is a duplicate of the parent hypervisor. And subsequent command just fails.

Comment thread
shwstppr marked this conversation as resolved.
Outdated

if (securityGroupEnabled != null) {
hpvCapabilities.setSecurityGroupEnabled(securityGroupEnabled);
Expand Down