use of org.apache.cloudstack.api.response.OutOfBandManagementResponse in project cloudstack by apache.
the class ConfigureOutOfBandManagementCmd method execute.
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@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());
}
CallContext.current().putContextParameter(Host.class, host.getUuid());
final OutOfBandManagementResponse response = outOfBandManagementService.configureOutOfBandManagement(host, getHostPMOptions());
response.setId(host.getUuid());
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of org.apache.cloudstack.api.response.OutOfBandManagementResponse in project cloudstack by apache.
the class DisableOutOfBandManagementForZoneCmd method execute.
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public final void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
final DataCenter zone = _resourceService.getZone(getZoneId());
if (zone == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find zone by ID: " + getZoneId());
}
OutOfBandManagementResponse response = outOfBandManagementService.disableOutOfBandManagement(zone);
CallContext.current().setEventDetails("Zone Id:" + zone.getId() + " out-of-band management enabled: false");
CallContext.current().putContextParameter(DataCenter.class, zone.getUuid());
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of org.apache.cloudstack.api.response.OutOfBandManagementResponse in project cloudstack by apache.
the class IssueOutOfBandManagementPowerActionCmd method execute.
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@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());
}
final PowerOperation powerOperation = PowerOperation.valueOf(getPowerAction());
CallContext.current().setEventDetails("Host Id: " + host.getId() + " Action: " + powerOperation.toString());
CallContext.current().putContextParameter(Host.class, host.getUuid());
final OutOfBandManagementResponse response = outOfBandManagementService.executeOutOfBandManagementPowerOperation(host, powerOperation, getActionTimeout());
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of org.apache.cloudstack.api.response.OutOfBandManagementResponse in project cloudstack by apache.
the class OutOfBandManagementServiceImpl method configureOutOfBandManagement.
@Override
@ActionEvent(eventType = EventTypes.EVENT_HOST_OUTOFBAND_MANAGEMENT_CONFIGURE, eventDescription = "updating out-of-band management configuration")
public OutOfBandManagementResponse configureOutOfBandManagement(final Host host, final ImmutableMap<OutOfBandManagement.Option, String> options) {
OutOfBandManagement outOfBandManagementConfig = outOfBandManagementDao.findByHost(host.getId());
if (outOfBandManagementConfig == null) {
outOfBandManagementConfig = outOfBandManagementDao.persist(new OutOfBandManagementVO(host.getId()));
}
outOfBandManagementConfig = updateConfig(outOfBandManagementConfig, options);
if (Strings.isNullOrEmpty(outOfBandManagementConfig.getDriver()) || !outOfBandManagementDriversMap.containsKey(outOfBandManagementConfig.getDriver().toLowerCase())) {
throw new CloudRuntimeException("Out-of-band management driver is not available. Please provide a valid driver name.");
}
boolean updatedConfig = outOfBandManagementDao.update(outOfBandManagementConfig.getId(), (OutOfBandManagementVO) outOfBandManagementConfig);
CallContext.current().setEventDetails("host id:" + host.getId() + " configuration:" + outOfBandManagementConfig.getAddress() + ":" + outOfBandManagementConfig.getPort());
if (!updatedConfig) {
throw new CloudRuntimeException("Failed to update out-of-band management config for the host in the database.");
}
String result = "Out-of-band management successfully configured for the host";
LOG.debug(result);
final OutOfBandManagementResponse response = new OutOfBandManagementResponse(outOfBandManagementDao.findByHost(host.getId()));
response.setResultDescription(result);
response.setSuccess(true);
return response;
}
use of org.apache.cloudstack.api.response.OutOfBandManagementResponse 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