Unify item creation/deletion in datastore access

All of our implementations are using the same implementation; all of the
smartness is actually in sysrepo or in libyang. As a bonus, this should
make it possible to remove regular leafs as well (backend-wise at
least).

Change-Id: I177cd233b4b699f66475eae735a659b7c8577534
diff --git a/src/datastore_access.hpp b/src/datastore_access.hpp
index 05c1296..0856d41 100644
--- a/src/datastore_access.hpp
+++ b/src/datastore_access.hpp
@@ -46,12 +46,8 @@
     virtual ~DatastoreAccess() = 0;
     virtual Tree getItems(const std::string& path) = 0;
     virtual void setLeaf(const std::string& path, leaf_data_ value) = 0;
-    virtual void createPresenceContainer(const std::string& path) = 0;
-    virtual void deletePresenceContainer(const std::string& path) = 0;
-    virtual void createListInstance(const std::string& path) = 0;
-    virtual void deleteListInstance(const std::string& path) = 0;
-    virtual void createLeafListInstance(const std::string& path) = 0;
-    virtual void deleteLeafListInstance(const std::string& path) = 0;
+    virtual void createItem(const std::string& path) = 0;
+    virtual void deleteItem(const std::string& path) = 0;
     virtual void moveItem(const std::string& path, std::variant<yang::move::Absolute, yang::move::Relative> move) = 0;
     virtual Tree executeRpc(const std::string& path, const Tree& input) = 0;
 
diff --git a/src/interpreter.cpp b/src/interpreter.cpp
index 3543e93..8ee2b55 100644
--- a/src/interpreter.cpp
+++ b/src/interpreter.cpp
@@ -87,22 +87,12 @@
 
 void Interpreter::operator()(const create_& create) const
 {
-    if (std::holds_alternative<listElement_>(create.m_path.m_nodes.back().m_suffix))
-        m_datastore.createListInstance(pathToString(toCanonicalPath(create.m_path)));
-    else if (std::holds_alternative<leafListElement_>(create.m_path.m_nodes.back().m_suffix))
-        m_datastore.createLeafListInstance(pathToString(toCanonicalPath(create.m_path)));
-    else
-        m_datastore.createPresenceContainer(pathToString(toCanonicalPath(create.m_path)));
+    m_datastore.createItem(pathToString(toCanonicalPath(create.m_path)));
 }
 
 void Interpreter::operator()(const delete_& delet) const
 {
-    if (std::holds_alternative<container_>(delet.m_path.m_nodes.back().m_suffix))
-        m_datastore.deletePresenceContainer(pathToString(toCanonicalPath(delet.m_path)));
-    else if (std::holds_alternative<leafListElement_>(delet.m_path.m_nodes.back().m_suffix))
-        m_datastore.deleteLeafListInstance(pathToString(toCanonicalPath(delet.m_path)));
-    else
-        m_datastore.deleteListInstance(pathToString(toCanonicalPath(delet.m_path)));
+    m_datastore.deleteItem(pathToString(toCanonicalPath(delet.m_path)));
 }
 
 void Interpreter::operator()(const ls_& ls) const
diff --git a/src/netconf_access.cpp b/src/netconf_access.cpp
index 15b79a8..a7cd6b4 100644
--- a/src/netconf_access.cpp
+++ b/src/netconf_access.cpp
@@ -65,13 +65,13 @@
     doEditFromDataNode(node);
 }
 
-void NetconfAccess::createPresenceContainer(const std::string& path)
+void NetconfAccess::createItem(const std::string& path)
 {
     auto node = m_schema->dataNodeFromPath(path);
     doEditFromDataNode(node);
 }
 
-void NetconfAccess::deletePresenceContainer(const std::string& path)
+void NetconfAccess::deleteItem(const std::string& path)
 {
     auto node = m_schema->dataNodeFromPath(path);
     auto container = *(node->find_path(path.c_str())->data().begin());
@@ -79,33 +79,6 @@
     doEditFromDataNode(node);
 }
 
-void NetconfAccess::createListInstance(const std::string& path)
-{
-    auto node = m_schema->dataNodeFromPath(path);
-    doEditFromDataNode(node);
-}
-
-void NetconfAccess::deleteListInstance(const std::string& path)
-{
-    auto node = m_schema->dataNodeFromPath(path);
-    auto list = *(node->find_path(path.c_str())->data().begin());
-    list->insert_attr(m_schema->getYangModule("ietf-netconf"), "operation", "delete");
-    doEditFromDataNode(node);
-}
-
-void NetconfAccess::createLeafListInstance(const std::string& path)
-{
-    auto node = m_schema->dataNodeFromPath(path);
-    doEditFromDataNode(node);
-}
-void NetconfAccess::deleteLeafListInstance(const std::string& path)
-{
-    auto node = m_schema->dataNodeFromPath(path);
-    auto list = *(node->find_path(path.c_str())->data().begin());
-    list->insert_attr(m_schema->getYangModule("ietf-netconf"), "operation", "delete");
-    doEditFromDataNode(node);
-}
-
 struct impl_toYangInsert {
     std::string operator()(yang::move::Absolute& absolute)
     {
diff --git a/src/netconf_access.hpp b/src/netconf_access.hpp
index 3875911..3f45a27 100644
--- a/src/netconf_access.hpp
+++ b/src/netconf_access.hpp
@@ -35,12 +35,8 @@
     ~NetconfAccess() override;
     Tree getItems(const std::string& path) override;
     void setLeaf(const std::string& path, leaf_data_ value) override;
-    void createPresenceContainer(const std::string& path) override;
-    void deletePresenceContainer(const std::string& path) override;
-    void createListInstance(const std::string& path) override;
-    void deleteListInstance(const std::string& path) override;
-    void createLeafListInstance(const std::string& path) override;
-    void deleteLeafListInstance(const std::string& path) override;
+    void createItem(const std::string& path) override;
+    void deleteItem(const std::string& path) override;
     void moveItem(const std::string& path, std::variant<yang::move::Absolute, yang::move::Relative> move) override;
     void commitChanges() override;
     void discardChanges() override;
diff --git a/src/python_netconf.cpp b/src/python_netconf.cpp
index 76dc559..19c096f 100644
--- a/src/python_netconf.cpp
+++ b/src/python_netconf.cpp
@@ -68,10 +68,8 @@
                     "server"_a, "port"_a=830, "username"_a, "interactive_auth"_a)
             .def("getItems", &NetconfAccess::getItems, "xpath"_a)
             .def("setLeaf", &NetconfAccess::setLeaf, "xpath"_a, "value"_a)
-            .def("createPresenceContainer", &NetconfAccess::createPresenceContainer, "xpath"_a)
-            .def("deletePresenceContainer", &NetconfAccess::deletePresenceContainer, "xpath"_a)
-            .def("createListInstance", &NetconfAccess::createListInstance, "xpath"_a)
-            .def("deleteListInstance", &NetconfAccess::deleteListInstance, "xpath"_a)
+            .def("createItem", &NetconfAccess::createItem, "xpath"_a)
+            .def("deleteItem", &NetconfAccess::deleteItem, "xpath"_a)
             .def("executeRpc", &NetconfAccess::executeRpc, "rpc"_a, "input"_a=DatastoreAccess::Tree{})
             .def("commitChanges", &NetconfAccess::commitChanges)
             ;
diff --git a/src/sysrepo_access.cpp b/src/sysrepo_access.cpp
index 7b9cb7a..70b8823 100644
--- a/src/sysrepo_access.cpp
+++ b/src/sysrepo_access.cpp
@@ -235,7 +235,7 @@
     }
 }
 
-void SysrepoAccess::createPresenceContainer(const std::string& path)
+void SysrepoAccess::createItem(const std::string& path)
 {
     try {
         m_session->set_item(path.c_str());
@@ -244,43 +244,7 @@
     }
 }
 
-void SysrepoAccess::deletePresenceContainer(const std::string& path)
-{
-    try {
-        m_session->delete_item(path.c_str());
-    } catch (sysrepo::sysrepo_exception& ex) {
-        reportErrors();
-    }
-}
-
-void SysrepoAccess::createLeafListInstance(const std::string& path)
-{
-    try {
-        m_session->set_item(path.c_str());
-    } catch (sysrepo::sysrepo_exception& ex) {
-        reportErrors();
-    }
-}
-
-void SysrepoAccess::deleteLeafListInstance(const std::string& path)
-{
-    try {
-        m_session->delete_item(path.c_str());
-    } catch (sysrepo::sysrepo_exception& ex) {
-        reportErrors();
-    }
-}
-
-void SysrepoAccess::createListInstance(const std::string& path)
-{
-    try {
-        m_session->set_item(path.c_str());
-    } catch (sysrepo::sysrepo_exception& ex) {
-        reportErrors();
-    }
-}
-
-void SysrepoAccess::deleteListInstance(const std::string& path)
+void SysrepoAccess::deleteItem(const std::string& path)
 {
     try {
         m_session->delete_item(path.c_str());
diff --git a/src/sysrepo_access.hpp b/src/sysrepo_access.hpp
index 6e66eea..4d87847 100644
--- a/src/sysrepo_access.hpp
+++ b/src/sysrepo_access.hpp
@@ -30,12 +30,8 @@
     SysrepoAccess(const std::string& appname, const Datastore datastore);
     Tree getItems(const std::string& path) override;
     void setLeaf(const std::string& path, leaf_data_ value) override;
-    void createPresenceContainer(const std::string& path) override;
-    void deletePresenceContainer(const std::string& path) override;
-    void createListInstance(const std::string& path) override;
-    void deleteListInstance(const std::string& path) override;
-    void createLeafListInstance(const std::string& path) override;
-    void deleteLeafListInstance(const std::string& path) override;
+    void createItem(const std::string& path) override;
+    void deleteItem(const std::string& path) override;
     void moveItem(const std::string& source, std::variant<yang::move::Absolute, yang::move::Relative> move) override;
     Tree executeRpc(const std::string& path, const Tree& input) override;