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());
}
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());
}
Aggregations