Search in sources :

Example 1 with HostAnnotationConfig

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

the class HostAnnotationOperator method combine.

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

Example 2 with HostAnnotationConfig

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

the class AnnotateHostCommand method doExecute.

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

Aggregations

HostAnnotationConfig (org.onosproject.net.config.basics.HostAnnotationConfig)2 Builder (org.onosproject.net.DefaultAnnotations.Builder)1 HostId (org.onosproject.net.HostId)1 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)1