mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 14:05:33 +00:00
ask config manager for zones on startup instead of using a hardcoded default list
git-svn-id: svn://bind10.isc.org/svn/bind10/branches/f2f200910@285 e5f2f494-b856-4b98-b285-d166d9295462
This commit is contained in:
@@ -20,6 +20,9 @@
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <cc/cpp/data.h>
|
||||
#include <cc/cpp/session.h>
|
||||
@@ -37,9 +40,10 @@ CommandSession::CommandSession() :
|
||||
{
|
||||
try {
|
||||
session_.establish();
|
||||
session_.subscribe("ParkingLot");
|
||||
session_.subscribe("Boss");
|
||||
session_.subscribe("statistics");
|
||||
session_.subscribe("ParkingLot", "*", "meonly");
|
||||
session_.subscribe("Boss", "*", "meonly");
|
||||
session_.subscribe("ConfigManager", "*", "meonly");
|
||||
session_.subscribe("statistics", "*", "meonly");
|
||||
} catch (...) {
|
||||
throw std::runtime_error("SessionManager: failed to open sessions");
|
||||
}
|
||||
@@ -83,3 +87,19 @@ CommandSession::getCommand(int counter) {
|
||||
|
||||
return std::pair<string, string>("unknown", "");
|
||||
}
|
||||
|
||||
std::vector<std::string>
|
||||
CommandSession::getZones() {
|
||||
ElementPtr cmd, result, env;
|
||||
std::vector<std::string> zone_names;
|
||||
std::stringstream cmd_string;
|
||||
cmd_string << "{ \"command\": [ \"zone\", \"list\" ] }";
|
||||
cmd = Element::create_from_string(cmd_string);
|
||||
sleep(1);
|
||||
session_.group_sendmsg(cmd, "ConfigManager");
|
||||
session_.group_recvmsg(env, result, false);
|
||||
BOOST_FOREACH(ElementPtr zone_name, result->get("result")->list_value()) {
|
||||
zone_names.push_back(zone_name->string_value());
|
||||
}
|
||||
return zone_names;
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@ public:
|
||||
CommandSession();
|
||||
int getSocket();
|
||||
std::pair<std::string, std::string> getCommand(int counter);
|
||||
std::vector<std::string> getZones();
|
||||
private:
|
||||
ISC::CC::Session session_;
|
||||
};
|
||||
|
@@ -23,6 +23,8 @@
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <dns/buffer.h>
|
||||
#include <dns/name.h>
|
||||
#include <dns/rrset.h>
|
||||
@@ -76,6 +78,9 @@ main(int argc, char* argv[]) {
|
||||
fd_set fds;
|
||||
int ps = plot.getSocket();
|
||||
int ss = cs.getSocket();
|
||||
BOOST_FOREACH(std::string zone, cs.getZones()) {
|
||||
plot.serve(zone);
|
||||
}
|
||||
int nfds = max(ps, ss) + 1;
|
||||
int counter = 0;
|
||||
|
||||
|
@@ -37,17 +37,7 @@ using namespace isc::dns;
|
||||
using namespace isc::dns::Rdata::IN;
|
||||
using namespace isc::dns::Rdata::Generic;
|
||||
|
||||
static void init_zones(ZoneSet& zones) {
|
||||
zones.serve("jinmei.org");
|
||||
zones.serve("nuthaven.org");
|
||||
zones.serve("isc.org");
|
||||
zones.serve("sisotowbell.org");
|
||||
zones.serve("flame.org");
|
||||
}
|
||||
|
||||
ParkingLot::ParkingLot(int port) {
|
||||
init_zones(zones);
|
||||
|
||||
ns1 = Rdata::RdataPtr(new NS("ns1.parking.example"));
|
||||
ns2 = Rdata::RdataPtr(new NS("ns2.parking.example"));
|
||||
ns3 = Rdata::RdataPtr(new NS("ns3.parking.example"));
|
||||
@@ -196,9 +186,14 @@ ParkingLot::processMessage() {
|
||||
void
|
||||
ParkingLot::command(pair<string,string> cmd) {
|
||||
if (cmd.first == "addzone")
|
||||
zones.serve(cmd.second);
|
||||
serve(cmd.second);
|
||||
else if (cmd.first == "delzone")
|
||||
zones.forget(cmd.second);
|
||||
else if (cmd.first == "shutdown")
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
ParkingLot::serve(std::string zone_name) {
|
||||
zones.serve(zone_name);
|
||||
}
|
||||
|
@@ -26,7 +26,8 @@ public:
|
||||
int getSocket() { return (sock); }
|
||||
void processMessage();
|
||||
void command(std::pair<std::string,std::string>);
|
||||
|
||||
void serve(std::string zone_name);
|
||||
|
||||
private:
|
||||
isc::dns::Rdata::RdataPtr ns1, ns2, ns3, a, aaaa, soa;
|
||||
ZoneSet zones;
|
||||
|
Reference in New Issue
Block a user