You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PdnsSlave.cpp 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // Created by robin on 8/8/15.
  3. //
  4. #include <fstream>
  5. #include "DataAccess/PdnsSlaveConfig.h"
  6. #include "DataAccess/HostsConfig.h"
  7. #include "PdnsSlave.h"
  8. PdnsSlave::PdnsSlave(const std::string &filePath)
  9. : _filePath(filePath)
  10. {
  11. }
  12. BResult PdnsSlave::readConfig()
  13. {
  14. PdnsSlaveConfig conf(_filePath);
  15. BResult res;
  16. if (!(res = conf.readConfig()))
  17. return res;
  18. _dhcpdFilePath = conf.getDhcpdFilePath();
  19. _dhcpdTemplatePath = conf.getDhcpdTemplatePath();
  20. _hostsPath = conf.getHostsPath();
  21. _masterConfig = conf.getMasterConfig();
  22. _slaveConfig = conf.getSlaveConfig();
  23. return true;
  24. }
  25. BResult PdnsSlave::readDhcpdTemplate()
  26. {
  27. std::ifstream dhcpTemplate(_dhcpdTemplatePath);
  28. if (!dhcpTemplate)
  29. return BResult().error("Could not open file");
  30. while (!dhcpTemplate.eof())
  31. {
  32. std::string line;
  33. getline(dhcpTemplate, line);
  34. _dhcpdTemplateContent += line + "\n";
  35. }
  36. dhcpTemplate.close();
  37. return true;
  38. }
  39. Result<Actions> PdnsSlave::readHosts()
  40. {
  41. HostsConfig conf(_hostsPath);
  42. auto res = conf.readConfig();
  43. if (!res)
  44. return res;
  45. _actions = res.getData();
  46. return res;
  47. }