]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[65-libyang-simplify-update-models] Revamped list methods: only [gs]etDatabases needs...
authorFrancis Dupont <fdupont@isc.org>
Tue, 20 Nov 2018 10:06:23 +0000 (11:06 +0100)
committerFrancis Dupont <fdupont@isc.org>
Thu, 22 Nov 2018 22:13:47 +0000 (17:13 -0500)
12 files changed:
src/lib/yang/tests/translator_pd_pool_unittests.cc
src/lib/yang/tests/translator_pool_unittests.cc
src/lib/yang/tests/translator_subnet_unittests.cc
src/lib/yang/translator_config.cc
src/lib/yang/translator_database.h
src/lib/yang/translator_pd_pool.cc
src/lib/yang/translator_pd_pool.h
src/lib/yang/translator_pool.cc
src/lib/yang/translator_pool.h
src/lib/yang/translator_shared_network.cc
src/lib/yang/translator_subnet.cc
src/lib/yang/translator_subnet.h

index e8de18333aff85dbaa29f0b527e85df6beaf8cd2..55583296bcf578efd7eda0b6add2d0ab96e9f6cb 100644 (file)
@@ -47,7 +47,7 @@ TEST_F(TranslatorPdPoolsTest, getEmptyIetf) {
     // Get the pd-pool list and check if it is empty.
     const string& xpath =
         "/ietf-dhcpv6-server:server/server-config/network-ranges"
-        "/network-range[network-range-id='111']/pd-pools/pd-pool";
+        "/network-range[network-range-id='111']/pd-pools";
     ConstElementPtr pools;
     EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
     ASSERT_TRUE(pools);
@@ -61,8 +61,7 @@ TEST_F(TranslatorPdPoolsTest, getEmptyKea) {
     useModel(KEA_DHCP6_SERVER);
 
     // Get the pd-pool list and check if it is empty.
-    const string& xpath =
-        "/kea-dhcp6-server:config/subnet6[id='111']/pd-pool";
+    const string& xpath = "/kea-dhcp6-server:config/subnet6[id='111']";
     ConstElementPtr pools;
     EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
     ASSERT_TRUE(pools);
@@ -104,7 +103,7 @@ TEST_F(TranslatorPdPoolsTest, getIetf) {
 
     // Get the pd-pool list and check if the pd-pool is in it.
     ConstElementPtr pools;
-    EXPECT_NO_THROW(pools = t_obj_->getPdPools(subnet + "/pd-pools/pd-pool"));
+    EXPECT_NO_THROW(pools = t_obj_->getPdPools(subnet + "/pd-pools"));
     ASSERT_TRUE(pools);
     ASSERT_EQ(Element::list, pools->getType());
     ASSERT_EQ(1, pools->size());
@@ -144,7 +143,7 @@ TEST_F(TranslatorPdPoolsTest, getKea) {
 
     // Get the pd-pool list and check if the pd-pool is in it.
     ConstElementPtr pools;
-    EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath + "/pd-pool"));
+    EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
     ASSERT_TRUE(pools);
     ASSERT_EQ(Element::list, pools->getType());
     ASSERT_EQ(1, pools->size());
@@ -171,7 +170,7 @@ TEST_F(TranslatorPdPoolsTest, setEmptyIetf) {
 
     // Get it back.
     pools.reset();
-    EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath + "/pd-pool"));
+    EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
     ASSERT_TRUE(pools);
     ASSERT_EQ(Element::list, pools->getType());
     EXPECT_EQ(0, pools->size());
@@ -195,7 +194,7 @@ TEST_F(TranslatorPdPoolsTest, setEmptyKea) {
 
     // Get it back.
     pools.reset();
-    EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath + "/pd-pool"));
+    EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
     ASSERT_TRUE(pools);
     ASSERT_EQ(Element::list, pools->getType());
     EXPECT_EQ(0, pools->size());
@@ -225,7 +224,7 @@ TEST_F(TranslatorPdPoolsTest, setIetf) {
 
     // Get it back.
     pools.reset();
-    EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath + "/pd-pool"));
+    EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
     ASSERT_TRUE(pools);
     ASSERT_EQ(Element::list, pools->getType());
     ASSERT_EQ(1, pools->size());
@@ -285,7 +284,7 @@ TEST_F(TranslatorPdPoolsTest, setKea) {
 
     // Get it back.
     pools.reset();
-    EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath + "/pd-pool"));
+    EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
     ASSERT_TRUE(pools);
     ASSERT_EQ(Element::list, pools->getType());
     ASSERT_EQ(1, pools->size());
@@ -348,7 +347,7 @@ TEST_F(TranslatorPdPoolsTest, getListKea) {
 
     // Get the pools list.
     ConstElementPtr pools;
-    EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath + "/pd-pool"));
+    EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath));
     ASSERT_TRUE(pools);
 
     // Check that both of them are returned properly.
index af1c024373405c2bbe38f59ecfac68243ef2e45c..e18f2e11743439ac88911fc4baedd15f6885f5d6 100644 (file)
@@ -46,8 +46,7 @@ TEST_F(TranslatorPoolsTest, getEmptyIetf) {
 
     // Get the pool list and check if it is empty.
     const string& xpath = "/ietf-dhcpv6-server:server/server-config/"
-        "network-ranges/network-range[network-range-id='111']/"
-         "address-pools/address-pool";
+        "network-ranges/network-range[network-range-id='111']/address-pools";
     ConstElementPtr pools;
     EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
     ASSERT_TRUE(pools);
@@ -61,8 +60,7 @@ TEST_F(TranslatorPoolsTest, getEmptyKea) {
     useModel(KEA_DHCP6_SERVER);
 
     // Get the pool list and check if it is empty.
-    const string& xpath =
-        "/kea-dhcp6-server:config/subnet6[id='111']/pool";
+    const string& xpath = "/kea-dhcp6-server:config/subnet6[id='111']";
     ConstElementPtr pools;
     EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
     ASSERT_TRUE(pools);
@@ -96,7 +94,7 @@ TEST_F(TranslatorPoolsTest, getIetf) {
 
     // Get the pool list and check if the pool is in it.
     ConstElementPtr pools;
-    EXPECT_NO_THROW(pools = t_obj_->getPools(xpath + "/address-pool"));
+    EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
     ASSERT_TRUE(pools);
     ASSERT_EQ(Element::list, pools->getType());
     ASSERT_EQ(1, pools->size());
@@ -140,7 +138,7 @@ TEST_F(TranslatorPoolsTest, getKea) {
 
     // Get the pool list and check if the pool is in it.
     ConstElementPtr pools;
-    EXPECT_NO_THROW(pools = t_obj_->getPools(xpath + "/pool"));
+    EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
     ASSERT_TRUE(pools);
     ASSERT_EQ(Element::list, pools->getType());
     ASSERT_EQ(1, pools->size());
@@ -166,7 +164,7 @@ TEST_F(TranslatorPoolsTest, setEmptyIetf) {
 
     // Get it back.
     pools.reset();
-    EXPECT_NO_THROW(pools = t_obj_->getPools(xpath + "/address-pool"));
+    EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
     ASSERT_TRUE(pools);
     ASSERT_EQ(Element::list, pools->getType());
     EXPECT_EQ(0, pools->size());
@@ -190,7 +188,7 @@ TEST_F(TranslatorPoolsTest, setEmptyKea) {
 
     // Get it back.
     pools.reset();
-    EXPECT_NO_THROW(pools = t_obj_->getPools(xpath + "/pool"));
+    EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
     ASSERT_TRUE(pools);
     ASSERT_EQ(Element::list, pools->getType());
     EXPECT_EQ(0, pools->size());
@@ -218,7 +216,7 @@ TEST_F(TranslatorPoolsTest, setIetf) {
 
     // Get it back.
     pools.reset();
-    EXPECT_NO_THROW(pools = t_obj_->getPools(xpath + "/address-pool"));
+    EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
     ASSERT_TRUE(pools);
     ASSERT_EQ(Element::list, pools->getType());
     ASSERT_EQ(1, pools->size());
@@ -279,7 +277,7 @@ TEST_F(TranslatorPoolsTest, setKea) {
 
     // Get it back.
     pools.reset();
-    EXPECT_NO_THROW(pools = t_obj_->getPools(xpath + "/pool"));
+    EXPECT_NO_THROW(pools = t_obj_->getPools(xpath));
     ASSERT_TRUE(pools);
     ASSERT_EQ(Element::list, pools->getType());
     ASSERT_EQ(1, pools->size());
index b2ec4452a4c0179b5195d7cf9416e2b58cf1b164..f2d31fd1b4803a93819d290255454189cade0635 100644 (file)
@@ -45,8 +45,7 @@ TEST_F(TranslatorSubnetsTest, getEmptyIetf) {
 
     // Get the subnet list and check if it is empty.
     const string& xpath =
-        "/ietf-dhcpv6-server:server/server-config/"
-        "network-ranges/network-range";
+        "/ietf-dhcpv6-server:server/server-config/network-ranges";
     ConstElementPtr subnets;
     EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
     ASSERT_TRUE(subnets);
@@ -60,7 +59,7 @@ TEST_F(TranslatorSubnetsTest, getEmptyKea) {
     useModel(KEA_DHCP6_SERVER);
 
     // Get the subnet list and check if it is empty.
-    const string& xpath = "/kea-dhcp6-server:config/subnet6";
+    const string& xpath = "/kea-dhcp6-server:config";
     ConstElementPtr subnets;
     EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
     ASSERT_TRUE(subnets);
@@ -91,7 +90,7 @@ TEST_F(TranslatorSubnetsTest, getIetf) {
 
     // Get the subnet list and check if the subnet is in it.
     ConstElementPtr subnets;
-    EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath + "/network-range"));
+    EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
     ASSERT_TRUE(subnets);
     ASSERT_EQ(Element::list, subnets->getType());
     ASSERT_EQ(1, subnets->size());
@@ -121,7 +120,7 @@ TEST_F(TranslatorSubnetsTest, getKea) {
 
     // Get the subnet list and check if the subnet is in it.
     ConstElementPtr subnets;
-    EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath + "/subnet6"));
+    EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
     ASSERT_TRUE(subnets);
     ASSERT_EQ(Element::list, subnets->getType());
     ASSERT_EQ(1, subnets->size());
@@ -177,7 +176,7 @@ TEST_F(TranslatorSubnetsTest, getPoolsIetf) {
 
     // Get the subnet list and check if the subnet is in it.
     ConstElementPtr subnets;
-    EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath + "/network-range"));
+    EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
     ASSERT_TRUE(subnets);
     ASSERT_EQ(Element::list, subnets->getType());
     ASSERT_EQ(1, subnets->size());
@@ -233,7 +232,7 @@ TEST_F(TranslatorSubnetsTest, getPoolsKea) {
 
     // Get the subnet list and check if the subnet is in it.
     ConstElementPtr subnets;
-    EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath + "/subnet6"));
+    EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
     ASSERT_TRUE(subnets);
     ASSERT_EQ(Element::list, subnets->getType());
     ASSERT_EQ(1, subnets->size());
@@ -253,7 +252,7 @@ TEST_F(TranslatorSubnetsTest, setEmptyIetf) {
 
     // Get it back.
     subnets.reset();
-    EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath + "/network-range"));
+    EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
     ASSERT_TRUE(subnets);
     ASSERT_EQ(Element::list, subnets->getType());
     EXPECT_EQ(0, subnets->size());
@@ -270,7 +269,7 @@ TEST_F(TranslatorSubnetsTest, setEmptyKea) {
     useModel(KEA_DHCP4_SERVER);
 
     // Set empty list.
-    const string& xpath = "/kea-dhcp4-server:config/subnet4";
+    const string& xpath = "/kea-dhcp4-server:config";
     ElementPtr subnets = Element::createList();
     EXPECT_NO_THROW(t_obj_->setSubnets(xpath, subnets));
 
@@ -305,7 +304,7 @@ TEST_F(TranslatorSubnetsTest, setIetf) {
 
     // Get it back.
     subnets.reset();
-    EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath + "/network-range"));
+    EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
     ASSERT_TRUE(subnets);
     ASSERT_EQ(Element::list, subnets->getType());
     ASSERT_EQ(1, subnets->size());
@@ -318,7 +317,7 @@ TEST_F(TranslatorSubnetsTest, setKea) {
     useModel(KEA_DHCP4_SERVER);
 
     // Set one subnet.
-    const string& xpath = "/kea-dhcp4-server:config/subnet4";
+    const string& xpath = "/kea-dhcp4-server:config";
     ElementPtr subnets = Element::createList();
     ElementPtr subnet = Element::createMap();
     subnet->set("subnet", Element::create(string("10.0.1.0/24")));
@@ -367,7 +366,7 @@ TEST_F(TranslatorSubnetsTest, setTwoIetf) {
 
     // Get it back.
     subnets.reset();
-    EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath + "/network-range"));
+    EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath));
     ASSERT_TRUE(subnets);
     ASSERT_EQ(Element::list, subnets->getType());
     ASSERT_EQ(1, subnets->size());
@@ -424,7 +423,7 @@ TEST_F(TranslatorSubnetsTest, setTwoKea) {
     useModel(KEA_DHCP4_SERVER);
 
     // Set one subnet.
-    const string& xpath = "/kea-dhcp4-server:config/subnet4";
+    const string& xpath = "/kea-dhcp4-server:config";
     ElementPtr subnets = Element::createList();
     ElementPtr subnet = Element::createMap();
     subnet->set("subnet", Element::create(string("10.0.1.0/24")));
index 10976cc192fdde637258100459794292a18d6a1d..2ffc1b0331de345a80d5ebd7ec80c28440491f4b 100644 (file)
@@ -72,7 +72,7 @@ TranslatorConfig::getConfigIetf6() {
     result->set("Dhcp6", dhcp6);
     string xpath = "/" + model_ + ":server/server-config";
     ConstElementPtr ranges =
-        getSubnets(xpath + "/network-ranges/network-range");
+        getSubnets(xpath + "/network-ranges");
     if (ranges && !ranges->empty()) {
         dhcp6->set("subnet6", ranges);
     }
@@ -299,7 +299,7 @@ TranslatorConfig::getServerKeaDhcp4() {
     string xpath = "/kea-dhcp4-server:config";
     ElementPtr result = getServerKeaDhcpCommon(xpath);
     // Handle subnets.
-    ConstElementPtr subnets = getSubnets(xpath + "/subnet4");
+    ConstElementPtr subnets = getSubnets(xpath);
     if (subnets && !subnets->empty()) {
         result->set("subnet4", subnets);
     }
@@ -338,7 +338,7 @@ TranslatorConfig::getServerKeaDhcp6() {
     // Handle DHCPv6 specific global parameters.
     getParam(result, xpath, "preferred-lifetime");
     // Handle subnets.
-    ConstElementPtr subnets = getSubnets(xpath + "/subnet6");
+    ConstElementPtr subnets = getSubnets(xpath);
     if (subnets && !subnets->empty()) {
         result->set("subnet6", subnets);
     }
@@ -718,7 +718,7 @@ TranslatorConfig::setServerKeaDhcp4(ConstElementPtr elem) {
     setServerKeaDhcpCommon(xpath, elem);
     ConstElementPtr subnets = elem->get("subnet4");
     if (subnets) {
-        setSubnets(xpath + "/subnet4", subnets);
+        setSubnets(xpath, subnets);
     }
     ConstElementPtr if_config = elem->get("interfaces-config");
     if (if_config) {
@@ -786,7 +786,7 @@ TranslatorConfig::setServerKeaDhcp6(ConstElementPtr elem) {
     }
     ConstElementPtr subnets = elem->get("subnet6");
     if (subnets) {
-        setSubnets(xpath + "/subnet6", subnets);
+        setSubnets(xpath, subnets);
     }
     ConstElementPtr if_config = elem->get("interfaces-config");
     if (if_config) {
index 4ce40c71f94672430cd49eba19928ece928d4a95..228cbbb2a6fe8bd6318dde196f1ff2c542078a69 100644 (file)
@@ -176,7 +176,7 @@ public:
 
     /// @brief Get and translate database accesses from YANG to JSON.
     ///
-    /// @param xpath The xpath of databases.
+    /// @param xpath The xpath of databases including the list name.
     /// @return JSON representation of databases.
     /// @throw SysrepoError when sysrepo raises an error.
     isc::data::ConstElementPtr getDatabases(const std::string& xpath);
@@ -185,7 +185,7 @@ public:
     ///
     /// Null elem argument removes the database list.
     ///
-    /// @param xpath The xpath of databases.
+    /// @param xpath The xpath of databases including the list name.
     /// @param elem The JSON element.
     void setDatabases(const std::string& xpath,
                       isc::data::ConstElementPtr elem);
@@ -193,14 +193,14 @@ public:
 protected:
     /// @brief getDatabases JSON for kea-dhcp[46]-server models.
     ///
-    /// @param xpath The xpath of databases.
+    /// @param xpath The xpath of databases including the list name.
     /// @return JSON representation of  databases.
     /// @throw SysrepoError when sysrepo raises an error.
     isc::data::ElementPtr getDatabasesKea(const std::string& xpath);
 
     /// @brief setDatabases for kea-dhcp[46]-server models.
     ///
-    /// @param xpath The xpath of databases.
+    /// @param xpath The xpath of databases including the list name.
     /// @param elem The JSON element.
     /// @throw BadValue on database without tyoe,
     void setDatabasesKea(const std::string& xpath,
index 26250affca0a97758b8431ba8be301855b652fa1..081558be1f4b305462ef6d41abaa238a648e2bc6 100644 (file)
@@ -299,25 +299,35 @@ TranslatorPdPools::~TranslatorPdPools() {
 ElementPtr
 TranslatorPdPools::getPdPools(const string& xpath) {
     try {
-        ElementPtr result = Element::createList();
-        S_Iter_Value iter = getIter(xpath);
-        if (!iter) {
-            // Can't happen.
-            isc_throw(Unexpected, "getPdPools: can't get iterator: " << xpath);
+        if ((model_ == IETF_DHCPV6_SERVER) ||
+            (model_ == KEA_DHCP6_SERVER)) {
+            return (getPdPoolsCommon(xpath));
         }
-        for (;;) {
-            const string& pool = getNext(iter);
-            if (pool.empty()) {
-                break;
-            }
-            result->add(getPdPool(pool));
-        }
-        return (result);
     } catch (const sysrepo_exception& ex) {
         isc_throw(SysrepoError,
                   "sysrepo error getting pd-pools at '" << xpath
                   << "': " << ex.what());
     }
+    isc_throw(NotImplemented,
+              "getPdPools not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorPdPools::getPdPoolsCommon(const string& xpath) {
+    ElementPtr result = Element::createList();
+    S_Iter_Value iter = getIter(xpath + "/pd-pool");
+    if (!iter) {
+        // Can't happen.
+        isc_throw(Unexpected, "getPdPools: can't get iterator: " << xpath);
+    }
+    for (;;) {
+        const string& pool = getNext(iter);
+        if (pool.empty()) {
+            break;
+        }
+        result->add(getPdPool(pool));
+    }
+    return (result);
 }
 
 void
index 8435adc3e873f6c9151e7d3f88af15f2b9c8166a..fae6bbeda673b0e1eaf900ad42e7e5cac518a9be 100644 (file)
@@ -159,14 +159,14 @@ protected:
     void setPdPoolIetf6(const std::string& xpath,
                         isc::data::ConstElementPtr elem);
 
-    /// @brief getPdPool for kea-dhcp6.
+    /// @brief getPdPool for kea-dhcp6-server.
     ///
     /// @param xpath The xpath of the pd-pool.
     /// @return JSON representation of the pd-pool.
     /// @throw SysrepoError when sysrepo raises an error.
     isc::data::ElementPtr getPdPoolKea(const std::string& xpath);
 
-    /// @brief setPdPool for kea-dhcp6.
+    /// @brief setPdPool for kea-dhcp6-server.
     ///
     /// @param xpath The xpath of the pd-pool.
     /// @param elem The JSON element.
@@ -209,6 +209,12 @@ public:
     void setPdPools(const std::string& xpath, isc::data::ConstElementPtr elem);
 
 protected:
+    /// @brief getPdPools common part.
+    ///
+    /// @param xpath The xpath of the pd-pool list.
+    /// @throw SysrepoError when sysrepo raises an error.
+    isc::data::ElementPtr getPdPoolsCommon(const std::string& xpath);
+
     /// @brief setPdPools using pool-id.
     ///
     /// @param xpath The xpath of the pd-pool list.
index cdeec8bcd5f3395b26306d1b99d9598e41394be1..efcd2dcee23acd92cbfae28a545e87da8c234597 100644 (file)
@@ -279,25 +279,55 @@ TranslatorPools::~TranslatorPools() {
 ElementPtr
 TranslatorPools::getPools(const string& xpath) {
     try {
-        ElementPtr result = Element::createList();
-        S_Iter_Value iter = getIter(xpath);
-        if (!iter) {
-            // Can't happen.
-            isc_throw(Unexpected, "getPools can't get iterator: " << xpath);
-        }
-        for (;;) {
-            const string& pool = getNext(iter);
-            if (pool.empty()) {
-                break;
-            }
-            result->add(getPool(pool));
+        if (model_ == IETF_DHCPV6_SERVER) {
+            return (getPoolsIetf(xpath));
+        } else if ((model_ == KEA_DHCP4_SERVER) ||
+                   (model_ == KEA_DHCP6_SERVER)) {
+            return (getPoolsKea(xpath));
         }
-        return (result);
     } catch (const sysrepo_exception& ex) {
         isc_throw(SysrepoError,
                   "sysrepo error getting pools at '" << xpath
                   << "': " << ex.what());
     }
+    isc_throw(NotImplemented,
+              "getPools not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorPools::getPoolsIetf(const string& xpath) {
+    ElementPtr result = Element::createList();
+    S_Iter_Value iter = getIter(xpath + "/address-pool");
+    if (!iter) {
+        // Can't happen.
+        isc_throw(Unexpected, "getPoolsIetf can't get iterator: " << xpath);
+    }
+    for (;;) {
+        const string& pool = getNext(iter);
+        if (pool.empty()) {
+            break;
+        }
+        result->add(getPool(pool));
+    }
+    return (result);
+}
+
+ElementPtr
+TranslatorPools::getPoolsKea(const string& xpath) {
+    ElementPtr result = Element::createList();
+    S_Iter_Value iter = getIter(xpath + "/pool");
+    if (!iter) {
+        // Can't happen.
+        isc_throw(Unexpected, "getPoolsKea can't get iterator: " << xpath);
+    }
+    for (;;) {
+        const string& pool = getNext(iter);
+        if (pool.empty()) {
+            break;
+        }
+        result->add(getPool(pool));
+    }
+    return (result);
 }
 
 void
index af58671d0b962c9fb36f5c1f2997128e4f359ad0..fe4a89d0326bffbd41a97119cdcb50e818e90c30 100644 (file)
@@ -177,14 +177,14 @@ protected:
     void setPoolIetf6(const std::string& xpath,
                       isc::data::ConstElementPtr elem);
 
-    /// @brief getPool for kea-dhcp[46].
+    /// @brief getPool for kea-dhcp[46]-server.
     ///
     /// @param xpath The xpath of the pool.
     /// @return JSON representation of the pool.
     /// @throw BadValue on a pool without prefix and start or end address.
     isc::data::ElementPtr getPoolKea(const std::string& xpath);
 
-    /// @brief setPool for kea-dhcp[46].
+    /// @brief setPool for kea-dhcp[46]-server.
     ///
     /// @param xpath The xpath of the pool.
     /// @param elem The JSON element.
@@ -224,6 +224,16 @@ public:
     void setPools(const std::string& xpath, isc::data::ConstElementPtr elem);
 
 protected:
+    /// @brief getPools for ietf-dhcpv6-server.
+    ///
+    /// @param xpath The xpath of the pool list.
+    isc::data::ElementPtr getPoolsIetf(const std::string& xpath);
+
+    /// @brief getPools for kea-dhcp[46]-server.
+    ///
+    /// @param xpath The xpath of the pool list.
+    isc::data::ElementPtr getPoolsKea(const std::string& xpath);
+
     /// @brief setPools using pool-id.
     ///
     /// @param xpath The xpath of the pool list.
index fed72de3fcc2581f9a1f6e43772ab42aa8dfd1d1..73644f581d5f8e7e8b19b93cbbc7fc6dc55fc3a7 100644 (file)
@@ -65,7 +65,7 @@ TranslatorSharedNetwork::getSharedNetworkKea(const string& xpath,
         isc_throw(Unexpected, "getSharedNetworkKea requires name: " << xpath);
     }
     result->set("name", name);
-    ConstElementPtr subnets = getSubnets(xpath + "/" + subsel);
+    ConstElementPtr subnets = getSubnets(xpath);
     if (subnets && (subnets->size() > 0)) {
         result->set(subsel, subnets);
     }
@@ -179,7 +179,7 @@ TranslatorSharedNetwork::setSharedNetworkKea(const string& xpath,
     // Skip name which is the key.
     ConstElementPtr subnets = elem->get(subsel);
     if (subnets && (subnets->size() > 0)) {
-        setSubnets(xpath + "/" + subsel, subnets);
+        setSubnets(xpath, subnets);
     }
     if (subsel == "subnet6") {
         ConstElementPtr preferred = elem->get("preferred-lifetime");
index 9ff6c1a339956ce42f7930c2f5b18a11c75fee8a..315a6010d9f6f364527933adceacd2e8e116f9b7 100644 (file)
@@ -58,12 +58,12 @@ TranslatorSubnet::getSubnetIetf6(const string& xpath) {
     ElementPtr result = Element::createMap();
     /// @todo timers
     /// @todo: option-data
-    ConstElementPtr pools = getPools(xpath + "/address-pools/address-pool");
+    ConstElementPtr pools = getPools(xpath + "/address-pools");
     if (pools) {
         /// Set empty list too.
         result->set("pools", pools);
     }
-    pools = getPdPools(xpath + "/pd-pools/pd-pool");
+    pools = getPdPools(xpath + "/pd-pools");
     if (pools && (pools->size() > 0)) {
         result->set("pd-pools", pools);
     }
@@ -116,12 +116,12 @@ TranslatorSubnet::getSubnetKea(const string& xpath) {
     if (options && (options->size() > 0)) {
         result->set("option-data", options);
     }
-    ConstElementPtr pools = getPools(xpath + "/pool");
+    ConstElementPtr pools = getPools(xpath);
     if (pools && (pools->size() > 0)) {
         result->set("pools", pools);
     }
     if (model_ == KEA_DHCP6_SERVER) {
-        pools = getPdPools(xpath + "/pd-pool");
+        pools = getPdPools(xpath);
         if (pools && (pools->size() > 0)) {
             result->set("pd-pools", pools);
         }
@@ -408,25 +408,39 @@ TranslatorSubnets::~TranslatorSubnets() {
 ElementPtr
 TranslatorSubnets::getSubnets(const string& xpath) {
     try {
-        ElementPtr result = Element::createList();
-        S_Iter_Value iter = getIter(xpath);
-        if (!iter) {
-            /// Can't happen.
-            isc_throw(Unexpected, "getSubnets: can't get iterator: " << xpath);
-        }
-        for (;;) {
-            const string& subnet = getNext(iter);
-            if (subnet.empty()) {
-                break;
-            }
-            result->add(getSubnet(subnet));
+        if (model_ == IETF_DHCPV6_SERVER) {
+            return (getSubnetsCommon(xpath, "network-range"));
+        } else if (model_ == KEA_DHCP4_SERVER) {
+            return (getSubnetsCommon(xpath, "subnet4"));
+        } else if (model_ == KEA_DHCP6_SERVER) {
+            return (getSubnetsCommon(xpath, "subnet6"));
         }
-        return (result);
     } catch (const sysrepo_exception& ex) {
         isc_throw(SysrepoError,
                   "sysrepo error getting subnets at '" << xpath
                   << "': " << ex.what());
     }
+    isc_throw(NotImplemented,
+              "getSubnets not implemented for the model: " << model_);
+}
+
+ElementPtr
+TranslatorSubnets::getSubnetsCommon(const string& xpath,
+                                    const std::string& subsel) {
+    ElementPtr result = Element::createList();
+    S_Iter_Value iter = getIter(xpath + "/" + subsel);
+    if (!iter) {
+        /// Can't happen.
+        isc_throw(Unexpected, "getSubnets: can't get iterator: " << xpath);
+    }
+    for (;;) {
+        const string& subnet = getNext(iter);
+        if (subnet.empty()) {
+            break;
+        }
+        result->add(getSubnet(subnet));
+    }
+    return (result);
 }
 
 void
@@ -434,9 +448,10 @@ TranslatorSubnets::setSubnets(const string& xpath, ConstElementPtr elem) {
     try {
         if (model_ == IETF_DHCPV6_SERVER) {
             setSubnetsIetf6(xpath, elem);
-        } else if ((model_ == KEA_DHCP4_SERVER) ||
-                   (model_ == KEA_DHCP6_SERVER)) {
-            setSubnetsKea(xpath, elem);
+        } else if (model_ == KEA_DHCP4_SERVER) {
+            setSubnetsKea(xpath, elem, "subnet4");
+        } else if (model_ == KEA_DHCP6_SERVER) {
+            setSubnetsKea(xpath, elem, "subnet6");
         } else {
             isc_throw(NotImplemented,
                       "setSubnets not implemented for the model: " << model_);
@@ -464,14 +479,16 @@ TranslatorSubnets::setSubnetsIetf6(const string& xpath, ConstElementPtr elem) {
 }
 
 void
-TranslatorSubnets::setSubnetsKea(const string& xpath, ConstElementPtr elem) {
+TranslatorSubnets::setSubnetsKea(const string& xpath, ConstElementPtr elem,
+                                 const std::string& subsel) {
     for (size_t i = 0; i < elem->size(); ++i) {
         ConstElementPtr subnet = elem->get(i);
         if (!subnet->contains("id")) {
             isc_throw(BadValue, "subnet without id: " << subnet->str());
         }
         ostringstream prefix;
-        prefix << xpath << "[id='" << subnet->get("id")->intValue() << "']";
+        prefix << xpath << "/" << subsel << "[id='"
+               << subnet->get("id")->intValue() << "']";
         setSubnet(prefix.str(), subnet);
     }
 }
index 61b2dbf434769bab5a4f93af6902d755e7bf8780..7023bec5e5a81c196bb32b41be6c7af369d0355a 100644 (file)
@@ -84,7 +84,7 @@ namespace yang {
 ///  +--rw host-reservations     host-reservation* [cli-id]
 /// @endcode
 ///
-/// YANG syntax for kea-dhcp[46] is with id as the key:
+/// YANG syntax for kea-dhcp[46]-server is with id as the key:
 /// @code
 ///  +--rw valid-lifetime?           uint32
 ///  +--rw renew-timer?              uint32
@@ -278,13 +278,13 @@ protected:
     void setSubnetIetf6(const std::string& xpath,
                         isc::data::ConstElementPtr elem);
 
-    /// @brief getSubnet for kea-dhcp[46].
+    /// @brief getSubnet for kea-dhcp[46]-server.
     ///
     /// @param xpath The xpath of the subnet.
     /// @return JSON representation of the subnet.
     isc::data::ElementPtr getSubnetKea(const std::string& xpath);
 
-    /// @brief setSubnet for kea-dhcp[46].
+    /// @brief setSubnet for kea-dhcp[46]-server.
     ///
     /// @param xpath The xpath of the subnet.
     /// @param elem The JSON element.
@@ -326,6 +326,13 @@ public:
     void setSubnets(const std::string& xpath, isc::data::ConstElementPtr elem);
 
 protected:
+    /// @brief getSubnets common part.
+    ///
+    /// @param xpath The xpath of the subnet list.
+    /// @param subsel The subnet list name.
+    isc::data::ElementPtr getSubnetsCommon(const std::string& xpath,
+                                           const std::string& subsel);
+
     /// @brief setSubnets for ietf-dhcpv6-server.
     ///
     /// @param xpath The xpath of the subnet list.
@@ -333,12 +340,14 @@ protected:
     void setSubnetsIetf6(const std::string& xpath,
                          isc::data::ConstElementPtr elem);
 
-    /// @brief setSubnets for kea-dhcp[46].
+    /// @brief setSubnets for kea-dhcp[46]-server.
     ///
     /// @param xpath The xpath of the subnet list.
     /// @param elem The JSON element.
+    /// @param subsel The subnet list name.
     void setSubnetsKea(const std::string& xpath,
-                       isc::data::ConstElementPtr elem);
+                       isc::data::ConstElementPtr elem,
+                       const std::string& subsel);
 };
 
 }; // end of namespace isc::yang