Search in sources :

Example 1 with DeviceAnnotationConfig

use of org.onosproject.net.config.basics.DeviceAnnotationConfig in project onos by opennetworkinglab.

the class DeviceAnnotationOperator method combine.

@Override
public DeviceDescription combine(DeviceId deviceId, DeviceDescription descr, Optional<Config> prevConfig) {
    DeviceAnnotationConfig cfg = lookupConfig(deviceId);
    if (cfg == null) {
        return descr;
    }
    Map<String, String> annotations = cfg.annotations();
    Builder builder = DefaultAnnotations.builder();
    builder.putAll(descr.annotations());
    if (prevConfig.isPresent()) {
        DeviceAnnotationConfig prevDeviceAnnotationConfig = (DeviceAnnotationConfig) prevConfig.get();
        for (String key : prevDeviceAnnotationConfig.annotations().keySet()) {
            if (!annotations.containsKey(key)) {
                builder.remove(key);
            }
        }
    }
    builder.putAll(annotations);
    return DefaultDeviceDescription.copyReplacingAnnotation(descr, builder.build());
}
Also used : Builder(org.onosproject.net.DefaultAnnotations.Builder) DeviceAnnotationConfig(org.onosproject.net.config.basics.DeviceAnnotationConfig)

Example 2 with DeviceAnnotationConfig

use of org.onosproject.net.config.basics.DeviceAnnotationConfig in project onos by opennetworkinglab.

the class AnnotateDeviceCommand method doExecute.

@Override
protected void doExecute() {
    NetworkConfigService netcfgService = get(NetworkConfigService.class);
    DeviceId deviceId = DeviceId.deviceId(uri);
    if (key == null) {
        print("[ERROR] Annotation key not specified.");
        return;
    }
    DeviceAnnotationConfig cfg = netcfgService.getConfig(deviceId, DeviceAnnotationConfig.class);
    if (cfg == null) {
        cfg = new DeviceAnnotationConfig(deviceId);
    }
    if (removeCfg) {
        // remove config about entry
        cfg.annotation(key);
    } else {
        // add remove request config
        cfg.annotation(key, value);
    }
    netcfgService.applyConfig(deviceId, DeviceAnnotationConfig.class, cfg.node());
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) DeviceId(org.onosproject.net.DeviceId) DeviceAnnotationConfig(org.onosproject.net.config.basics.DeviceAnnotationConfig)

Aggregations

DeviceAnnotationConfig (org.onosproject.net.config.basics.DeviceAnnotationConfig)2 Builder (org.onosproject.net.DefaultAnnotations.Builder)1 DeviceId (org.onosproject.net.DeviceId)1 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)1