Search in sources :

Example 1 with OutOfBandManagementDriverResponse

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

the class IpmitoolOutOfBandManagementDriver method execute.

private OutOfBandManagementDriverResponse execute(final OutOfBandManagementDriverPowerCommand cmd) {
    List<String> ipmiToolCommands = IPMITOOL.getIpmiToolCommandArgs(IpmiToolPath.value(), IpmiToolInterface.value(), IpmiToolRetries.value(), cmd.getOptions(), "chassis", "power", IPMITOOL.parsePowerCommand(cmd.getPowerOperation()));
    final OutOfBandManagementDriverResponse response = IPMITOOL.executeCommands(ipmiToolCommands, cmd.getTimeout());
    if (response.isSuccess() && cmd.getPowerOperation().equals(OutOfBandManagement.PowerOperation.STATUS)) {
        response.setPowerState(IPMITOOL.parsePowerState(response.getResult().trim()));
    }
    return response;
}
Also used : OutOfBandManagementDriverResponse(org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse)

Example 2 with OutOfBandManagementDriverResponse

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

the class IpmitoolOutOfBandManagementDriver method getIpmiUserId.

private String getIpmiUserId(ImmutableMap<OutOfBandManagement.Option, String> options, final Duration timeOut) {
    final String username = options.get(OutOfBandManagement.Option.USERNAME);
    if (Strings.isNullOrEmpty(username)) {
        throw new CloudRuntimeException("Empty IPMI user configured, cannot proceed to find user's ID");
    }
    final List<String> ipmiToolCommands = IPMITOOL.getIpmiToolCommandArgs(IpmiToolPath.value(), IpmiToolInterface.value(), IpmiToolRetries.value(), options, "user", "list");
    final OutOfBandManagementDriverResponse output = IPMITOOL.executeCommands(ipmiToolCommands, timeOut);
    if (!output.isSuccess()) {
        throw new CloudRuntimeException("Failed to find IPMI user to change password, error: " + output.getError());
    }
    final String userId = IPMITOOL.findIpmiUser(output.getResult(), username);
    if (Strings.isNullOrEmpty(userId)) {
        throw new CloudRuntimeException("No IPMI user ID found for the username: " + username);
    }
    return userId;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) OutOfBandManagementDriverResponse(org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse)

Example 3 with OutOfBandManagementDriverResponse

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

the class IpmitoolOutOfBandManagementDriver method initDriver.

private void initDriver() {
    isDriverEnabled = true;
    final OutOfBandManagementDriverResponse output = IPMITOOL.executeCommands(Arrays.asList(IpmiToolPath.value(), "-V"));
    if (output.isSuccess() && output.getResult().startsWith("ipmitool version")) {
        isIpmiToolBinAvailable = true;
        LOG.debug("OutOfBandManagementDriver ipmitool initialized: " + output.getResult());
    } else {
        isIpmiToolBinAvailable = false;
        LOG.error("OutOfBandManagementDriver ipmitool failed initialization with error: " + output.getError() + "; standard output: " + output.getResult());
    }
}
Also used : OutOfBandManagementDriverResponse(org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse)

Example 4 with OutOfBandManagementDriverResponse

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

the class IpmitoolWrapper method executeCommands.

public OutOfBandManagementDriverResponse executeCommands(final List<String> commands, final Duration timeOut) {
    final ProcessResult result = RUNNER.executeCommands(commands, timeOut);
    if (LOG.isTraceEnabled()) {
        List<String> cleanedCommands = new ArrayList<String>();
        int maskNextCommand = 0;
        for (String command : commands) {
            if (maskNextCommand > 0) {
                cleanedCommands.add("**** ");
                maskNextCommand--;
                continue;
            }
            if (command.equalsIgnoreCase("-P")) {
                maskNextCommand = 1;
            } else if (command.toLowerCase().endsWith("password")) {
                maskNextCommand = 2;
            }
            cleanedCommands.add(command);
        }
        LOG.trace("Executed ipmitool process with commands: " + StringUtils.join(cleanedCommands, ", ") + "\nIpmitool execution standard output: " + result.getStdOutput() + "\nIpmitool execution error output: " + result.getStdError());
    }
    return new OutOfBandManagementDriverResponse(result.getStdOutput(), result.getStdError(), result.isSuccess());
}
Also used : OutOfBandManagementDriverResponse(org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse) ProcessResult(org.apache.cloudstack.utils.process.ProcessResult) ArrayList(java.util.ArrayList)

Example 5 with OutOfBandManagementDriverResponse

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

the class OutOfBandManagementServiceTest method testOutOfBandManagementDriverResponseEvent.

@Test
public void testOutOfBandManagementDriverResponseEvent() {
    OutOfBandManagementDriverResponse r = new OutOfBandManagementDriverResponse("some result", "some error", false);
    r.setSuccess(false);
    r.setAuthFailure(false);
    Assert.assertEquals(r.toEvent(), OutOfBandManagement.PowerState.Event.Unknown);
    r.setSuccess(false);
    r.setAuthFailure(true);
    Assert.assertEquals(r.toEvent(), OutOfBandManagement.PowerState.Event.AuthError);
    r.setAuthFailure(false);
    r.setSuccess(true);
    r.setPowerState(OutOfBandManagement.PowerState.On);
    Assert.assertEquals(r.toEvent(), OutOfBandManagement.PowerState.Event.On);
    r.setPowerState(OutOfBandManagement.PowerState.Off);
    Assert.assertEquals(r.toEvent(), OutOfBandManagement.PowerState.Event.Off);
    r.setPowerState(OutOfBandManagement.PowerState.Disabled);
    Assert.assertEquals(r.toEvent(), OutOfBandManagement.PowerState.Event.Disabled);
}
Also used : OutOfBandManagementDriverResponse(org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse) Test(org.junit.Test)

Aggregations

OutOfBandManagementDriverResponse (org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 ActionEvent (com.cloud.event.ActionEvent)2 OutOfBandManagementResponse (org.apache.cloudstack.api.response.OutOfBandManagementResponse)2 TransactionStatus (com.cloud.utils.db.TransactionStatus)1 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)1 ArrayList (java.util.ArrayList)1 ConfigurationException (javax.naming.ConfigurationException)1 OutOfBandManagementDriverChangePasswordCommand (org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverChangePasswordCommand)1 OutOfBandManagementDriverPowerCommand (org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverPowerCommand)1 ProcessResult (org.apache.cloudstack.utils.process.ProcessResult)1 Test (org.junit.Test)1