use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class CassiniTerminalDevicePowerConfigExt method executeRpc.
/**
* Execute RPC request.
* @param session Netconf session
* @param message Netconf message in XML format
* @return XMLConfiguration object
*/
private XMLConfiguration executeRpc(NetconfSession session, String message) {
try {
CompletableFuture<String> fut = session.rpc(message);
String rpcReply = fut.get();
XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
xconf.setExpressionEngine(new XPathExpressionEngine());
return xconf;
} catch (NetconfException ne) {
log.error("Exception on Netconf protocol: {}.", ne);
} catch (InterruptedException ie) {
log.error("Interrupted Exception: {}.", ie);
} catch (ExecutionException ee) {
log.error("Concurrent Exception while executing Netconf operation: {}.", ee);
}
return null;
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class NetconfConfigSetter method setConfiguration.
@Override
public String setConfiguration(String filePath) {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
DeviceId deviceId = handler.data().deviceId();
Preconditions.checkNotNull(controller, "Netconf controller is null");
String request;
try {
request = new String(Files.readAllBytes(Paths.get(filePath)));
} catch (IOException e) {
log.error("Cannot read configuration file", e);
return UNABLE_TO_READ_FILE;
}
try {
return controller.getDevicesMap().get(deviceId).getSession().requestSync(request);
} catch (NetconfException e) {
log.error("Configuration could not be set", e);
}
return UNABLE_TO_SET_CONFIG;
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class AbstractOdtnTerminalDeviceDriver method configureDevice.
protected void configureDevice(DeviceId did, Document doc) {
NetconfController ctr = getService(NetconfController.class);
Optional.ofNullable(ctr.getNetconfDevice(did)).map(NetconfDevice::getSession).ifPresent(session -> {
try {
session.rpc(toCharSequence(doc).toString()).join();
} catch (NetconfException e) {
log.error("Exception thrown", e);
}
});
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class ControllerConfigJuniperImpl method requestCommand.
private boolean requestCommand(String command) {
NetconfSession session = getSession();
if (session == null) {
log.error("Cannot get session : {}", command);
return false;
}
try {
String reply = session.requestSync(command).trim();
log.debug(reply);
if (!isOK(reply)) {
log.error("discard changes {}", reply);
session.requestSync(buildDiscardChanges());
return false;
}
reply = session.requestSync(buildCommit()).trim();
log.debug("reply : {}", reply);
} catch (NetconfException e) {
log.debug(e.getMessage());
return false;
}
return true;
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class DeviceDiscoveryJuniperImpl method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
DeviceId devId = handler().data().deviceId();
NetconfSession session = lookupNetconfSession(devId);
String sysInfo;
String chassisMacAddresses;
try {
sysInfo = session.get(requestBuilder(REQ_SYS_INFO));
chassisMacAddresses = session.get(requestBuilder(REQ_MAC_ADD_INFO));
} catch (NetconfException e) {
log.warn("Failed to retrieve device details for {}", devId);
return null;
}
log.trace("Device {} system-information {}", devId, sysInfo);
DeviceDescription description = JuniperUtils.parseJuniperDescription(devId, loadXmlString(sysInfo), chassisMacAddresses);
log.debug("Device {} description {}", devId, description);
return description;
}
Aggregations