]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[experiments/yang] set-config method implemented
authorTomek Mrugalski <tomasz@isc.org>
Tue, 12 Jul 2016 18:31:08 +0000 (20:31 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Tue, 12 Jul 2016 18:31:08 +0000 (20:31 +0200)
 It's implemented, but not tested at all.

src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/bin/dhcp6/ctrl_dhcp6_srv.h

index 8a398209166d0ca51e56711d4f9629ebf15486d1..6b927d4ba9bf2066c1a0dd2c825d625d736c0a1d 100644 (file)
@@ -97,6 +97,46 @@ ControlledDhcpv6Srv::commandLeasesReclaimHandler(const string&,
     return (answer);
 }
 
+ConstElementPtr
+ControlledDhcpv6Srv::commandSetConfigHandler(const string&,
+                                             ConstElementPtr args) {
+    const int status_code = 1; // 1 indicates an error
+    string message;
+
+    ConstElementPtr result;
+    ConstElementPtr dhcp6;
+
+    // args must be { "Dhcp6": { ... }, "Logging": { ... } }
+    // the Logging component is technically optional, but very recommended.
+    if (!args) {
+        message = "Missing mandatory 'Dhcp6' parameter.";
+    } else {
+        ConstElementPtr dhcp6 = args->get("Dhcp6");
+        if (!dhcp6) {
+            message = "Missing mandatory 'Dhcp6' parameter.";
+        } else if (dhcp6->getType() != Element::map) {
+            message = "'Dhcp6' parameter expected to be a map.";
+        }
+    }
+
+    if (!dhcp6) {
+        // Something went wrong, we can't find the Dhcp6 element.
+        result = isc::config::createAnswer(status_code, message);
+        return (result);
+    }
+
+    // Let's configure logging. We should call configureLogger, even
+    // if there's no logging specified. It means to return to the
+    // default logging.
+    ConstElementPtr logging = args->get("Logging");
+    Daemon::configureLogger(args->get("Logging"), CfgMgr::instance().getStagingCfg());
+
+    // Ok, logging set. Now let's configure the server.
+    result = ControlledDhcpv6Srv::processCommand("config-reload", dhcp6);
+
+    return (result);
+}
+
 isc::data::ConstElementPtr
 ControlledDhcpv6Srv::processCommand(const std::string& command,
                                     isc::data::ConstElementPtr args) {
@@ -285,6 +325,9 @@ ControlledDhcpv6Srv::ControlledDhcpv6Srv(uint16_t port)
     CommandMgr::instance().registerCommand("leases-reclaim",
         boost::bind(&ControlledDhcpv6Srv::commandLeasesReclaimHandler, this, _1, _2));
 
+    CommandMgr::instance().registerCommand("set-config",
+        boost::bind(&ControlledDhcpv6Srv::commandSetConfigHandler, this, _1, _2));
+
     // Register statistic related commands
     CommandMgr::instance().registerCommand("statistic-get",
         boost::bind(&StatsMgr::statisticGetHandler, _1, _2));
index b1ca9587c1424e09e09a6060dc0531e3818d9e51..1c6bde1664230ef72b9903cc2fcb6b13a4e396fd 100644 (file)
@@ -143,6 +143,20 @@ private:
     commandConfigReloadHandler(const std::string& command,
                                isc::data::ConstElementPtr args);
 
+    /// @brief handler for processing 'set-config' command
+    ///
+    /// This handler processes set-config command, which processes
+    /// configuration specified in args parameter.
+    /// @param command (parameter ignored)
+    /// @param args configuration to be processed. Expected format:
+    /// map containing Dhcp6 map that contains DHCPv6 server configuration.
+    /// May also contain Logging map that specifies logging configuration.
+    ///
+    /// @return status of the command
+    isc::data::ConstElementPtr
+    commandSetConfigHandler(const std::string& command,
+                            isc::data::ConstElementPtr args);
+
     /// @brief Handler for processing 'leases-reclaim' command
     ///
     /// This handler processes leases-reclaim command, which triggers