api: Added retrieve BGP sessions by ID (#7825)

* add support for retrieving BGP sessions via id

* fix syntax, use router params

* use count properly

* add get_bgp docs

* streamlined get_bgp sql query
This commit is contained in:
Lee Spottiswood
2017-11-30 22:51:20 +00:00
committed by Neil Lathwood
parent 5871ee1c67
commit e3082873f6
3 changed files with 69 additions and 0 deletions

View File

@ -506,6 +506,31 @@ function list_bgp()
}
function get_bgp()
{
check_is_read();
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$bgpPeerId = $router['id'];
if (!is_numeric($bgpPeerId)) {
api_error(400, 'Invalid id has been provided');
}
$bgp_session = dbFetchRows("SELECT * FROM `bgpPeers` WHERE `bgpPeerState` IS NOT NULL AND `bgpPeerState` != '' AND bgpPeer_id = ?", array($bgpPeerId));
$bgp_session_count = count($bgp_session);
if (!is_numeric($bgp_session_count)) {
api_error(500, 'Error retrieving BGP peer');
}
if ($bgp_session_count == 0) {
api_error(404, "BGP peer $bgpPeerId does not exist");
}
api_success($bgp_session, 'bgp_session');
}
function list_ospf()
{
check_is_read();