static constexpr StatementTag INSERT_HOST =
"INSERT_HOST";
+ // Retrieves hosts informations, IPv6 reservations and both IPv4 and IPv6
+ // options associated with the hosts.
+ static constexpr StatementTag GET_HOST =
+ "GET_HOST";
+
// Retrieves host information, IPv6 reservations and both IPv4 and IPv6
// options associated with the host.
static constexpr StatementTag GET_HOST_BY_HOST_ID =
}; // CqlHostExchange
constexpr StatementTag CqlHostExchange::INSERT_HOST;
+constexpr StatementTag CqlHostExchange::GET_HOST;
constexpr StatementTag CqlHostExchange::GET_HOST_BY_HOST_ID;
constexpr StatementTag CqlHostExchange::GET_HOST_BY_IPV4_ADDRESS;
constexpr StatementTag CqlHostExchange::GET_HOST_BY_IPV4_SUBNET_ID_AND_HOST_ID;
"IF NOT EXISTS "
}},
+ {GET_HOST,
+ {GET_HOST,
+ "SELECT "
+ "id, "
+ "host_identifier, "
+ "host_identifier_type, "
+ "host_ipv4_subnet_id, "
+ "host_ipv6_subnet_id, "
+ "host_ipv4_address, "
+ "host_ipv4_next_server, "
+ "host_ipv4_server_hostname, "
+ "host_ipv4_boot_file_name, "
+ "hostname, "
+ "user_context, "
+ "host_ipv4_client_classes, "
+ "host_ipv6_client_classes, "
+ "reserved_ipv6_prefix_address, "
+ "reserved_ipv6_prefix_length, "
+ "reserved_ipv6_prefix_address_type, "
+ "iaid, "
+ "option_universe, "
+ "option_code, "
+ "option_value, "
+ "option_formatted_value, "
+ "option_space, "
+ "option_is_persistent, "
+ "option_client_class, "
+ "option_subnet_id, "
+ "option_user_context, "
+ "option_scope_id "
+ "FROM host_reservations "
+ }},
+
{GET_HOST_BY_HOST_ID,
{GET_HOST_BY_HOST_ID,
"SELECT "
virtual ConstHostCollection
getAll4(const asiolink::IOAddress& address) const;
+ /// @brief Implementation of @ref CqlHostDataSource::getAllHosts()
+ ///
+ /// See @ref CqlHostDataSource::getAllHosts() for parameter details.
+ virtual ConstHostCollection
+ getAllHosts() const;
+
/// @brief Implementation of @ref CqlHostDataSource::getName()
virtual std::string getName() const;
return (result);
}
+ConstHostCollection
+CqlHostDataSourceImpl::getAllHosts() const {
+
+ // Bind to array.
+ AnyArray where_values;
+
+ // Run statement.
+ ConstHostCollection result = getHostCollection(CqlHostExchange::GET_HOST, where_values);
+
+ return (result);
+}
+
std::string
CqlHostDataSourceImpl::getName() const {
std::string name;
return (impl_->get6(subnet_id, address));
}
+ConstHostCollection
+CqlHostDataSource::getAllHosts() const {
+ return (impl_->getAllHosts());
+}
+
std::string
CqlHostDataSource::getType() const {
return std::string("cql");
get6(const SubnetID& subnet_id,
const asiolink::IOAddress& address) const override;
+ /// @brief Returns a collection of all the hosts.
+ ///
+ /// This method may return multiple @ref Host objects.
+ ///
+ /// @return Collection of const @ref Host objects.
+ virtual ConstHostCollection
+ getAllHosts() const;
+
/// @brief Returns textual description of the backend.
///
/// @return Description of the backend.
HostDataSourceFactory::create(validCqlConnectionString());
hdsptr_ = HostDataSourceFactory::getHostDataSourcePtr();
}
+
+ /// @brief Returns number of IPv4 options currently stored in DB.
+ virtual int countDBOptions4() {
+ int result = 0;
+
+ const CqlHostDataSource* cql_host_mgr = dynamic_cast<const CqlHostDataSource*>(&(*hdsptr_));
+ ConstHostCollection all = cql_host_mgr->getAllHosts();
+
+ for (ConstHostCollection::const_iterator it = all.begin();
+ it != all.end(); ++it) {
+ ConstCfgOptionPtr cfg_option4 = (*it)->getCfgOption4();
+ std::list<std::string> option_spaces4 = cfg_option4->getOptionSpaceNames();
+ std::list<std::string> vendor_spaces4 = cfg_option4->getVendorIdsSpaceNames();
+ option_spaces4.insert(option_spaces4.end(), vendor_spaces4.begin(),
+ vendor_spaces4.end());
+ for (const std::string& space : option_spaces4) {
+ OptionContainerPtr options = cfg_option4->getAll(space);
+ result += options->size();
+ }
+ }
+
+ return (result);
+ }
+
+ /// @brief Returns number of IPv6 options currently stored in DB.
+ virtual int countDBOptions6() {
+ int result = 0;
+
+ const CqlHostDataSource* cql_host_mgr = dynamic_cast<const CqlHostDataSource*>(&(*hdsptr_));
+ ConstHostCollection all = cql_host_mgr->getAllHosts();
+
+ for (ConstHostCollection::const_iterator it = all.begin();
+ it != all.end(); ++it) {
+ ConstCfgOptionPtr cfg_option6 = (*it)->getCfgOption6();
+ std::list<std::string> option_spaces6 = cfg_option6->getOptionSpaceNames();
+ std::list<std::string> vendor_spaces6 = cfg_option6->getVendorIdsSpaceNames();
+ option_spaces6.insert(option_spaces6.end(), vendor_spaces6.begin(),
+ vendor_spaces6.end());
+ for (const std::string& space : option_spaces6) {
+ OptionContainerPtr options = cfg_option6->getAll(space);
+ result += options->size();
+ }
+ }
+
+ return (result);
+ }
+
+ /// @brief Returns number of IPv6 reservations currently stored in DB.
+ virtual int countDBReservations6() {
+ int result = 0;
+
+ const CqlHostDataSource* cql_host_mgr = dynamic_cast<const CqlHostDataSource*>(&(*hdsptr_));
+ ConstHostCollection all = cql_host_mgr->getAllHosts();
+
+ for (ConstHostCollection::const_iterator it = all.begin();
+ it != all.end(); ++it) {
+ IPv6ResrvRange reservations = (*it)->getIPv6Reservations();
+ result += std::distance(reservations.first, reservations.second);
+ }
+
+ return (result);
+ }
+
};
/// @brief Check that database can be opened
return (countRowsInTable("dhcp4_options"));
}
- /// @brief Returns number of IPv4 options currently stored in DB.
+ /// @brief Returns number of IPv6 options currently stored in DB.
virtual int countDBOptions6() {
return (countRowsInTable("dhcp6_options"));
}
return (countRowsInTable("dhcp4_options"));
}
- /// @brief Returns number of IPv4 options currently stored in DB.
+ /// @brief Returns number of IPv6 options currently stored in DB.
virtual int countDBOptions6() {
return (countRowsInTable("dhcp6_options"));
}