Search in sources :

Example 1 with UsernamePassword

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);
    }
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) Optional(java.util.Optional) NetconfDeviceInfo(org.onosproject.netconf.NetconfDeviceInfo) Device(org.onosproject.net.Device) NetconfDevice(org.onosproject.netconf.NetconfDevice) DeviceKey(org.onosproject.net.key.DeviceKey) UsernamePassword(org.onosproject.net.key.UsernamePassword)

Aggregations

Optional (java.util.Optional)1 Device (org.onosproject.net.Device)1 DeviceKey (org.onosproject.net.key.DeviceKey)1 UsernamePassword (org.onosproject.net.key.UsernamePassword)1 NetconfDevice (org.onosproject.netconf.NetconfDevice)1 NetconfDeviceInfo (org.onosproject.netconf.NetconfDeviceInfo)1 NetconfException (org.onosproject.netconf.NetconfException)1