Search in sources :

Example 6 with OutOfBandManagementResponse

use of org.apache.cloudstack.api.response.OutOfBandManagementResponse in project cloudstack by apache.

the class OutOfBandManagementServiceImpl method buildEnableDisableResponse.

private OutOfBandManagementResponse buildEnableDisableResponse(final boolean enabled) {
    final OutOfBandManagementResponse response = new OutOfBandManagementResponse();
    response.setEnabled(enabled);
    response.setSuccess(true);
    return response;
}
Also used : OutOfBandManagementResponse(org.apache.cloudstack.api.response.OutOfBandManagementResponse)

Example 7 with OutOfBandManagementResponse

use of org.apache.cloudstack.api.response.OutOfBandManagementResponse in project cloudstack by apache.

the class OutOfBandManagementServiceImpl method changeOutOfBandManagementPassword.

@Override
@ActionEvent(eventType = EventTypes.EVENT_HOST_OUTOFBAND_MANAGEMENT_CHANGE_PASSWORD, eventDescription = "updating out-of-band management password")
public OutOfBandManagementResponse changeOutOfBandManagementPassword(final Host host, final String newPassword) {
    checkOutOfBandManagementEnabledByZoneClusterHost(host);
    if (Strings.isNullOrEmpty(newPassword)) {
        throw new CloudRuntimeException(String.format("Cannot change out-of-band management password as provided new-password is null or empty for the host %s.", host.getUuid()));
    }
    final OutOfBandManagement outOfBandManagementConfig = outOfBandManagementDao.findByHost(host.getId());
    final ImmutableMap<OutOfBandManagement.Option, String> options = getOptions(outOfBandManagementConfig);
    if (!(options.containsKey(OutOfBandManagement.Option.PASSWORD) && !Strings.isNullOrEmpty(options.get(OutOfBandManagement.Option.PASSWORD)))) {
        throw new CloudRuntimeException(String.format("Cannot change out-of-band management password as we've no previously configured password for the host %s.", host.getUuid()));
    }
    final OutOfBandManagementDriver driver = getDriver(outOfBandManagementConfig);
    final OutOfBandManagementDriverChangePasswordCommand changePasswordCmd = new OutOfBandManagementDriverChangePasswordCommand(options, ActionTimeout.valueIn(host.getClusterId()), newPassword);
    final boolean changePasswordResult = Transaction.execute(new TransactionCallback<Boolean>() {

        @Override
        public Boolean doInTransaction(TransactionStatus status) {
            final OutOfBandManagement updatedOutOfBandManagementConfig = outOfBandManagementDao.findByHost(host.getId());
            updatedOutOfBandManagementConfig.setPassword(newPassword);
            boolean result = outOfBandManagementDao.update(updatedOutOfBandManagementConfig.getId(), (OutOfBandManagementVO) updatedOutOfBandManagementConfig);
            if (!result) {
                throw new CloudRuntimeException(String.format("Failed to change out-of-band management password for host (%s) in the database.", host.getUuid()));
            }
            final OutOfBandManagementDriverResponse driverResponse;
            try {
                driverResponse = driver.execute(changePasswordCmd);
            } catch (Exception e) {
                LOG.error("Out-of-band management change password failed due to driver error: " + e.getMessage());
                throw new CloudRuntimeException(String.format("Failed to change out-of-band management password for host (%s) due to driver error: %s", host.getUuid(), e.getMessage()));
            }
            if (!driverResponse.isSuccess()) {
                throw new CloudRuntimeException(String.format("Failed to change out-of-band management password for host (%s) with error: %s", host.getUuid(), driverResponse.getError()));
            }
            return result && driverResponse.isSuccess();
        }
    });
    final OutOfBandManagementResponse response = new OutOfBandManagementResponse();
    response.setSuccess(changePasswordResult);
    response.setId(host.getUuid());
    return response;
}
Also used : OutOfBandManagementResponse(org.apache.cloudstack.api.response.OutOfBandManagementResponse) OutOfBandManagementDriverResponse(org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse) TransactionStatus(com.cloud.utils.db.TransactionStatus) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) OutOfBandManagementDriverChangePasswordCommand(org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverChangePasswordCommand) ActionEvent(com.cloud.event.ActionEvent)

Example 8 with OutOfBandManagementResponse

use of org.apache.cloudstack.api.response.OutOfBandManagementResponse in project cloudstack by apache.

the class ChangeOutOfBandManagementPasswordCmd 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().setEventDetails("Host Id: " + host.getId() + " Password: " + getPassword().charAt(0) + "****");
    CallContext.current().putContextParameter(Host.class, host.getUuid());
    final OutOfBandManagementResponse response = outOfBandManagementService.changeOutOfBandManagementPassword(host, getPassword());
    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 9 with OutOfBandManagementResponse

use of org.apache.cloudstack.api.response.OutOfBandManagementResponse in project cloudstack by apache.

the class DisableOutOfBandManagementForClusterCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public final void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    final Cluster cluster = _resourceService.getCluster(getClusterId());
    if (cluster == null) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find cluster by ID: " + getClusterId());
    }
    OutOfBandManagementResponse response = outOfBandManagementService.disableOutOfBandManagement(cluster);
    CallContext.current().setEventDetails("Cluster Id:" + cluster.getId() + " out-of-band management enabled: false");
    CallContext.current().putContextParameter(Cluster.class, cluster.getUuid());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : OutOfBandManagementResponse(org.apache.cloudstack.api.response.OutOfBandManagementResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Cluster(com.cloud.org.Cluster)

Example 10 with OutOfBandManagementResponse

use of org.apache.cloudstack.api.response.OutOfBandManagementResponse in project cloudstack by apache.

the class DisableOutOfBandManagementForHostCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public final 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());
    }
    OutOfBandManagementResponse response = outOfBandManagementService.disableOutOfBandManagement(host);
    CallContext.current().setEventDetails("Host Id:" + host.getId() + " out-of-band management enabled: false");
    CallContext.current().putContextParameter(Host.class, host.getUuid());
    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)

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