37 datadir_ = Optional<std::string>(datadir, unspecified);
42 ensureCurrentAllocated();
46 d2_client_mgr_->setD2ClientConfig(new_config);
52 configuration_->setD2ClientConfig(new_config);
57 return (d2_client_mgr_->ddnsEnabled());
62 return (d2_client_mgr_->getD2ClientConfig());
67 return (*d2_client_mgr_);
71CfgMgr::ensureCurrentAllocated() {
72 if (!configuration_ || configs_.empty()) {
74 configs_.push_back(configuration_);
81 configuration_->removeStatistics();
84 external_configs_.clear();
91 ensureCurrentAllocated();
96 configuration_->removeStatistics();
98 if (!configs_.back()->sequenceEquals(*configuration_)) {
99 configuration_ = configs_.back();
103 SrvConfigList::iterator it = configs_.begin();
105 configs_.erase(configs_.begin(), it);
110 auto now = boost::posix_time::second_clock::universal_time();
111 configuration_->setLastCommitTime(now);
114 configuration_->updateStatistics();
116 configuration_->configureLowerLevelLibraries();
121 ensureCurrentAllocated();
122 if (!configuration_->sequenceEquals(*configs_.back())) {
129 ensureCurrentAllocated();
132 " to an old configuration");
133 }
else if (index > configs_.size() - 1) {
135 << index <<
"', only '" << configs_.size() - 1
136 <<
"' previous commits available");
148 SrvConfigList::const_reverse_iterator it = configs_.rbegin();
149 std::advance(it, index);
162 ensureCurrentAllocated();
163 return (configuration_);
168 ensureCurrentAllocated();
169 if (configuration_->sequenceEquals(*configs_.back())) {
170 uint32_t sequence = configuration_->getSequence();
173 return (configs_.back());
180 if (!external_configs_.empty()) {
181 seq = external_configs_.rbegin()->second->getSequence() + 1;
185 external_configs_[seq] = srv_config;
211CfgMgr::mergeIntoCfg(
const SrvConfigPtr& target_config,
const uint32_t seq) {
212 auto source_config = external_configs_.find(seq);
213 if (source_config != external_configs_.end()) {
214 target_config->merge(*source_config->second);
215 external_configs_.erase(source_config);
219 "of " << seq <<
" was not found");
224 : datadir_(DHCP_DATA_DIR, true), d2_client_mgr_(new
D2ClientMgr()), family_(AF_INET) {
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
util::Optional< std::string > getDataDir() const
returns path do the data directory
CfgMgr()
Protected constructor.
const D2ClientConfigPtr & getD2ClientConfig() const
Fetches the DHCP-DDNS configuration pointer.
D2ClientMgr & getD2ClientMgr()
Fetches the DHCP-DDNS manager.
void clear()
Removes current, staging and all previous configurations.
SrvConfigPtr createExternalCfg()
Creates an external configuration and returns pointer to it.
void setD2ClientConfig(D2ClientConfigPtr &new_config)
Updates the DHCP-DDNS client configuration to the given value.
void rollback()
Removes staging configuration.
static CfgMgr & instance()
returns a single instance of Configuration Manager
virtual ~CfgMgr()
virtual destructor
void mergeIntoStagingCfg(const uint32_t seq)
Merges external configuration with the given sequence number into the staging configuration.
void mergeIntoCurrentCfg(const uint32_t seq)
Merges external configuration with the given sequence number into the current configuration.
void setDataDir(const std::string &datadir, bool unspecified=true)
Sets new data directory.
SrvConfigPtr getStagingCfg()
Returns a pointer to the staging configuration.
bool ddnsEnabled()
Convenience method for checking if DHCP-DDNS updates are enabled.
void revert(const size_t index)
Reverts to one of the previous configurations.
static const size_t CONFIG_LIST_SIZE
A number of configurations held by CfgMgr.
void commit()
Commits the staging configuration.
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Acts as a storage vault for D2 client configuration.
D2ClientMgr isolates Kea from the details of being a D2 client.
static void setRuntimeOptionDefs(const OptionDefSpaceContainer &defs)
Copies option definitions created at runtime.
Specifies current DHCP configuration.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< D2ClientConfig > D2ClientConfigPtr
Defines a pointer for D2ClientConfig instances.
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
Defines the logger used by the top-level component of kea-lfc.