use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.
the class AdvaTerminalDeviceDiscovery method getNetconfSession.
/**
* Returns the NetconfSession with the device for which the method was called.
*
* @param deviceId device indetifier
*
* @return The netconf session or null
*/
private NetconfSession getNetconfSession(DeviceId deviceId) {
NetconfController controller = handler().get(NetconfController.class);
NetconfDevice ncdev = controller.getDevicesMap().get(deviceId);
if (ncdev == null) {
log.trace("No netconf device, returning null session");
return null;
}
return ncdev.getSession();
}
use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.
the class NokiaOpenConfigDeviceDiscovery method getNetconfSessionAndLogin.
/**
* Login to the device by providing the correct user and password in order to configure the device
* Returns the NetconfSession with the device for which the method was called.
*
* @param deviceId device indetifier
* @param userName
* @param passwd
* @return The netconf session or null
*/
private NetconfSession getNetconfSessionAndLogin(DeviceId deviceId, String userName, String passwd) {
NetconfController nc = handler().get(NetconfController.class);
NetconfDevice ndev = nc.getDevicesMap().get(deviceId);
if (ndev == null) {
log.debug("netconf device " + deviceId + " is not found, returning null session");
return null;
}
NetconfSession ns = ndev.getSession();
if (ns == null) {
log.error("discoverPorts called with null session for {}", deviceId);
return null;
}
try {
String reply = ns.requestSync(buildLoginRpc(userName, passwd));
if (reply.contains("<ok/>")) {
return ns;
} else {
log.debug(reply);
return null;
}
} catch (NetconfException e) {
log.error("can not login to device", e);
}
return ns;
}
use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.
the class NetconfGetCommand method doExecute.
@Override
protected void doExecute() {
DeviceId deviceId = DeviceId.deviceId(uri);
NetconfController controller = get(NetconfController.class);
checkNotNull(controller, "Netconf controller is null");
NetconfDevice device = controller.getDevicesMap().get(deviceId);
if (device == null) {
print("Netconf device object not found for %s", deviceId);
return;
}
NetconfSession session = device.getSession();
if (session == null) {
print("Netconf session not found for %s", deviceId);
return;
}
try {
CharSequence res = session.asyncGet().get(timeoutSec, TimeUnit.SECONDS);
print("%s", res);
} catch (NetconfException | InterruptedException | ExecutionException | TimeoutException e) {
log.error("Configuration could not be retrieved", e);
print("Error occurred retrieving configuration");
}
}
use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.
the class NetconfSubscriptionTestCommand method doExecute.
@Override
protected void doExecute() {
NetconfController controller = get(NetconfController.class);
DeviceId did = DeviceId.deviceId(uri);
NetconfDevice netconfDevice = controller.getNetconfDevice(did);
if (netconfDevice == null) {
print("%s not found or not connected to this node", did);
return;
}
if (!end) {
try {
netconfDevice.getSession().startSubscription();
} catch (NetconfException e) {
log.error("Exception thrown", e);
print("starting subscription failed (see log for details)");
}
} else {
try {
netconfDevice.getSession().endSubscription();
} catch (NetconfException e) {
log.error("Exception thrown", e);
print("ending subscription failed (see log for details)");
}
}
}
use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.
the class PolatisNetconfUtility method getNetconfSession.
/**
* Returns the NETCONF session of the device.
*
* @return session
*/
private static NetconfSession getNetconfSession(DriverHandler handler) {
NetconfController controller = checkNotNull(handler.get(NetconfController.class));
NetconfSession session = controller.getNetconfDevice(handler.data().deviceId()).getSession();
if (session == null) {
throw new IllegalStateException(new NetconfException("Failed to retrieve the netconf device."));
}
return session;
}
Aggregations