Skip to content
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.cloudstack.outofbandmanagement.OutOfBandManagement.PowerOperation;
import org.apache.cloudstack.outofbandmanagement.OutOfBandManagementService;
import org.joda.time.DateTime;
import com.cloud.host.Status;

import javax.inject.Inject;

Expand Down Expand Up @@ -84,11 +85,18 @@ public boolean recover(Host r) throws HARecoveryException {

@Override
public boolean fence(Host r) throws HAFenceException {

try {
if (outOfBandManagementService.isOutOfBandManagementEnabled(r)){
final OutOfBandManagementResponse resp = outOfBandManagementService.executePowerOperation(r, PowerOperation.OFF, null);
return resp.getSuccess();
// host exists and is managed OOB
if (r != null && outOfBandManagementService.isOutOfBandManagementEnabled(r)) {
// check host status
if (Status.Down.equals(r.getStatus())) {
logger.info("Host " + r.getName() + " is already down. Returning success.");
return true;
} else {
final OutOfBandManagementResponse resp = outOfBandManagementService.executePowerOperation(r, PowerOperation.OFF, null);
return resp.getSuccess();
}
} else {
logger.warn("OOBM fence operation failed for this host " + r.getName());
return false;
Expand Down
Loading