use of com.iwave.ext.command.CommandException in project coprhd-controller by CoprHD.
the class AixHostDiscoveryAdapter method setNativeGuid.
@Override
protected void setNativeGuid(Host host) {
AixSystem aix = getCli(host);
try {
String macAddress = aix.getNetworkAdapterMacAddress(ENT0);
if (macAddress != null && !host.getNativeGuid().equalsIgnoreCase(macAddress)) {
checkDuplicateHost(host, macAddress);
info("Setting nativeGuid for " + host.getId() + " as " + macAddress);
host.setNativeGuid(macAddress);
save(host);
}
} catch (CommandException ex) {
LOG.warn("Failed to get MAC address of adapter during discovery");
}
}
use of com.iwave.ext.command.CommandException in project coprhd-controller by CoprHD.
the class LinuxHostDiscoveryAdapter method getVersions.
protected List<LinuxVersion> getVersions(Host host) {
LinuxSystemCLI cli = createLinuxCLI(host);
List<LinuxVersion> versions = new ArrayList<LinuxVersion>();
LinuxVersionCommand[] commands = { new GetSuSEVersionCommand(), new GetRedhatVersionCommandOne(), new GetRedhatVersionCommandTwo(), new GetRedhatVersionCommandThree(), new GetLinuxVersionLSBReleaseCommand() };
for (LinuxVersionCommand command : commands) {
try {
cli.executeCommand(command);
LinuxVersion version = command.getResults();
if (version != null) {
versions.add(version);
}
} catch (CommandException e) {
warn("Could not retrieve linux version", e);
}
}
if (versions.isEmpty()) {
error("Could not determine version of linux host %s", host.getLabel());
versions.add(new LinuxVersion(LinuxDistribution.UNKNOWN, ""));
}
return versions;
}
use of com.iwave.ext.command.CommandException in project coprhd-controller by CoprHD.
the class SSHCommandExecutor method executeCommand.
@Override
public CommandOutput executeCommand(Command command) throws CommandException {
try {
if (!isConnected()) {
connect();
}
ChannelExec channel = (ChannelExec) session.openChannel("exec");
try {
StreamConsumer stdout = new StreamConsumer(channel.getInputStream());
StreamConsumer stderr = new StreamConsumer(channel.getErrStream());
connect(command, channel);
waitForDone(channel);
stdout.close();
stderr.close();
int exitCode = channel.getExitStatus();
return new CommandOutput(stdout.toString(), stderr.toString(), exitCode);
} finally {
channel.disconnect();
}
} catch (JSchException | IOException | InterruptedException | SSHException e) {
log.error(String.format("SSH '%s' command failed: ", command.getCommand()), e);
throw new CommandException(e);
} finally {
if (isAutoDisconnect()) {
disconnect();
}
}
}
use of com.iwave.ext.command.CommandException in project coprhd-controller by CoprHD.
the class ShellCommandExecutor method sendCommand.
/**
* Sends a command to the remote host. This returns a CommandOutput, but the exit value is
* always 0 since it is being handled by the remote shell.
*
* @param command the command to send.
* @return the command output.
*/
protected CommandOutput sendCommand(String command) {
try {
send(command);
String matched = waitFor(promptPattern);
String stdout = getCurrentCommandOutput();
stdoutPos += StringUtils.length(stdout);
// Strip the command from the start of the output (ignoring any inserted line breaks)
stdout = IWaveStringUtils.removeStartIgnoringWhiteSpace(stdout, command);
if (StringUtils.startsWith(stdout, "\r\n")) {
stdout = StringUtils.removeStart(stdout, "\r\n");
} else if (StringUtils.startsWith(stdout, "\r") || StringUtils.startsWith(stdout, "\n")) {
stdout = StringUtils.substring(stdout, 1);
}
// Strip the prompt from the end of the output
stdout = StringUtils.removeEnd(stdout, matched);
return new CommandOutput(stdout, null, 0);
} catch (Exception e) {
CommandException ce = new CommandException(e);
ce.setOutput(tryGetCommandOutput());
throw ce;
}
}
use of com.iwave.ext.command.CommandException in project coprhd-controller by CoprHD.
the class AixVioDiscoveryAdapter method setNativeGuid.
@Override
protected void setNativeGuid(Host host) {
AixVioCLI cli = getCli(host);
try {
String macAddress = cli.getNetworkAdapterMacAddress(ENT0);
if (macAddress != null && !host.getNativeGuid().equalsIgnoreCase(macAddress)) {
checkDuplicateHost(host, macAddress);
info("Setting nativeGuid for " + host.getId() + " as " + macAddress);
host.setNativeGuid(macAddress);
save(host);
}
} catch (CommandException ex) {
LOG.warn("Failed to get MAC address of adapter during discovery");
}
}
Aggregations