Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Kea
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
450
Issues
450
List
Boards
Labels
Service Desk
Milestones
Merge Requests
75
Merge Requests
75
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ISC Open Source Projects
Kea
Commits
ad8a7cd7
Commit
ad8a7cd7
authored
Jun 12, 2019
by
Marcin Siodelski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[
#642
,
!373
] Updated MySQL Config Backend with simple server mgmt functions.
parent
8ca10218
Changes
25
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
845 additions
and
53 deletions
+845
-53
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc
+65
-13
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.h
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.h
+1
-1
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc
+64
-13
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.h
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.h
+1
-1
src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc
src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc
+130
-0
src/hooks/dhcp/mysql_cb/mysql_cb_impl.h
src/hooks/dhcp/mysql_cb/mysql_cb_impl.h
+76
-9
src/hooks/dhcp/mysql_cb/mysql_cb_messages.cc
src/hooks/dhcp/mysql_cb/mysql_cb_messages.cc
+17
-1
src/hooks/dhcp/mysql_cb/mysql_cb_messages.h
src/hooks/dhcp/mysql_cb/mysql_cb_messages.h
+9
-1
src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes
src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes
+30
-0
src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h
src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h
+48
-0
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc
+125
-1
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc
+124
-1
src/lib/config_backend/constants.h
src/lib/config_backend/constants.h
+2
-0
src/lib/dhcpsrv/config_backend_dhcp4.h
src/lib/dhcpsrv/config_backend_dhcp4.h
+1
-1
src/lib/dhcpsrv/config_backend_dhcp6.h
src/lib/dhcpsrv/config_backend_dhcp6.h
+2
-1
src/lib/dhcpsrv/config_backend_pool_dhcp4.cc
src/lib/dhcpsrv/config_backend_pool_dhcp4.cc
+1
-1
src/lib/dhcpsrv/config_backend_pool_dhcp4.h
src/lib/dhcpsrv/config_backend_pool_dhcp4.h
+1
-1
src/lib/dhcpsrv/config_backend_pool_dhcp6.cc
src/lib/dhcpsrv/config_backend_pool_dhcp6.cc
+1
-1
src/lib/dhcpsrv/config_backend_pool_dhcp6.h
src/lib/dhcpsrv/config_backend_pool_dhcp6.h
+2
-1
src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.cc
src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.cc
+2
-2
src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.h
src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.h
+1
-1
src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.cc
src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.cc
+2
-2
src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.h
src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.h
+1
-1
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/dhcpdb_create.mysql
+55
-0
src/share/database/scripts/mysql/upgrade_8.0_to_9.0.sh.in
src/share/database/scripts/mysql/upgrade_8.0_to_9.0.sh.in
+84
-0
No files found.
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc
View file @
ad8a7cd7
...
...
@@ -79,6 +79,8 @@ public:
GET_OPTION4_POOL_ID_CODE_SPACE
,
GET_OPTION4_SHARED_NETWORK_CODE_SPACE
,
GET_AUDIT_ENTRIES4_TIME
,
GET_SERVER4
,
GET_ALL_SERVERS4
,
INSERT_GLOBAL_PARAMETER4
,
INSERT_GLOBAL_PARAMETER4_SERVER
,
INSERT_SUBNET4
,
...
...
@@ -90,6 +92,7 @@ public:
INSERT_OPTION_DEF4_SERVER
,
INSERT_OPTION4
,
INSERT_OPTION4_SERVER
,
INSERT_SERVER4
,
UPDATE_GLOBAL_PARAMETER4
,
UPDATE_SUBNET4
,
UPDATE_SHARED_NETWORK4
,
...
...
@@ -98,6 +101,7 @@ public:
UPDATE_OPTION4_SUBNET_ID
,
UPDATE_OPTION4_POOL_ID
,
UPDATE_OPTION4_SHARED_NETWORK
,
UPDATE_SERVER4
,
DELETE_GLOBAL_PARAMETER4
,
DELETE_ALL_GLOBAL_PARAMETERS4
,
DELETE_SUBNET4_ID
,
...
...
@@ -115,6 +119,8 @@ public:
DELETE_OPTION4_SHARED_NETWORK
,
DELETE_OPTIONS4_SUBNET_ID
,
DELETE_OPTIONS4_SHARED_NETWORK
,
DELETE_SERVER4
,
DELETE_ALL_SERVERS4
,
NUM_STATEMENTS
};
...
...
@@ -1886,6 +1892,7 @@ public:
true
,
in_bindings
));
}
};
namespace
{
...
...
@@ -2032,6 +2039,16 @@ TaggedStatementArray tagged_statements = { {
MYSQL_GET_AUDIT_ENTRIES_TIME
(
dhcp4
)
},
// Retrieves a server by tag.
{
MySqlConfigBackendDHCPv4Impl
::
GET_SERVER4
,
MYSQL_GET_SERVER
(
dhcp4
)
},
// Retrieves all servers.
{
MySqlConfigBackendDHCPv4Impl
::
GET_ALL_SERVERS4
,
MYSQL_GET_ALL_SERVERS
(
dhcp4
)
},
// Insert global parameter.
{
MySqlConfigBackendDHCPv4Impl
::
INSERT_GLOBAL_PARAMETER4
,
MYSQL_INSERT_GLOBAL_PARAMETER
(
dhcp4
)
...
...
@@ -2136,6 +2153,11 @@ TaggedStatementArray tagged_statements = { {
MYSQL_INSERT_OPTION_SERVER
(
dhcp4
)
},
// Insert server with server tag and description.
{
MySqlConfigBackendDHCPv4Impl
::
INSERT_SERVER4
,
MYSQL_INSERT_SERVER
(
dhcp4
)
},
// Update existing global parameter.
{
MySqlConfigBackendDHCPv4Impl
::
UPDATE_GLOBAL_PARAMETER4
,
MYSQL_UPDATE_GLOBAL_PARAMETER
(
dhcp4
)
...
...
@@ -2223,6 +2245,11 @@ TaggedStatementArray tagged_statements = { {
MYSQL_UPDATE_OPTION4
(
AND
o
.
scope_id
=
4
AND
o
.
shared_network_name
=
?
AND
o
.
code
=
?
AND
o
.
space
=
?
)
},
// Update existing server, e.g. server description.
{
MySqlConfigBackendDHCPv4Impl
::
UPDATE_SERVER4
,
MYSQL_UPDATE_SERVER
(
dhcp4
)
},
// Delete global parameter by name.
{
MySqlConfigBackendDHCPv4Impl
::
DELETE_GLOBAL_PARAMETER4
,
MYSQL_DELETE_GLOBAL_PARAMETER
(
dhcp4
,
AND
g
.
name
=
?
)
...
...
@@ -2308,6 +2335,16 @@ TaggedStatementArray tagged_statements = { {
// Delete options belonging to a shared_network.
{
MySqlConfigBackendDHCPv4Impl
::
DELETE_OPTIONS4_SHARED_NETWORK
,
MYSQL_DELETE_OPTION
(
dhcp4
,
AND
o
.
scope_id
=
4
AND
o
.
shared_network_name
=
?
)
},
// Delete a server by tag.
{
MySqlConfigBackendDHCPv4Impl
::
DELETE_SERVER4
,
MYSQL_DELETE_SERVER
(
dhcp4
)
},
// Deletes all servers except logical server 'all'.
{
MySqlConfigBackendDHCPv4Impl
::
DELETE_ALL_SERVERS4
,
MYSQL_DELETE_ALL_SERVERS
(
dhcp4
)
}
}
};
...
...
@@ -2532,14 +2569,22 @@ MySqlConfigBackendDHCPv4::getRecentAuditEntries(const db::ServerSelector& server
ServerCollection
MySqlConfigBackendDHCPv4
::
getAllServers4
()
const
{
isc_throw
(
NotImplemented
,
"MySqlConfigBackendDHCPv4::getAllServers4"
" is not implemented"
);
ServerCollection
servers
;
LOG_DEBUG
(
mysql_cb_logger
,
DBGLVL_TRACE_BASIC
,
MYSQL_CB_GET_ALL_SERVERS4
);
impl_
->
getAllServers
(
MySqlConfigBackendDHCPv4Impl
::
GET_ALL_SERVERS4
,
servers
);
LOG_DEBUG
(
mysql_cb_logger
,
DBGLVL_TRACE_BASIC
,
MYSQL_CB_GET_ALL_SERVERS4_RESULT
)
.
arg
(
servers
.
size
());
return
(
servers
);
}
ServerPtr
MySqlConfigBackendDHCPv4
::
getServer4
(
const
data
::
ServerTag
&
/* server_tag */
)
const
{
isc_throw
(
NotImplemented
,
"MySqlConfigBackendDHCPv4::getServer4"
" is not implemented"
);
MySqlConfigBackendDHCPv4
::
getServer4
(
const
data
::
ServerTag
&
server_tag
)
const
{
LOG_DEBUG
(
mysql_cb_logger
,
DBGLVL_TRACE_BASIC
,
MYSQL_CB_GET_SERVER4
)
.
arg
(
server_tag
.
get
());
return
(
impl_
->
getServer
(
MySqlConfigBackendDHCPv4Impl
::
GET_SERVER4
,
server_tag
));
}
void
...
...
@@ -2611,9 +2656,13 @@ MySqlConfigBackendDHCPv4::createUpdateGlobalParameter4(const ServerSelector& ser
}
void
MySqlConfigBackendDHCPv4
::
createUpdateServer4
(
const
ServerPtr
&
/* server */
)
{
isc_throw
(
NotImplemented
,
"MySqlConfigBackendDHCPv4::createUpdateServer4"
" is not implemented"
);
MySqlConfigBackendDHCPv4
::
createUpdateServer4
(
const
ServerPtr
&
server
)
{
LOG_DEBUG
(
mysql_cb_logger
,
DBGLVL_TRACE_BASIC
,
MYSQL_CB_CREATE_UPDATE_SERVER4
)
.
arg
(
server
->
getServerTag
());
impl_
->
createUpdateServer
(
MySqlConfigBackendDHCPv4Impl
::
CREATE_AUDIT_REVISION
,
MySqlConfigBackendDHCPv4Impl
::
INSERT_SERVER4
,
MySqlConfigBackendDHCPv4Impl
::
UPDATE_SERVER4
,
server
);
}
uint64_t
...
...
@@ -2792,15 +2841,18 @@ MySqlConfigBackendDHCPv4::deleteAllGlobalParameters4(const ServerSelector& serve
}
uint64_t
MySqlConfigBackendDHCPv4
::
deleteServer4
(
const
std
::
string
&
/* server_tag */
)
{
isc_throw
(
NotImplemented
,
"MySqlConfigBackendDHCPv4::deleteServer4"
" is not implemented"
);
MySqlConfigBackendDHCPv4
::
deleteServer4
(
const
ServerTag
&
server_tag
)
{
uint64_t
result
=
impl_
->
deleteServer
(
MySqlConfigBackendDHCPv4Impl
::
CREATE_AUDIT_REVISION
,
MySqlConfigBackendDHCPv4Impl
::
DELETE_SERVER4
,
server_tag
.
get
());
return
(
result
);
}
uint64_t
MySqlConfigBackendDHCPv4
::
deleteAllServers4
()
{
isc_throw
(
NotImplemented
,
"MySqlConfigBackendDHCPv4::deleteAllServers4"
" is not implemented"
);
uint64_t
result
=
impl_
->
deleteAllServers
(
MySqlConfigBackendDHCPv4Impl
::
CREATE_AUDIT_REVISION
,
MySqlConfigBackendDHCPv4Impl
::
DELETE_ALL_SERVERS4
);
return
(
result
);
}
std
::
string
...
...
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.h
View file @
ad8a7cd7
...
...
@@ -450,7 +450,7 @@ public:
/// @param server_tag Tag of the server to be deleted.
/// @return Number of deleted servers.
virtual
uint64_t
deleteServer4
(
const
std
::
strin
g
&
server_tag
);
deleteServer4
(
const
data
::
ServerTa
g
&
server_tag
);
/// @brief Deletes all servers from the backend except the logical
/// server 'all'.
...
...
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc
View file @
ad8a7cd7
...
...
@@ -82,6 +82,8 @@ public:
GET_OPTION6_PD_POOL_ID_CODE_SPACE
,
GET_OPTION6_SHARED_NETWORK_CODE_SPACE
,
GET_AUDIT_ENTRIES6_TIME
,
GET_SERVER6
,
GET_ALL_SERVERS6
,
INSERT_GLOBAL_PARAMETER6
,
INSERT_GLOBAL_PARAMETER6_SERVER
,
INSERT_SUBNET6
,
...
...
@@ -94,6 +96,7 @@ public:
INSERT_OPTION_DEF6_SERVER
,
INSERT_OPTION6
,
INSERT_OPTION6_SERVER
,
INSERT_SERVER6
,
UPDATE_GLOBAL_PARAMETER6
,
UPDATE_SUBNET6
,
UPDATE_SHARED_NETWORK6
,
...
...
@@ -103,6 +106,7 @@ public:
UPDATE_OPTION6_POOL_ID
,
UPDATE_OPTION6_PD_POOL_ID
,
UPDATE_OPTION6_SHARED_NETWORK
,
UPDATE_SERVER6
,
DELETE_GLOBAL_PARAMETER6
,
DELETE_ALL_GLOBAL_PARAMETERS6
,
DELETE_SUBNET6_ID
,
...
...
@@ -122,6 +126,8 @@ public:
DELETE_OPTION6_SHARED_NETWORK
,
DELETE_OPTIONS6_SUBNET_ID
,
DELETE_OPTIONS6_SHARED_NETWORK
,
DELETE_SERVER6
,
DELETE_ALL_SERVERS6
,
NUM_STATEMENTS
};
...
...
@@ -2380,6 +2386,16 @@ TaggedStatementArray tagged_statements = { {
MYSQL_GET_AUDIT_ENTRIES_TIME
(
dhcp6
)
},
// Retrieves a server by tag.
{
MySqlConfigBackendDHCPv6Impl
::
GET_SERVER6
,
MYSQL_GET_SERVER
(
dhcp6
)
},
// Retrieves all servers.
{
MySqlConfigBackendDHCPv6Impl
::
GET_ALL_SERVERS6
,
MYSQL_GET_ALL_SERVERS
(
dhcp6
)
},
// Insert global parameter.
{
MySqlConfigBackendDHCPv6Impl
::
INSERT_GLOBAL_PARAMETER6
,
MYSQL_INSERT_GLOBAL_PARAMETER
(
dhcp6
)
...
...
@@ -2486,6 +2502,11 @@ TaggedStatementArray tagged_statements = { {
MYSQL_INSERT_OPTION_SERVER
(
dhcp6
)
},
// Insert server with server tag and description.
{
MySqlConfigBackendDHCPv6Impl
::
INSERT_SERVER6
,
MYSQL_INSERT_SERVER
(
dhcp6
)
},
// Update existing global parameter.
{
MySqlConfigBackendDHCPv6Impl
::
UPDATE_GLOBAL_PARAMETER6
,
MYSQL_UPDATE_GLOBAL_PARAMETER
(
dhcp6
)
...
...
@@ -2575,6 +2596,11 @@ TaggedStatementArray tagged_statements = { {
MYSQL_UPDATE_OPTION6
(
AND
o
.
scope_id
=
4
AND
o
.
shared_network_name
=
?
AND
o
.
code
=
?
AND
o
.
space
=
?
)
},
// Update existing server, e.g. server description.
{
MySqlConfigBackendDHCPv6Impl
::
UPDATE_SERVER6
,
MYSQL_UPDATE_SERVER
(
dhcp6
)
},
// Delete global parameter by name.
{
MySqlConfigBackendDHCPv6Impl
::
DELETE_GLOBAL_PARAMETER6
,
MYSQL_DELETE_GLOBAL_PARAMETER
(
dhcp6
,
AND
g
.
name
=
?
)
...
...
@@ -2670,6 +2696,16 @@ TaggedStatementArray tagged_statements = { {
// Delete options belonging to a shared_network.
{
MySqlConfigBackendDHCPv6Impl
::
DELETE_OPTIONS6_SHARED_NETWORK
,
MYSQL_DELETE_OPTION
(
dhcp6
,
AND
o
.
scope_id
=
4
AND
o
.
shared_network_name
=
?
)
},
// Delete a server by tag.
{
MySqlConfigBackendDHCPv6Impl
::
DELETE_SERVER6
,
MYSQL_DELETE_SERVER
(
dhcp6
)
},
// Deletes all servers except logical server 'all'.
{
MySqlConfigBackendDHCPv6Impl
::
DELETE_ALL_SERVERS6
,
MYSQL_DELETE_ALL_SERVERS
(
dhcp6
)
}
}
};
...
...
@@ -2894,14 +2930,22 @@ MySqlConfigBackendDHCPv6::getRecentAuditEntries(const db::ServerSelector& server
ServerCollection
MySqlConfigBackendDHCPv6
::
getAllServers6
()
const
{
isc_throw
(
NotImplemented
,
"MySqlConfigBackendDHCPv6::getAllServers6"
" is not implemented"
);
ServerCollection
servers
;
LOG_DEBUG
(
mysql_cb_logger
,
DBGLVL_TRACE_BASIC
,
MYSQL_CB_GET_ALL_SERVERS6
);
impl_
->
getAllServers
(
MySqlConfigBackendDHCPv6Impl
::
GET_ALL_SERVERS6
,
servers
);
LOG_DEBUG
(
mysql_cb_logger
,
DBGLVL_TRACE_BASIC
,
MYSQL_CB_GET_ALL_SERVERS6_RESULT
)
.
arg
(
servers
.
size
());
return
(
servers
);
}
ServerPtr
MySqlConfigBackendDHCPv6
::
getServer6
(
const
data
::
ServerTag
&
/* server_tag */
)
const
{
isc_throw
(
NotImplemented
,
"MySqlConfigBackendDHCPv6::getServer6"
" is not implemented"
);
MySqlConfigBackendDHCPv6
::
getServer6
(
const
data
::
ServerTag
&
server_tag
)
const
{
LOG_DEBUG
(
mysql_cb_logger
,
DBGLVL_TRACE_BASIC
,
MYSQL_CB_GET_SERVER6
)
.
arg
(
server_tag
.
get
());
return
(
impl_
->
getServer
(
MySqlConfigBackendDHCPv6Impl
::
GET_SERVER6
,
server_tag
));
}
void
...
...
@@ -2984,9 +3028,13 @@ MySqlConfigBackendDHCPv6::createUpdateGlobalParameter6(const ServerSelector& ser
}
void
MySqlConfigBackendDHCPv6
::
createUpdateServer6
(
const
ServerPtr
&
/* server */
)
{
isc_throw
(
NotImplemented
,
"MySqlConfigBackendDHCPv6::createUpdateServer6"
" is not implemented"
);
MySqlConfigBackendDHCPv6
::
createUpdateServer6
(
const
ServerPtr
&
server
)
{
LOG_DEBUG
(
mysql_cb_logger
,
DBGLVL_TRACE_BASIC
,
MYSQL_CB_CREATE_UPDATE_SERVER6
)
.
arg
(
server
->
getServerTag
());
impl_
->
createUpdateServer
(
MySqlConfigBackendDHCPv6Impl
::
CREATE_AUDIT_REVISION
,
MySqlConfigBackendDHCPv6Impl
::
INSERT_SERVER6
,
MySqlConfigBackendDHCPv6Impl
::
UPDATE_SERVER6
,
server
);
}
uint64_t
...
...
@@ -3180,15 +3228,18 @@ MySqlConfigBackendDHCPv6::deleteAllGlobalParameters6(const ServerSelector& serve
}
uint64_t
MySqlConfigBackendDHCPv6
::
deleteServer6
(
const
std
::
string
&
/* server_tag */
)
{
isc_throw
(
NotImplemented
,
"MySqlConfigBackendDHCPv4::deleteServer6"
" is not implemented"
);
MySqlConfigBackendDHCPv6
::
deleteServer6
(
const
ServerTag
&
server_tag
)
{
uint64_t
result
=
impl_
->
deleteServer
(
MySqlConfigBackendDHCPv6Impl
::
CREATE_AUDIT_REVISION
,
MySqlConfigBackendDHCPv6Impl
::
DELETE_SERVER6
,
server_tag
.
get
());
return
(
result
);
}
uint64_t
MySqlConfigBackendDHCPv6
::
deleteAllServers6
()
{
isc_throw
(
NotImplemented
,
"MySqlConfigBackendDHCPv6::deleteAllServers6"
" is not implemented"
);
uint64_t
result
=
impl_
->
deleteAllServers
(
MySqlConfigBackendDHCPv6Impl
::
CREATE_AUDIT_REVISION
,
MySqlConfigBackendDHCPv6Impl
::
DELETE_ALL_SERVERS6
);
return
(
result
);
}
std
::
string
...
...
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.h
View file @
ad8a7cd7
...
...
@@ -483,7 +483,7 @@ public:
/// @param server_tag Tag of the server to be deleted.
/// @return Number of deleted servers.
virtual
uint64_t
deleteServer6
(
const
std
::
strin
g
&
server_tag
);
deleteServer6
(
const
data
::
ServerTa
g
&
server_tag
);
/// @brief Deletes all servers from the backend except the logical
/// server 'all'.
...
...
src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc
View file @
ad8a7cd7
...
...
@@ -832,6 +832,136 @@ MySqlConfigBackendImpl::createOptionValueBinding(const OptionDescriptorPtr& opti
return
(
MySqlBinding
::
createNull
());
}
ServerPtr
MySqlConfigBackendImpl
::
getServer
(
const
int
index
,
const
ServerTag
&
server_tag
)
{
ServerCollection
servers
;
MySqlBindingCollection
in_bindings
=
{
MySqlBinding
::
createString
(
server_tag
.
get
())
};
getServers
(
index
,
in_bindings
,
servers
);
return
(
servers
.
empty
()
?
ServerPtr
()
:
*
servers
.
begin
());
}
void
MySqlConfigBackendImpl
::
getAllServers
(
const
int
index
,
db
::
ServerCollection
&
servers
)
{
MySqlBindingCollection
in_bindings
;
getServers
(
index
,
in_bindings
,
servers
);
}
void
MySqlConfigBackendImpl
::
getServers
(
const
int
index
,
const
MySqlBindingCollection
&
in_bindings
,
ServerCollection
&
servers
)
{
MySqlBindingCollection
out_bindings
=
{
MySqlBinding
::
createInteger
<
uint64_t
>
(),
MySqlBinding
::
createString
(
SERVER_TAG_BUF_LENGTH
),
MySqlBinding
::
createString
(
SERVER_DESCRIPTION_BUF_LENGTH
),
MySqlBinding
::
createTimestamp
()
};
conn_
.
selectQuery
(
index
,
in_bindings
,
out_bindings
,
[
&
servers
](
MySqlBindingCollection
&
out_bindings
)
{
ServerPtr
last_server
;
uint64_t
id
=
out_bindings
[
0
]
->
getInteger
<
uint64_t
>
();
if
(
!
last_server
||
(
last_server
->
getId
()
!=
id
))
{
// Set description if it is non-null.
auto
desc
=
(
out_bindings
[
2
]
->
amNull
()
?
""
:
out_bindings
[
2
]
->
getString
());
last_server
=
Server
::
create
(
ServerTag
(
out_bindings
[
1
]
->
getString
()),
desc
);
// id
last_server
->
setId
(
id
);
// modification_ts
last_server
->
setModificationTime
(
out_bindings
[
3
]
->
getTimestamp
());
// New server fetched. Let's store it.
servers
.
insert
(
last_server
);
}
});
}
void
MySqlConfigBackendImpl
::
createUpdateServer
(
const
int
create_audit_revision_index
,
const
int
create_index
,
const
int
update_index
,
const
ServerPtr
&
server
)
{
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision
audit_revision
(
this
,
create_audit_revision_index
,
ServerSelector
::
ALL
(),
"server set"
,
true
);
MySqlTransaction
transaction
(
conn_
);
MySqlBindingCollection
in_bindings
=
{
MySqlBinding
::
createString
(
server
->
getServerTag
()),
MySqlBinding
::
createString
(
server
->
getDescription
()),
MySqlBinding
::
createTimestamp
(
server
->
getModificationTime
())
};
try
{
conn_
.
insertQuery
(
create_index
,
in_bindings
);
}
catch
(
const
DuplicateEntry
&
)
{
in_bindings
.
push_back
(
MySqlBinding
::
createString
(
server
->
getServerTag
()));
conn_
.
updateDeleteQuery
(
update_index
,
in_bindings
);
}
transaction
.
commit
();
}
uint64_t
MySqlConfigBackendImpl
::
deleteServer
(
const
int
create_audit_revision_index
,
const
int
delete_index
,
const
std
::
string
&
server_tag
)
{
MySqlTransaction
transaction
(
conn_
);
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision
audit_revision
(
this
,
create_audit_revision_index
,
ServerSelector
::
ALL
(),
"deleting a server"
,
false
);
// Specify which server should be deleted.
MySqlBindingCollection
in_bindings
=
{
MySqlBinding
::
createString
(
server_tag
)
};
// Attempt to delete the server.
auto
count
=
conn_
.
updateDeleteQuery
(
delete_index
,
in_bindings
);
transaction
.
commit
();
return
(
count
);
}
uint64_t
MySqlConfigBackendImpl
::
deleteAllServers
(
const
int
create_audit_revision_index
,
const
int
delete_index
)
{
MySqlTransaction
transaction
(
conn_
);
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision
audit_revision
(
this
,
create_audit_revision_index
,
ServerSelector
::
ALL
(),
"deleting a server"
,
false
);
MySqlBindingCollection
in_bindings
;
// Attempt to delete the servers.
auto
count
=
conn_
.
updateDeleteQuery
(
delete_index
,
in_bindings
);
transaction
.
commit
();
return
(
count
);
}
std
::
string
MySqlConfigBackendImpl
::
getType
()
const
{
return
(
"mysql"
);
...
...
src/hooks/dhcp/mysql_cb/mysql_cb_impl.h
View file @
ad8a7cd7
...
...
@@ -10,6 +10,8 @@
#include <cc/stamped_value.h>
#include <database/audit_entry.h>
#include <database/database_connection.h>
#include <database/server.h>
#include <database/server_collection.h>
#include <database/server_selector.h>
#include <dhcp/option.h>
#include <dhcp/option_definition.h>
...
...
@@ -340,7 +342,7 @@ public:
/// size of the bindings collection must match the number of placeholders
/// in the prepared statement. The input bindings collection must be empty
/// if the query contains no WHERE clause.
/// @param [out]
subnet
s Reference to the container where fetched parameters
/// @param [out]
parameter
s Reference to the container where fetched parameters
/// will be inserted.
void
getGlobalParameters
(
const
int
index
,
const
db
::
MySqlBindingCollection
&
in_bindings
,
...
...
@@ -595,6 +597,79 @@ public:
db
::
MySqlBinding
::
createNull
());
}
/// @brief Creates input binding for option value parameter.
///
/// @param option Option descriptor holding option for which binding is to
/// be created.
/// @return Pointer to the binding (possibly null binding if formatted
/// value is non-empty.
db
::
MySqlBindingPtr
createOptionValueBinding
(
const
OptionDescriptorPtr
&
option
);
/// @brief Retrieves a server.
///
/// @param index Index of the query to be used.
/// @param server_tag Server tag of the server to be retrieved.
/// @return Pointer to the @c Server object representing the server or
/// null if such server doesn't exist.
db
::
ServerPtr
getServer
(
const
int
index
,
const
data
::
ServerTag
&
server_tag
);
/// @brief Retrieves all servers.
///
/// @param index Index of the query to be used.
/// @param [out] servers Reference to the container where fetched servers
/// will be inserted.
void
getAllServers
(
const
int
index
,
db
::
ServerCollection
&
servers
);
/// @brief Sends query to retrieve servers.
///
/// @param index Index of the query to be used.
/// @param in_bindings Reference to the MySQL input bindings.
/// @param [out] servers Reference to the container where fetched servers
/// will be inserted.
void
getServers
(
const
int
index
,
const
db
::
MySqlBindingCollection
&
in_bindings
,
db
::
ServerCollection
&
servers
);
/// @brief Creates or updates a server.
///
/// This method attempts to insert a new server into the database using
/// the query identified by @c create_index. If the insertion fails because
/// the server with the given tag already exists in the database, the
/// existing server is updated using the query identified by the
/// @c update_index.
///
/// @param create_audit_revision Index of the query inserting audit
/// revision.
/// @param create_index Index of the INSERT query to be used.
/// @param update_index index of the UPDATE query to be used.
/// @param server Pointer to the server to be insertedor updated.
void
createUpdateServer
(
const
int
create_audit_revision_index
,
const
int
create_index
,
const
int
update_index
,
const
db
::
ServerPtr
&
server
);
/// @brief Attempts to delete a server having a given tag.
///
/// @param create_audit_revision Index of the query inserting audit
/// revision.
/// @param create_index Index of the DELETE query to be executed.
/// @param server_tag Tag of the server to be deleted.
/// @return Number of deleted servers.
uint64_t
deleteServer
(
const
int
create_audit_revision_index
,
const
int
index
,
const
std
::
string
&
server_tag
);
/// @brief Attempts to delete all servers.
///
/// This method deletes all servers added by the user. It does not
/// delete the logical server 'all'.
///
/// @param create_audit_revision Index of the query inserting audit
/// revision.
/// @param server_tag Tag of the server to be deleted.
/// @return Number of deleted servers.
uint64_t
deleteAllServers
(
const
int
create_audit_revision_index
,
const
int
index
);
/// @brief Returns backend type in the textual format.
///
/// @return "mysql".
...
...
@@ -616,14 +691,6 @@ public:
/// @return Port number on which database service is available.
uint16_t
getPort
()
const
;
/// @brief Creates input binding for option value parameter.
///
/// @param option Option descriptor holding option for which binding is to
/// be created.
/// @return Pointer to the binding (possibly null binding if formatted
/// value is non-empty.
db
::
MySqlBindingPtr
createOptionValueBinding
(
const
OptionDescriptorPtr
&
option
);
/// @brief Represents connection to the MySQL database.
db
::
MySqlConnection
conn_
;
...
...
src/hooks/dhcp/mysql_cb/mysql_cb_messages.cc
View file @
ad8a7cd7
// File created from ../../../../src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes on
Thu May 16 2019 15:00
// File created from ../../../../src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes on
Wed Jun 12 2019 14:09
#include <cstddef>
#include <log/message_types.h>
...
...
@@ -18,6 +18,8 @@ extern const isc::log::MessageID MYSQL_CB_CREATE_UPDATE_OPTION4 = "MYSQL_CB_CREA
extern
const
isc
::
log
::
MessageID
MYSQL_CB_CREATE_UPDATE_OPTION6
=
"MYSQL_CB_CREATE_UPDATE_OPTION6"
;
extern
const
isc
::
log
::
MessageID
MYSQL_CB_CREATE_UPDATE_OPTION_DEF4
=
"MYSQL_CB_CREATE_UPDATE_OPTION_DEF4"
;
extern
const
isc
::
log
::
MessageID
MYSQL_CB_CREATE_UPDATE_OPTION_DEF6
=
"MYSQL_CB_CREATE_UPDATE_OPTION_DEF6"
;
extern
const
isc
::
log
::
MessageID
MYSQL_CB_CREATE_UPDATE_SERVER4
=
"MYSQL_CB_CREATE_UPDATE_SERVER4"
;
extern
const
isc
::
log
::
MessageID
MYSQL_CB_CREATE_UPDATE_SERVER6
=
"MYSQL_CB_CREATE_UPDATE_SERVER6"
;
extern
const
isc
::
log
::
MessageID
MYSQL_CB_CREATE_UPDATE_SHARED_NETWORK4
=
"MYSQL_CB_CREATE_UPDATE_SHARED_NETWORK4"
;
extern
const
isc
::
log
::
MessageID
MYSQL_CB_CREATE_UPDATE_SHARED_NETWORK6
=
"MYSQL_CB_CREATE_UPDATE_SHARED_NETWORK6"
;
extern
const
isc
::
log
::
MessageID
MYSQL_CB_CREATE_UPDATE_SHARED_NETWORK_OPTION4
=
"MYSQL_CB_CREATE_UPDATE_SHARED_NETWORK_OPTION4"
;
...
...
@@ -95,6 +97,10 @@ extern const isc::log::MessageID MYSQL_CB_GET_ALL_OPTION_DEFS4 = "MYSQL_CB_GET_A
extern
const
isc
::
log
::
MessageID
MYSQL_CB_GET_ALL_OPTION_DEFS4_RESULT
=
"MYSQL_CB_GET_ALL_OPTION_DEFS4_RESULT"
;
extern
const
isc
::
log
::
MessageID
MYSQL_CB_GET_ALL_OPTION_DEFS6
=
"MYSQL_CB_GET_ALL_OPTION_DEFS6"
;
extern
const
isc
::
log
::
MessageID
MYSQL_CB_GET_ALL_OPTION_DEFS6_RESULT
=
"MYSQL_CB_GET_ALL_OPTION_DEFS6_RESULT"
;
extern
const
isc
::
log
::
MessageID
MYSQL_CB_GET_ALL_SERVERS4
=
"MYSQL_CB_GET_ALL_SERVERS4"
;