-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a9aa08
commit 5890376
Showing
5 changed files
with
263 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from .manager import Manager | ||
from .log import log_err, log_debug | ||
|
||
ROUTE_MAPS = ["FROM_SDN_SLB_ROUTES"] | ||
|
||
|
||
class RouteMapMgr(Manager): | ||
"""This class add route-map when BGP_PROFILE_TABLE in APPL_DB is updated""" | ||
|
||
def __init__(self, common_objs, db, table): | ||
""" | ||
Initialize the object | ||
:param common_objs: common object dictionary | ||
:param db: name of the db | ||
:param table: name of the table in the db | ||
""" | ||
super(RouteMapMgr, self).__init__( | ||
common_objs, | ||
[], | ||
db, | ||
table, | ||
) | ||
|
||
def set_handler(self, key, data): | ||
log_debug("BGPRouteMapMgr:: set handler") | ||
"""Only need a name as the key, and community id as the data""" | ||
if not self.__set_handler_validate(key, data): | ||
return True | ||
|
||
self.__update_rm(key, data) | ||
return True | ||
|
||
def del_handler(self, key): | ||
log_debug("BGPRouteMapMgr:: del handler") | ||
if not self.__del_handler_validate(key): | ||
return | ||
self.__remove_rm(key) | ||
|
||
def __remove_rm(self, rm): | ||
cmds = ["no route-map %s permit 100" % ("%s_RM" % rm)] | ||
log_debug("BGPRouteMapMgr:: remove route-map %s" % ("%s_RM" % rm)) | ||
self.cfg_mgr.push_list(cmds) | ||
log_debug("BGPRouteMapMgr::Done") | ||
|
||
def __set_handler_validate(self, key, data): | ||
if key not in ROUTE_MAPS: | ||
log_err("BGPRouteMapMgr:: Invalid key for route-map %s" % key) | ||
return False | ||
|
||
if not data: | ||
log_err("BGPRouteMapMgr:: data is None") | ||
return False | ||
community_ids = data["community_id"].split(":") | ||
try: | ||
if ( | ||
len(community_ids) != 2 | ||
or int(community_ids[0]) not in range(0, 65536) | ||
or int(community_ids[1]) not in range(0, 65536) | ||
): | ||
log_err("BGPRouteMapMgr:: data %s doesn't include valid community id %s" % (data, community_ids)) | ||
return False | ||
except ValueError: | ||
log_err("BGPRouteMapMgr:: data %s includes illegal input" % (data)) | ||
return False | ||
|
||
return True | ||
|
||
def __del_handler_validate(self, key): | ||
if key not in ROUTE_MAPS: | ||
log_err("BGPRouteMapMgr:: Invalid key for route-map %s" % key) | ||
return False | ||
return True | ||
|
||
def __update_rm(self, rm, data): | ||
cmds = ["route-map %s permit 100" % ("%s_RM" % rm), " set community %s" % data["community_id"]] | ||
log_debug("BGPRouteMapMgr:: update route-map %s community %s" % ("%s_RM" % rm, data["community_id"])) | ||
self.cfg_mgr.push_list(cmds) | ||
log_debug("BGPRouteMapMgr::Done") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.