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;
}
Aggregations