예제 #1
0
 def __del_handler_validate(self, key):
     """
     Validate "DEL" method parameters
     :param key: a key of "DEL" message
     :return: True if parameters are valid, False if parameters are invalid
     """
     if not self.key_re.match(key):
         log_err(
             "BGPAllowListMgr::Received BGP ALLOWED 'DEL' message with invalid key: '$s'"
             % key)
         return False
     return True
예제 #2
0
 def remove_slot(self, db, table):
     """
     Remove an object from the storage
     :param db: db name
     :param table: table name
     """
     slot = self.get_slot_name(db, table)
     if slot in self.data:
         del self.data[slot]
     else:
         log_err(
             "Directory: Can't remove slot '%s'. The slot doesn't exist" %
             slot)
예제 #3
0
 def remove(self, db, table, key):
     """
     Remove a value from the storage
     :param db: db name
     :param table: table name
     :param key: key to remove
     """
     slot = self.get_slot_name(db, table)
     if slot in self.data:
         if key in self.data[slot]:
             del self.data[slot][key]
         else:
             log_err(
                 "Directory: Can't remove key '%s' from slot '%s'. The key doesn't exist"
                 % (key, slot))
     else:
         log_err(
             "Directory: Can't remove key '%s' from slot '%s'. The slot doesn't exist"
             % (key, slot))
예제 #4
0
 def __set_handler_validate(self, key, data):
     """
     Validate parameters of a "Set" message
     :param key: ket of the 'SET' message
     :param data: data of the 'SET' message
     :return: True if parameters are valid, False if parameters are invalid
     """
     if data is None:
         log_err(
             "BGPAllowListMgr::Received BGP ALLOWED 'SET' message without data"
         )
         return False
     if not self.key_re.match(key):
         log_err(
             "BGPAllowListMgr::Received BGP ALLOWED 'SET' message with invalid key: '%s'"
             % key)
         return False
     prefixes_v4 = []
     prefixes_v6 = []
     if "prefixes_v4" in data:
         prefixes_v4 = str(data["prefixes_v4"]).split(",")
         if not all(
                 TemplateFabric.is_ipv4(prefix) for prefix in prefixes_v4):
             arguments = "prefixes_v4", str(data["prefixes_v4"])
             log_err(
                 "BGPAllowListMgr::Received BGP ALLOWED 'SET' message with invalid input[%s]:'%s'"
                 % arguments)
             return False
     if "prefixes_v6" in data:
         prefixes_v6 = str(data["prefixes_v6"]).split(",")
         if not all(
                 TemplateFabric.is_ipv6(prefix) for prefix in prefixes_v6):
             arguments = "prefixes_v6", str(data["prefixes_v6"])
             log_err(
                 "BGPAllowListMgr::Received BGP ALLOWED 'SET' message with invalid input[%s]:'%s'"
                 % arguments)
             return False
     if not prefixes_v4 and not prefixes_v6:
         log_err(
             "BGPAllowListMgr::Received BGP ALLOWED 'SET' message with no prefixes specified: %s"
             % str(data))
         return False
     return True
예제 #5
0
 def handler(self, key, op, data):
     """
     This method is executed on each add/remove event on the table.
     :param key: key of the table entry
     :param op: operation on the table entry. Could be either 'SET' or 'DEL'
     :param data: associated data of the event. Empty for 'DEL' operation.
     """
     if op == swsscommon.SET_COMMAND:
         if self.directory.available_deps(self.deps):  # all required dependencies are set in the Directory?
             res = self.set_handler(key, data)
             if not res:  # set handler returned False, which means it is not ready to process is. Save it for later.
                 log_debug("'SET' handler returned NOT_READY for the Manager: %s" % self.__class__)
                 self.set_queue.append((key, data))
         else:
             log_debug("Not all dependencies are met for the Manager: %s" % self.__class__)
             self.set_queue.append((key, data))
     elif op == swsscommon.DEL_COMMAND:
         self.del_handler(key)
     else:
         log_err("Invalid operation '%s' for key '%s'" % (op, key))
예제 #6
0
 def del_handler(self, key):
     """ Placeholder for 'DEL' command """
     log_err("del_handler wasn't implemented for %s" % self.__class__.__name__)
예제 #7
0
 def set_handler(self, key, data):
     """ Placeholder for 'SET' command """
     log_err("set_handler() wasn't implemented for %s" % self.__class__.__name__)