本文整理汇总了Python中filter.Filter.destroy_tc_rules方法的典型用法代码示例。如果您正苦于以下问题:Python Filter.destroy_tc_rules方法的具体用法?Python Filter.destroy_tc_rules怎么用?Python Filter.destroy_tc_rules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类filter.Filter
的用法示例。
在下文中一共展示了Filter.destroy_tc_rules方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TShapper
# 需要导入模块: from filter import Filter [as 别名]
# 或者: from filter.Filter import destroy_tc_rules [as 别名]
class TShapper(Thread):
N_TOKENS = 8000
SLEEP_INTERVAL = 2 #Seconds
FILTER_DELETE_INTERVAL = 30 #Seconds
OLD_DEVICES_TIMEOUT = 300 #Seconds
USE_SNMP = False
def __init__(self):
Thread.__init__(self)
logging.basicConfig(filename='trottle.log',level=logging.DEBUG)
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',\
datefmt='%m/%d/%Y %I:%M:%S %p')
self.stopped = False
self.active_filters = 0
self.filter_delete_counter = 0
self.tokens = list()
self.devices = dict()
self.max_devices = {
'Number': 0,
'Time' : datetime.now()
}
self.speed = {
'Down' : 0,
'Up' : 0,
'Last_Update' : datetime.now()
}
self.filter = Filter()
self.generate_tokens()
if self.USE_SNMP:
self.SNMPDetector = SNMPDetector()
self.SNMPDetector.start()
def generate_tokens(self):
for i in range(1, self.N_TOKENS+1):
self.tokens.append(i)
def get_token(self):
return self.tokens.pop(0)
def release_token(self, token):
self.tokens.append(token)
def stop(self):
self.stopped = True
#Deletes the TC Rules
self.filter.destroy_tc_rules()
if self.USE_SNMP:
self.SNMPDetector.stop()
def restart(self):
#Deletes the TC Rules
self.filter.destroy_tc_rules()
#Restarts Objects
self.__init__()
#Starts the new TC Rules
self.filter.init_tc_rules()
def run(self):
#Starts the new TC Rules
self.filter.init_tc_rules()
#Updates the TC Rules
while not self.stopped:
try:
self.update()
except KernelError as e:
cprint("KERNEL ERROR: Restarting ", 'red')
logging.warning("KernelError:"+str(e))
sleep(2)
self.restart()
sleep(self.SLEEP_INTERVAL)
def update(self):
#cprint("Update", 'white')
if self.USE_SNMP:
updated_devices = self.get_devices_adresses_from_snmp()
else:
updated_devices = self.get_devices_adresses()
for device_mac, ips in updated_devices.items():
self.update_device(device_mac, ips)
self.clean_old_devices()
if len(self.devices) > self.max_devices['Number']:
self.max_devices['Number'] = len(self.devices)
self.max_devices['Time'] = datetime.now()
cprint("Current Clients/Max:"+str(len(self.devices))+"/"+\
#.........这里部分代码省略.........