use of org.onosproject.net.key.UsernamePassword in project onos by opennetworkinglab.
the class NetconfControllerImpl method createDeviceInfo.
private NetconfDeviceInfo createDeviceInfo(DeviceId deviceId) throws NetconfException {
Device device = deviceService.getDevice(deviceId);
String ip, path = null;
int port;
if (device != null) {
ip = device.annotations().value("ipaddress");
port = Integer.parseInt(device.annotations().value("port"));
} else {
Triple<String, Integer, Optional<String>> info = extractIpPortPath(deviceId);
ip = info.getLeft();
port = info.getMiddle();
path = (info.getRight().isPresent() ? info.getRight().get() : null);
}
try {
DeviceKey deviceKey = deviceKeyService.getDeviceKey(DeviceKeyId.deviceKeyId(deviceId.toString()));
if (deviceKey.type() == DeviceKey.Type.USERNAME_PASSWORD) {
UsernamePassword usernamepasswd = deviceKey.asUsernamePassword();
return new NetconfDeviceInfo(usernamepasswd.username(), usernamepasswd.password(), IpAddress.valueOf(ip), port, path);
} else if (deviceKey.type() == DeviceKey.Type.SSL_KEY) {
String username = deviceKey.annotations().value(AnnotationKeys.USERNAME);
String password = deviceKey.annotations().value(AnnotationKeys.PASSWORD);
String sshkey = deviceKey.annotations().value(AnnotationKeys.SSHKEY);
return new NetconfDeviceInfo(username, password, IpAddress.valueOf(ip), port, path, sshkey);
} else {
log.error("Unknown device key for device {}", deviceId);
throw new NetconfException("Unknown device key for device " + deviceId);
}
} catch (NullPointerException e) {
log.error("No Device Key for device {}, {}", deviceId, e);
throw new NetconfException("No Device Key for device " + deviceId, e);
}
}
Aggregations