Move hostconfig functionality to Neutron Northbound 85/49785/5
authorRitu Sood <ritu.sood@intel.com>
Fri, 23 Dec 2016 03:34:08 +0000 (19:34 -0800)
committerRitu Sood <ritu.sood@intel.com>
Thu, 9 Feb 2017 02:28:54 +0000 (18:28 -0800)
This patch moves hostconfig functionality from Netvirt
to NN project. The code is organized to support multiple
southbound implementations. This patch includes
support for hostconfig for OVS.

Change-Id: If428cd3e0c1c466342888f46f17a1916176f0fc6
Signed-off-by: Ritu Sood <ritu.sood@intel.com>
features/production/pom.xml
features/production/src/main/features/features.xml
neutron-hostconfig/ovs/pom.xml [new file with mode: 0644]
neutron-hostconfig/ovs/src/main/java/org/opendaylight/neutron/hostconfig/ovs/NeutronHostconfigOvsListener.java [new file with mode: 0644]
neutron-hostconfig/ovs/src/main/resources/org/opendaylight/blueprint/neutron-hostconfig-ovs.xml [new file with mode: 0644]
neutron-hostconfig/pom.xml [new file with mode: 0644]
neutron-hostconfig/utils/pom.xml [new file with mode: 0644]
neutron-hostconfig/utils/src/main/java/org/opendaylight/neutron/hostconfig/utils/NeutronHostconfigUtils.java [new file with mode: 0644]
pom.xml

index cc523c49cc1e81135aca57129f616e05988eee77..77cac88262232c012c7c755a874146d6ed8ae118 100644 (file)
@@ -17,6 +17,7 @@
       <controller.mdsal.version>1.5.0-SNAPSHOT</controller.mdsal.version>
       <mdsal.model.version>0.10.0-SNAPSHOT</mdsal.model.version>
       <restconf.version>1.5.0-SNAPSHOT</restconf.version>
+      <ovsdb.version>1.4.0-SNAPSHOT</ovsdb.version>
   </properties>
   <dependencyManagement>
     <dependencies>
       <artifactId>neutron-logger</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.ovsdb</groupId>
+      <artifactId>southbound-features</artifactId>
+      <version>${ovsdb.version}</version>
+      <classifier>features</classifier>
+      <type>xml</type>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.ovsdb</groupId>
+      <artifactId>utils.mdsal-utils</artifactId>
+      <version>${ovsdb.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>neutron-hostconfig-utils</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>neutron-hostconfig-ovs</artifactId>
+      <version>${project.version}</version>
+    </dependency>
   </dependencies>
   <scm>
     <connection>scm:git:ssh://git.opendaylight.org:29418/neutron.git</connection>
index bf5b81ca16b563aeb444477f7e60229f5650af9a..b5a171e3c66ca01da202c8dffb1aee53d89a8328 100644 (file)
@@ -7,6 +7,7 @@
    <repository>mvn:org.opendaylight.yangtools/features-yangtools/{{VERSION}}/xml/features</repository>
    <repository>mvn:org.opendaylight.mdsal.model/features-mdsal-model/{{VERSION}}/xml/features</repository>
    <repository>mvn:org.opendaylight.controller/features-mdsal/{{VERSION}}/xml/features</repository>
+   <repository>mvn:org.opendaylight.ovsdb/southbound-features/{{VERSION}}/xml/features</repository>
    <repository>mvn:org.opendaylight.netconf/features-restconf/{{VERSION}}/xml/features</repository>
    <feature name='odl-neutron-service' version='${project.version}' description="OpenDaylight :: Neutron :: API">
     <feature version='${project.version}'>odl-neutron-spi</feature>
     <bundle>mvn:org.opendaylight.neutron/neutron-logger/{{VERSION}}</bundle>
     <bundle>mvn:org.osgi/org.osgi.core/{{VERSION}}</bundle>
   </feature>
+  <feature name='odl-neutron-hostconfig-ovs' version='${project.version}' description="OpenDaylight :: Neutron :: HostconfigOvs">
+    <feature version='${controller.mdsal.version}'>odl-mdsal-broker</feature>
+    <feature version="${ovsdb.version}">odl-ovsdb-southbound-api</feature>
+    <bundle>mvn:org.opendaylight.neutron/model/{{VERSION}}</bundle>
+    <bundle>mvn:org.opendaylight.ovsdb/utils.mdsal-utils/{{VERSION}}</bundle>
+    <bundle>mvn:org.opendaylight.ovsdb/utils.southbound-utils/{{VERSION}}</bundle>
+    <bundle>mvn:org.opendaylight.neutron/neutron-hostconfig-utils/{{VERSION}}</bundle>
+    <bundle>mvn:org.opendaylight.neutron/neutron-hostconfig-ovs/{{VERSION}}</bundle>
+    <bundle>mvn:org.osgi/org.osgi.core/{{VERSION}}</bundle>
+  </feature>
 </features>
diff --git a/neutron-hostconfig/ovs/pom.xml b/neutron-hostconfig/ovs/pom.xml
new file mode 100644 (file)
index 0000000..c8ae816
--- /dev/null
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.opendaylight.controller</groupId>
+    <artifactId>config-parent</artifactId>
+    <version>0.6.0-SNAPSHOT</version>
+    <relativePath/>
+  </parent>
+
+  <groupId>org.opendaylight.neutron</groupId>
+  <artifactId>neutron-hostconfig-ovs</artifactId>
+  <version>0.8.0-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+  <properties>
+    <checkstyle.location>${project.parent.basedir}/src/main/resources</checkstyle.location>
+  </properties>
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.opendaylight.mdsal.model</groupId>
+        <artifactId>mdsal-model-artifacts</artifactId>
+        <version>0.10.0-SNAPSHOT</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+  <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.neutron</groupId>
+      <artifactId>neutron-spi</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.neutron</groupId>
+      <artifactId>model</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.ovsdb</groupId>
+      <artifactId>utils.mdsal-utils</artifactId>
+      <version>1.4.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.ovsdb</groupId>
+      <artifactId>utils.southbound-utils</artifactId>
+      <version>1.4.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.neutron</groupId>
+      <artifactId>neutron-hostconfig-utils</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>config-api</artifactId>
+      <version>0.6.0-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <inherited>true</inherited>
+        <configuration>
+          <compilerArgs>
+            <arg>-Xlint:unchecked</arg>
+            <arg>-Xlint:deprecation</arg>
+          </compilerArgs>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <scm>
+    <connection>scm:git:ssh://git.opendaylight.org:29418/neutron.git</connection>
+    <developerConnection>scm:git:ssh://git.opendaylight.org:29418/neutron.git</developerConnection>
+    <tag>HEAD</tag>
+    <url>https://wiki.opendaylight.org/view/NeutronNorthBound:Main</url>
+  </scm>
+  <distributionManagement>
+    <!-- Site deployment -->
+    <site>
+      <id>opendaylight-site</id>
+      <url>${nexus.site.url}/${project.artifactId}/</url>
+    </site>
+  </distributionManagement>
+
+  <!--
+      Maven Site Configuration
+
+      The following configuration is necessary for maven-site-plugin to
+      correctly identify the correct deployment path for OpenDaylight Maven
+      sites.
+  -->
+  <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
+</project>
diff --git a/neutron-hostconfig/ovs/src/main/java/org/opendaylight/neutron/hostconfig/ovs/NeutronHostconfigOvsListener.java b/neutron-hostconfig/ovs/src/main/java/org/opendaylight/neutron/hostconfig/ovs/NeutronHostconfigOvsListener.java
new file mode 100644 (file)
index 0000000..c09e88b
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2017 Intel Corporation.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.neutron.hostconfig.ovs;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
+
+import java.util.Collection;
+import java.util.Map;
+import javax.annotation.Nonnull;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.neutron.hostconfig.utils.NeutronHostconfigUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchExternalIds;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NeutronHostconfigOvsListener implements ClusteredDataTreeChangeListener<Node>, AutoCloseable {
+    private static final Logger LOG = LoggerFactory.getLogger(NeutronHostconfigOvsListener.class);
+    private final DataBroker dataBroker;
+    private final SouthboundUtils southboundUtils;
+    private final NeutronHostconfigUtils neutronHostconfig;
+    private ListenerRegistration<DataTreeChangeListener<Node>> listenerRegistration;
+    private static final String OS_HOST_CONFIG_HOST_ID_KEY = "odl_os_hostconfig_hostid";
+    private static final String OS_HOST_CONFIG_CONFIG_KEY_PREFIX = "odl_os_hostconfig_config_odl_";
+    private static int HOST_TYPE_STR_LEN = 8;
+
+    public NeutronHostconfigOvsListener(final DataBroker dataBroker) {
+        this.dataBroker = dataBroker;
+        MdsalUtils mdsalUtils = new MdsalUtils(dataBroker);
+        this.southboundUtils = new SouthboundUtils(mdsalUtils);
+        this.neutronHostconfig = new NeutronHostconfigUtils(dataBroker);
+    }
+
+    private void processChanges(Collection<DataTreeModification<Node>> changes) {
+        LOG.info("onDataTreeChanged: Received Data Tree Changed ...", changes);
+        for (DataTreeModification<Node> change : changes) {
+            final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
+            final DataObjectModification<Node> mod = change.getRootNode();
+            LOG.info("onDataTreeChanged: Received Data Tree Changed Update of Type={} for Key={}",
+                    mod.getModificationType(), key);
+            switch (mod.getModificationType()) {
+                case DELETE:
+                    updateHostConfig(mod.getDataAfter(), NeutronHostconfigUtils.Action.DELETE);
+                    break;
+                case SUBTREE_MODIFIED:
+                    updateHostConfig(mod.getDataAfter(), NeutronHostconfigUtils.Action.UPDATE);
+                    break;
+                case WRITE:
+                    updateHostConfig(mod.getDataAfter(), NeutronHostconfigUtils.Action.ADD);
+                    break;
+                default:
+                    LOG.error("onDataTreeChanged: Invalid modification type={}",
+                            mod.getModificationType());
+                    break;
+            }
+        }
+    }
+
+    @Override
+    public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Node>> changes) {
+        Preconditions.checkNotNull(changes, "Changes may not be null!");
+        processChanges(changes);
+    }
+
+    private InstanceIdentifier<Node> createNodeIdentifier() {
+        return InstanceIdentifier
+                .create(NetworkTopology.class)
+                .child(Topology.class, new TopologyKey(SouthboundUtils.OVSDB_TOPOLOGY_ID))
+                .child(Node.class);
+    }
+
+    public void init() {
+        LOG.info("{} start", getClass().getSimpleName());
+        DataTreeIdentifier<Node> dataTreeIdentifier =
+                new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, createNodeIdentifier());
+        LOG.info("Neutron Hostconfig DataChange listener registration {}", dataTreeIdentifier);
+        listenerRegistration = dataBroker.registerDataTreeChangeListener(dataTreeIdentifier, this);
+    }
+
+    public void close() throws Exception {
+        if (listenerRegistration != null) {
+            listenerRegistration.close();
+            LOG.trace("HostConfig listener Closed");
+        }
+    }
+
+    private void updateHostConfig(Node node, NeutronHostconfigUtils.Action action) {
+        String hostId = getExternalId(node, OS_HOST_CONFIG_HOST_ID_KEY);
+        if (hostId == null) {
+            return;
+        }
+        for (Map.Entry<String, String> entry : extractHostConfig(node).entrySet()) {
+            neutronHostconfig.updateMdsal(neutronHostconfig.buildHostConfigInfo(hostId, entry.getKey(),
+                    entry.getValue()), action);
+        }
+    }
+
+    private Map<String, String> extractHostConfig(Node node) {
+        Map<String, String> config = Maps.newHashMap();
+        OvsdbNodeAugmentation ovsdbNode = getOvsdbNodeAugmentation(node);
+        if (ovsdbNode != null && ovsdbNode.getOpenvswitchExternalIds() != null) {
+            for (OpenvswitchExternalIds openvswitchExternalIds : ovsdbNode.getOpenvswitchExternalIds()) {
+                if (openvswitchExternalIds.getExternalIdKey().startsWith(OS_HOST_CONFIG_CONFIG_KEY_PREFIX)) {
+                    // Extract the host type. Max 8 characters after
+                    // suffix OS_HOST_CONFIG_CONFIG_KEY_PREFIX.length()
+                    String hostType = openvswitchExternalIds.getExternalIdKey().substring(
+                            OS_HOST_CONFIG_CONFIG_KEY_PREFIX.length());
+                    if (null != hostType && hostType.length() > 0) {
+                        if (hostType.length() > HOST_TYPE_STR_LEN) {
+                            hostType = hostType.substring(0, HOST_TYPE_STR_LEN);
+                        }
+                        hostType = "ODL " + hostType.toUpperCase();
+                        if (null != openvswitchExternalIds.getExternalIdValue()) {
+                            config.put(hostType, openvswitchExternalIds.getExternalIdValue());
+                        }
+                    }
+                }
+            }
+        }
+        return config;
+    }
+
+    private String getExternalId(Node node, String key) {
+        OvsdbNodeAugmentation ovsdbNode = getOvsdbNodeAugmentation(node);
+        if (ovsdbNode != null && ovsdbNode.getOpenvswitchExternalIds() != null) {
+            for (OpenvswitchExternalIds openvswitchExternalIds : ovsdbNode.getOpenvswitchExternalIds()) {
+                if (openvswitchExternalIds.getExternalIdKey().equals(key)) {
+                    return openvswitchExternalIds.getExternalIdValue();
+                }
+            }
+        }
+        return null;
+    }
+
+    private OvsdbNodeAugmentation getOvsdbNodeAugmentation(Node node) {
+        OvsdbNodeAugmentation ovsdbNode = southboundUtils.extractOvsdbNode(node);
+        if (ovsdbNode == null) {
+            Node nodeFromReadOvsdbNode = southboundUtils.readOvsdbNode(node);
+            if (nodeFromReadOvsdbNode != null) {
+                ovsdbNode = southboundUtils.extractOvsdbNode(nodeFromReadOvsdbNode);
+            }
+        }
+        return ovsdbNode;
+    }
+}
diff --git a/neutron-hostconfig/ovs/src/main/resources/org/opendaylight/blueprint/neutron-hostconfig-ovs.xml b/neutron-hostconfig/ovs/src/main/resources/org/opendaylight/blueprint/neutron-hostconfig-ovs.xml
new file mode 100644 (file)
index 0000000..71f4feb
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+    xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+    odl:use-default-for-reference-types="true">
+
+  <reference id="dataBroker"
+      interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
+      odl:type="default" />
+
+  <bean id="neutronHostconfigOvs"
+     class="org.opendaylight.neutron.hostconfig.ovs.NeutronHostconfigOvsListener"
+     init-method="init"
+     destroy-method="close">
+    <argument ref="dataBroker"/>
+  </bean>
+
+</blueprint>
diff --git a/neutron-hostconfig/pom.xml b/neutron-hostconfig/pom.xml
new file mode 100644 (file)
index 0000000..c1f5009
--- /dev/null
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.opendaylight.controller</groupId>
+    <artifactId>config-parent</artifactId>
+    <version>0.6.0-SNAPSHOT</version>
+    <relativePath/>
+  </parent>
+
+  <groupId>org.opendaylight.neutron</groupId>
+  <artifactId>neutron-hostconfig</artifactId>
+  <version>0.8.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+  <modules>
+    <module>utils</module>
+    <module>ovs</module>
+  </modules>
+  <!-- DO NOT install or deploy the repo root pom as it's only needed to initiate a build -->
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-deploy-plugin</artifactId>
+        <configuration>
+          <skip>true</skip>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-install-plugin</artifactId>
+        <configuration>
+          <skip>true</skip>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <!--
+      Maven Site Configuration
+      The following configuration is necessary for maven-site-plugin to
+      correctly identify the correct deployment path for OpenDaylight Maven
+      sites.
+  -->
+  <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
+
+  <distributionManagement>
+    <site>
+      <id>opendaylight-site</id>
+      <url>${nexus.site.url}/${project.artifactId}/</url>
+    </site>
+  </distributionManagement>
+</project>
+
diff --git a/neutron-hostconfig/utils/pom.xml b/neutron-hostconfig/utils/pom.xml
new file mode 100644 (file)
index 0000000..013d4ce
--- /dev/null
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.opendaylight.controller</groupId>
+    <artifactId>config-parent</artifactId>
+    <version>0.6.0-SNAPSHOT</version>
+    <relativePath/>
+  </parent>
+
+  <groupId>org.opendaylight.neutron</groupId>
+  <artifactId>neutron-hostconfig-utils</artifactId>
+  <version>0.8.0-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+  <properties>
+    <checkstyle.location>${project.parent.basedir}/src/main/resources</checkstyle.location>
+  </properties>
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.opendaylight.mdsal.model</groupId>
+        <artifactId>mdsal-model-artifacts</artifactId>
+        <version>0.10.0-SNAPSHOT</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+  <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.neutron</groupId>
+      <artifactId>model</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>config-api</artifactId>
+      <version>0.6.0-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <inherited>true</inherited>
+        <configuration>
+          <compilerArgs>
+            <arg>-Xlint:unchecked</arg>
+            <arg>-Xlint:deprecation</arg>
+          </compilerArgs>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <scm>
+    <connection>scm:git:ssh://git.opendaylight.org:29418/neutron.git</connection>
+    <developerConnection>scm:git:ssh://git.opendaylight.org:29418/neutron.git</developerConnection>
+    <tag>HEAD</tag>
+    <url>https://wiki.opendaylight.org/view/NeutronNorthBound:Main</url>
+  </scm>
+  <distributionManagement>
+    <!-- Site deployment -->
+    <site>
+      <id>opendaylight-site</id>
+      <url>${nexus.site.url}/${project.artifactId}/</url>
+    </site>
+  </distributionManagement>
+
+  <!--
+      Maven Site Configuration
+
+      The following configuration is necessary for maven-site-plugin to
+      correctly identify the correct deployment path for OpenDaylight Maven
+      sites.
+  -->
+  <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
+</project>
+
diff --git a/neutron-hostconfig/utils/src/main/java/org/opendaylight/neutron/hostconfig/utils/NeutronHostconfigUtils.java b/neutron-hostconfig/utils/src/main/java/org/opendaylight/neutron/hostconfig/utils/NeutronHostconfigUtils.java
new file mode 100644 (file)
index 0000000..44cee4e
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2017 Intel Corporation and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.neutron.hostconfig.utils;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.Hostconfigs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.Hostconfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.HostconfigBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NeutronHostconfigUtils {
+    private static final Logger LOG = LoggerFactory.getLogger(NeutronHostconfigUtils.class);
+    private final DataBroker dataBroker;
+
+    public enum Action {
+        ADD,
+        UPDATE,
+        DELETE
+    }
+
+    public NeutronHostconfigUtils(final DataBroker dataBroker) {
+        this.dataBroker = dataBroker;
+    }
+
+    public void updateMdsal(Hostconfig hostConfig, Action action) {
+        InstanceIdentifier<Hostconfig> hostConfigId;
+        if (hostConfig == null) {
+            return;
+        }
+        try {
+            switch (action) {
+                case ADD:
+                case UPDATE:
+                    final WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
+                    hostConfigId = createInstanceIdentifier(hostConfig);
+                    writeTx.put(LogicalDatastoreType.OPERATIONAL, hostConfigId, hostConfig, true);
+                    writeTx.submit().get();
+                    break;
+                case DELETE:
+                    final WriteTransaction delTx = dataBroker.newWriteOnlyTransaction();
+                    hostConfigId = createInstanceIdentifier(hostConfig);
+                    delTx.delete(LogicalDatastoreType.OPERATIONAL, hostConfigId);
+                    delTx.submit().get();
+                    break;
+                default:
+                    break;
+            }
+        } catch (Exception e) {
+            LOG.warn("Hostconfig transaction commit failed to DS.", e);
+        }
+    }
+
+    public Hostconfig buildHostConfigInfo(String hostId, String hostType, String hostConfig) {
+        HostconfigBuilder hostconfigBuilder = new HostconfigBuilder();
+        hostconfigBuilder.setHostId(hostId);
+        hostconfigBuilder.setHostType(hostType);
+        hostconfigBuilder.setConfig(hostConfig);
+        return hostconfigBuilder.build();
+    }
+
+    private InstanceIdentifier<Hostconfig> createInstanceIdentifier(Hostconfig hostconfig) {
+        return InstanceIdentifier.create(Neutron.class).child(Hostconfigs.class)
+                .child(Hostconfig.class, hostconfig.getKey());
+    }
+}
diff --git a/pom.xml b/pom.xml
index 4d6f51e5dbae1798967f8e17421821283bb58d61..e27d00897c9cc460cfc328f6603574b67c9d59da 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -99,6 +99,7 @@
     <module>karaf</module>
     <module>integration/test</module>
     <module>model</module>
+    <module>neutron-hostconfig</module>
   </modules>
   <build>
     <plugins>