Search in sources :

Example 1 with OutOfBandManagementResponse

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);
}
Also used : OutOfBandManagementResponse(org.apache.cloudstack.api.response.OutOfBandManagementResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Host(com.cloud.host.Host)

Example 2 with OutOfBandManagementResponse

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);
}
Also used : OutOfBandManagementResponse(org.apache.cloudstack.api.response.OutOfBandManagementResponse) DataCenter(com.cloud.dc.DataCenter) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 3 with OutOfBandManagementResponse

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);
}
Also used : OutOfBandManagementResponse(org.apache.cloudstack.api.response.OutOfBandManagementResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Host(com.cloud.host.Host) PowerOperation(org.apache.cloudstack.outofbandmanagement.OutOfBandManagement.PowerOperation)

Example 4 with OutOfBandManagementResponse

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;
}
Also used : OutOfBandManagementResponse(org.apache.cloudstack.api.response.OutOfBandManagementResponse) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ActionEvent(com.cloud.event.ActionEvent)

Example 5 with OutOfBandManagementResponse

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

OutOfBandManagementResponse (org.apache.cloudstack.api.response.OutOfBandManagementResponse)13 ServerApiException (org.apache.cloudstack.api.ServerApiException)9 Host (com.cloud.host.Host)5 ActionEvent (com.cloud.event.ActionEvent)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 DataCenter (com.cloud.dc.DataCenter)2 Cluster (com.cloud.org.Cluster)2 OutOfBandManagementDriverResponse (org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse)2 TransactionStatus (com.cloud.utils.db.TransactionStatus)1 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)1 ConfigurationException (javax.naming.ConfigurationException)1 PowerOperation (org.apache.cloudstack.outofbandmanagement.OutOfBandManagement.PowerOperation)1 OutOfBandManagementDriverChangePasswordCommand (org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverChangePasswordCommand)1 OutOfBandManagementDriverPowerCommand (org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverPowerCommand)1