Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | import fnmatch |
| 3 | import logging |
| 4 | |
| 5 | class sflow_sub_record: |
| 6 | def __init__(self,scheme,app_id,app_ip,app_port,subscription_info,sub_info_filter): |
| 7 | logging.debug("* Updating subscription_info ") |
| 8 | self.scheme = scheme |
| 9 | self.app_id = app_id |
| 10 | self.ipaddress = app_ip |
| 11 | self.portno = app_port |
| 12 | self.subscription_info = subscription_info |
| 13 | self.sub_info_filter = sub_info_filter |
| 14 | |
| 15 | sflow_sub_database=[] |
| 16 | def add_sflow_sub_record(record): |
| 17 | logging.info("* inside %s",add_sflow_sub_record.__name__) |
| 18 | if not sflow_sub_database: |
| 19 | logging.debug("* -----------List is EMpty -------------") |
| 20 | sflow_sub_database.append(record) |
| 21 | logging.debug("* Subscription is sucessful") |
| 22 | return "Subscription is sucessful \n" |
| 23 | for x in sflow_sub_database: |
| 24 | if (record.ipaddress == x.ipaddress) and (record.portno == x.portno) : |
| 25 | logging.warning("* entry already exists\n") |
| 26 | return "entry already exists \n" |
| 27 | sflow_sub_database.append(record) |
| 28 | return "Subscription is sucessful \n" |
| 29 | |
| 30 | def delete_sflow_sub_record(ip,port): |
| 31 | logging.info("* inside %s",delete_sflow_sub_record.__name__) |
| 32 | Flag = False |
| 33 | for x in sflow_sub_database: |
| 34 | if (ip == x.ipaddress) and (port == x.portno) : |
| 35 | sflow_sub_database.remove(x) |
| 36 | Flag = True |
| 37 | logging.debug("* Un-Subscription is sucessful") |
| 38 | return "Un-Subscription is sucessful \n" |
| 39 | if not Flag : |
| 40 | err_str = "No subscription exists with target: udp://" + ip + ":" + str(port) + "\n" |
| 41 | logging.error(err_str) |
| 42 | raise Exception (err_str) |
| 43 | |
| 44 | def print_sflow_sub_records(): |
| 45 | logging.info("* inside %s",print_sflow_sub_records.__name__) |
| 46 | for obj in sflow_sub_database: |
| 47 | logging.debug("* ------------------------------------------------") |
| 48 | logging.debug("* scheme:%s",obj.scheme) |
| 49 | logging.debug("* app_id:%s",obj.app_id) |
| 50 | logging.debug("* portno:%s",obj.portno ) |
| 51 | logging.debug("* ipaddress:%s",obj.ipaddress) |
| 52 | logging.debug("* portno:%s",obj.portno) |
| 53 | logging.debug("* subscription_info:%s",obj.subscription_info) |
| 54 | logging.debug("* sub_info_filter:%s",obj.sub_info_filter) |
| 55 | logging.debug("* ------------------------------------------------") |
| 56 | |
| 57 | def get_sflow_sub_records(notif_subscription_info): |
| 58 | logging.info("* inside %s",get_sflow_sub_records.__name__) |
| 59 | sub_list=[] |
| 60 | for obj in sflow_sub_database: |
| 61 | if obj.subscription_info == notif_subscription_info: |
| 62 | sub_list.append(obj) |
| 63 | return sub_list |