use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class NetconfDeviceProvider method initiateConnection.
// initiating the SSh connection the a given device.
private void initiateConnection(DeviceId deviceId) {
if (!isReachable(deviceId)) {
log.warn("Can't connect to device {}", deviceId);
return;
}
try {
NetconfDevice deviceNetconf = controller.connectDevice(deviceId);
if (deviceNetconf != null) {
// storeDeviceKey(config.sshKey(), config.username(), config.password(), deviceId);
NetconfDeviceConfig config = cfgService.getConfig(deviceId, NetconfDeviceConfig.class);
// getting the device description
DeviceDescription deviceDescription = getDeviceDescription(deviceId, config);
// connecting device to ONOS
log.debug("Connected NETCONF device {}, on {}:{} {} with username {}", deviceId, config.ip(), config.port(), (config.path().isPresent() ? "/" + config.path().get() : ""), config.username());
providerService.deviceConnected(deviceId, deviceDescription);
} else {
mastershipService.relinquishMastership(deviceId);
deviceKeyAdminService.removeKey(DeviceKeyId.deviceKeyId(deviceId.toString()));
log.error("Can't connect to NETCONF device {}", deviceId);
}
} catch (Exception e) {
mastershipService.relinquishMastership(deviceId);
deviceKeyAdminService.removeKey(DeviceKeyId.deviceKeyId(deviceId.toString()));
throw new IllegalStateException(new NetconfException("Can't connect to NETCONF device " + deviceId, e));
}
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class NetconfAlarmProvider method deactivate.
@Deactivate
public void deactivate() {
providerRegistry.unregister(this);
idNotificationListenerMap.forEach((id, listener) -> {
NetconfDevice device = controller.getNetconfDevice(id);
if (device.isMasterSession()) {
try {
device.getSession().removeDeviceOutputListener(listener);
} catch (NetconfException e) {
log.error("RemoveDeviceOutputListener Error {}", e.getMessage());
}
}
});
controller.removeDeviceListener(deviceListener);
providerService = null;
log.info("NetconfAlarmProvider Stopped");
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class Ciena5162PortAdmin method setAdminState.
/**
* Sets the administrative state of the given port to the given value.
*
* @param number
* port number
* @param value
* state, true for enabled, false for disabled
* @return true if successfully set
*/
private CompletableFuture<Boolean> setAdminState(PortNumber number, Boolean value) {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
try {
Map<String, Object> templateContext = new HashMap<String, Object>();
templateContext.put("port-number", number.toLong());
templateContext.put("admin-state", value.toString());
Node req = (Node) TEMPLATE_MANAGER.doRequest(session, "port-admin-state", templateContext, "/", XPathConstants.NODE);
XPath xp = XPathFactory.newInstance().newXPath();
// If OK element exists then it worked.
Node ok = (Node) xp.evaluate("/rpc-reply/ok", req, XPathConstants.NODE);
return CompletableFuture.completedFuture(ok != null);
} catch (XPathExpressionException | NetconfException e) {
log.error("Unable to set port admin state for port {} to {}", number, handler().data().deviceId(), value, e);
}
return CompletableFuture.completedFuture(false);
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class Ciena5170PortAdmin method isEnabled.
@Override
public CompletableFuture<Boolean> isEnabled(PortNumber number) {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
try {
Map<String, Object> templateContext = new HashMap<String, Object>();
templateContext.put("port-number", number.toString());
Node port = TEMPLATE_MANAGER.doRequest(session, "logicalPort", templateContext);
XPath xp = XPathFactory.newInstance().newXPath();
return CompletableFuture.completedFuture(Boolean.valueOf(xp.evaluate("admin-status/text()", port)));
} catch (XPathExpressionException | NetconfException e) {
log.error("Unable to query port state for port {} from device {}", number, handler().data().deviceId(), e);
}
return CompletableFuture.completedFuture(false);
}
use of org.onosproject.netconf.NetconfException in project onos by opennetworkinglab.
the class FujitsuT100DeviceDescription method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
String reply;
try {
reply = session.get(requestBuilder());
} catch (NetconfException e) {
log.error("Failed to retrieve port details for device {}", handler().data().deviceId());
return ImmutableList.of();
}
List<PortDescription> descriptions = parseFujitsuT100Ports(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes())));
return ImmutableList.copyOf(descriptions);
}
Aggregations