Skip to content
Open
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 @@ -38,6 +38,9 @@
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.ha.HAConfigManager;
import org.apache.cloudstack.ha.HAResource;
import org.apache.cloudstack.outofbandmanagement.OutOfBandManagementService;
import com.cloud.hypervisor.Hypervisor.HypervisorType;


import javax.inject.Inject;

Expand All @@ -50,6 +53,9 @@ public final class ConfigureHAForHostCmd extends BaseAsyncCmd {
@Inject
private HAConfigManager haConfigManager;

@Inject
private OutOfBandManagementService outOfBandManagementService;

/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -98,6 +104,12 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find host by ID: " + getHostId());
}

if (host.getHypervisorType() == HypervisorType.KVM) {
if (!outOfBandManagementService.isOutOfBandManagementEnabled(host)) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Cannot configure HA on KVM host because Out-of-Band Management (OOBM) is not enabled.");
}
}

final boolean result = haConfigManager.configureHA(host.getId(), HAResource.ResourceType.Host, getHaProvider());
if (!result) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure HA provider for the host");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.ha.HAConfigManager;
import org.apache.cloudstack.ha.HAResource;

import com.cloud.hypervisor.Hypervisor.HypervisorType;
import org.apache.cloudstack.outofbandmanagement.OutOfBandManagementService;
import javax.inject.Inject;

@APICommand(name = "enableHAForHost", description = "Enables HA for a host",
Expand All @@ -49,6 +50,10 @@ public final class EnableHAForHostCmd extends BaseAsyncCmd {
@Inject
private HAConfigManager haConfigManager;

@Inject
private OutOfBandManagementService outOfBandManagementService;


/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -89,6 +94,15 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
if (host == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find host by ID: " + getHostId());
}

// --- YOUR NEW GUARDRAIL ---
if (host.getHypervisorType() == HypervisorType.KVM) {
if (!outOfBandManagementService.isOutOfBandManagementEnabled(host)) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Cannot enable HA on KVM host because Out-of-Band Management (OOBM) is not enabled.");
}
}
// --------------------------

final boolean result = haConfigManager.enableHA(host.getId(), HAResource.ResourceType.Host);

CallContext.current().setEventDetails("Host Id:" + host.getId() + " HA enabled: true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
import org.apache.cloudstack.api.response.OutOfBandManagementResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.outofbandmanagement.OutOfBandManagementService;
import org.apache.cloudstack.ha.HAConfigManager;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import org.apache.cloudstack.ha.HAResource;

import javax.inject.Inject;

Expand All @@ -46,6 +49,9 @@
since = "4.9.0", authorized = {RoleType.Admin})
public class DisableOutOfBandManagementForHostCmd extends BaseAsyncCmd {

@Inject
private HAConfigManager haConfigManager;

@Inject
private OutOfBandManagementService outOfBandManagementService;

Expand All @@ -61,13 +67,22 @@ public class DisableOutOfBandManagementForHostCmd extends BaseAsyncCmd {
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

@Override
final public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
final Host host = _resourceService.getHost(getHostId());
if (host == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find host by ID: " + getHostId());
}

if (host.getHypervisorType() == HypervisorType.KVM) {
java.util.List<org.apache.cloudstack.ha.HAConfig> haConfigs = haConfigManager.listHAResources(host.getId(), HAResource.ResourceType.Host);
if (haConfigs != null && !haConfigs.isEmpty()) {
if (haConfigs.get(0).isEnabled()) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Cannot disable Out-of-Band Management (OOBM) because HA is currently enabled on this KVM host. Please disable HA first.");
}
}
}

OutOfBandManagementResponse response = outOfBandManagementService.disableOutOfBandManagement(host);

CallContext.current().setEventDetails("Host Id:" + host.getId() + " out-of-band management enabled: false");
Expand Down
3 changes: 3 additions & 0 deletions ui/src/config/section/infra/hosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ export default {
docHelp: 'adminguide/hosts.html#out-of-band-management',
dataView: true,
show: (record) => {
if (record.hypervisor === 'KVM' && record?.hostha?.haenable === true) {
return false
}
return record?.outofbandmanagement?.enabled === true
},
args: ['hostid'],
Expand Down