Search in sources :

Example 1 with OutOfBandManagementDriverPowerCommand

use of org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverPowerCommand in project cloudstack by apache.

the class OutOfBandManagementServiceImpl method executeOutOfBandManagementPowerOperation.

@Override
@ActionEvent(eventType = EventTypes.EVENT_HOST_OUTOFBAND_MANAGEMENT_ACTION, eventDescription = "issuing host out-of-band management action", async = true)
public OutOfBandManagementResponse executeOutOfBandManagementPowerOperation(final Host host, final OutOfBandManagement.PowerOperation powerOperation, final Long timeout) {
    checkOutOfBandManagementEnabledByZoneClusterHost(host);
    final OutOfBandManagement outOfBandManagementConfig = getConfigForHost(host);
    final ImmutableMap<OutOfBandManagement.Option, String> options = getOptions(outOfBandManagementConfig);
    final OutOfBandManagementDriver driver = getDriver(outOfBandManagementConfig);
    Long actionTimeOut = timeout;
    if (actionTimeOut == null) {
        actionTimeOut = ActionTimeout.valueIn(host.getClusterId());
    }
    final OutOfBandManagementDriverPowerCommand cmd = new OutOfBandManagementDriverPowerCommand(options, actionTimeOut, powerOperation);
    final OutOfBandManagementDriverResponse driverResponse = driver.execute(cmd);
    if (driverResponse == null) {
        throw new CloudRuntimeException(String.format("Out-of-band Management action (%s) on host (%s) failed due to no response from the driver", powerOperation, host.getUuid()));
    }
    if (powerOperation.equals(OutOfBandManagement.PowerOperation.STATUS)) {
        transitionPowerState(driverResponse.toEvent(), outOfBandManagementConfig);
    }
    if (!driverResponse.isSuccess()) {
        String errorMessage = String.format("Out-of-band Management action (%s) on host (%s) failed with error: %s", powerOperation, host.getUuid(), driverResponse.getError());
        if (driverResponse.hasAuthFailure()) {
            errorMessage = String.format("Out-of-band Management action (%s) on host (%s) failed due to authentication error: %s. Please check configured credentials.", powerOperation, host.getUuid(), driverResponse.getError());
            sendAuthError(host, errorMessage);
        }
        if (!powerOperation.equals(OutOfBandManagement.PowerOperation.STATUS)) {
            LOG.debug(errorMessage);
        }
        throw new CloudRuntimeException(errorMessage);
    }
    final OutOfBandManagementResponse response = new OutOfBandManagementResponse(outOfBandManagementDao.findByHost(host.getId()));
    response.setSuccess(driverResponse.isSuccess());
    response.setResultDescription(driverResponse.getResult());
    response.setId(host.getUuid());
    response.setOutOfBandManagementAction(powerOperation.toString());
    return response;
}
Also used : OutOfBandManagementResponse(org.apache.cloudstack.api.response.OutOfBandManagementResponse) OutOfBandManagementDriverPowerCommand(org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverPowerCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) OutOfBandManagementDriverResponse(org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

ActionEvent (com.cloud.event.ActionEvent)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 OutOfBandManagementResponse (org.apache.cloudstack.api.response.OutOfBandManagementResponse)1 OutOfBandManagementDriverPowerCommand (org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverPowerCommand)1 OutOfBandManagementDriverResponse (org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse)1