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