Ejemplo n.º 1
0
 def __init__(self, info):
     self.namespaces = None
     self.path = None
     if isinstance(info, dict):
         p1 = '#text'
         p2 = '@xmlns'
         try:
             path = info[p1]
             namespaces = []
             for k, v in info.items():
                 if k.startswith(p2):
                     pfx = yang_nsname_to_prefix(v)
                     d = {'ns': v, 'pfx': pfx}
                     namespaces.append(d)
                     nickname = k.split(':')[-1]
                     path = path.replace(nickname, pfx)
             self.namespaces = namespaces
             self.path = path
         except:
             msg = "DEBUG: failed to process info '%s'" % info
             dbg_print(msg)
     elif isinstance(info, basestring):
         self.path = info
     else:
         msg = "DEBUG: info=%s, " \
               "unexpected data format '%s'" % (info, type(info))
         dbg_print(msg)
Ejemplo n.º 2
0
 def __init__(self, info):
     self.namespaces = None
     self.path = None
     if isinstance(info, dict):
         p1 = '#text'
         p2 = '@xmlns'
         try:
             path = info[p1]
             namespaces = []
             for k, v in info.items():
                 if k.startswith(p2):
                     pfx = yang_nsname_to_prefix(v)
                     d = {'ns': v, 'pfx': pfx}
                     namespaces.append(d)
                     nickname = k.split(':')[-1]
                     path = path.replace(nickname, pfx)
             self.namespaces = namespaces
             self.path = path
         except:
             msg = "DEBUG: failed to process info '%s'" % info
             dbg_print(msg)
     elif isinstance(info, basestring):
         self.path = info
     else:
         msg = "DEBUG: info=%s, " \
               "unexpected data format '%s'" % (info, type(info))
         dbg_print(msg)
Ejemplo n.º 3
0
 def __init__(self, event):
     p = 'path'
     if isinstance(event, dict):
         for k, v in event.items():
             if k == p:
                 self.path_info = PathInfo(v)
             else:
                 setattr(self, k, v)
     else:
         msg = "DEBUG: event=%s, " \
               "unexpected data format '%s'" % (event, type(event))
         dbg_print(msg)
Ejemplo n.º 4
0
 def __init__(self, event):
     p = 'path'
     if isinstance(event, dict):
         for k, v in event.items():
             if k == p:
                 self.path_info = PathInfo(v)
             else:
                 setattr(self, k, v)
     else:
         msg = "DEBUG: event=%s, " \
               "unexpected data format '%s'" % (event, type(event))
         dbg_print(msg)
Ejemplo n.º 5
0
    def __init__(self, event):
        self.added_switches = []
        self.removed_switches = []
        self.added_hosts = []
        self.removed_hosts = []
        self.added_links = []
        self.removed_links = []

        d = xmltodict.parse(event)
        try:
            p1 = 'notification'
            notification = d[p1]

            p2 = 'eventTime'
            self.timestamp = notification[p2]

            self.events = []
            p3 = 'data-changed-notification'
            p4 = 'data-change-event'
            events = notification[p3][p4]
            if isinstance(events, list):
                for item in events:
                    tc_evt = TopoChangeEvent(item)
                    self.events.append(tc_evt)
            elif isinstance(events, dict):
                tc_evt = TopoChangeEvent(events)
                self.events.append(tc_evt)
            else:
                msg = "DEBUG: events=%s, " \
                      "unexpected data format '%s'" % (events, type(events))
                dbg_print(msg)

            for event in self.events:
                if event.created():
                    if event.is_switch():
                        self.added_switches.append(event.get_node_id())
                    elif event.is_host():
                        self.added_hosts.append(event.get_node_id())
                    elif event.is_link():
                        self.added_links.append(event.get_link_id())
                elif event.deleted():
                    if event.is_switch():
                        self.removed_switches.append(event.get_node_id())
                    elif event.is_host():
                        self.removed_hosts.append(event.get_node_id())
                    elif event.is_link():
                        self.removed_links.append(event.get_link_id())
        except(Exception):
            msg = "DEBUG: failed to process event '%s'" % event
            dbg_print(msg)
Ejemplo n.º 6
0
    def __init__(self, event):
        self.added_switches = []
        self.removed_switches = []
        self.added_hosts = []
        self.removed_hosts = []
        self.added_links = []
        self.removed_links = []

        d = xmltodict.parse(event)
        try:
            p1 = 'notification'
            notification = d[p1]

            p2 = 'eventTime'
            self.timestamp = notification[p2]

            self.events = []
            p3 = 'data-changed-notification'
            p4 = 'data-change-event'
            events = notification[p3][p4]
            if isinstance(events, list):
                for item in events:
                    tc_evt = TopoChangeEvent(item)
                    self.events.append(tc_evt)
            elif isinstance(events, dict):
                tc_evt = TopoChangeEvent(events)
                self.events.append(tc_evt)
            else:
                msg = "DEBUG: events=%s, " \
                      "unexpected data format '%s'" % (events, type(events))
                dbg_print(msg)

            for event in self.events:
                if event.created():
                    if event.is_switch():
                        self.added_switches.append(event.get_node_id())
                    elif event.is_host():
                        self.added_hosts.append(event.get_node_id())
                    elif event.is_link():
                        self.added_links.append(event.get_link_id())
                elif event.deleted():
                    if event.is_switch():
                        self.removed_switches.append(event.get_node_id())
                    elif event.is_host():
                        self.removed_hosts.append(event.get_node_id())
                    elif event.is_link():
                        self.removed_links.append(event.get_link_id())
        except(Exception):
            msg = "DEBUG: failed to process event '%s'" % event
            dbg_print(msg)
Ejemplo n.º 7
0
    def __init__(self, event):
        self.added_nodes = []
        self.removed_nodes = []
        self.added_flows = []
        self.removed_flows = []

        d = xmltodict.parse(event)
        try:
            p1 = 'notification'
            notification = d[p1]

            p2 = 'eventTime'
            self.timestamp = notification[p2]

            self.events = []
            p3 = 'data-changed-notification'
            p4 = 'data-change-event'
            events = notification[p3][p4]
            if isinstance(events, list):
                for item in events:
                    evt = InventoryChangeEvent(item)
                    self.events.append(evt)
            elif isinstance(events, dict):
                evt = InventoryChangeEvent(events)
                self.events.append(evt)
            else:
                msg = "DEBUG: events=%s, " \
                      "unexpected data format '%s'" % (events, type(events))
                dbg_print(msg)

            for event in self.events:
                if event.created():
                    if event.is_node():
                        self.added_nodes.append(event.get_node_id())
                    elif event.is_flow_entry():
                        flow_info = FlowInfo(event)
                        self.added_flows.append(flow_info)
                elif event.deleted():
                    if event.is_node():
                        self.removed_nodes.append(event.get_node_id())
                    elif event.is_flow_entry():
                        flow_info = FlowInfo(event)
                        self.removed_flows.append(flow_info)
        except(Exception) as e:
            print "Error, %s" % e
Ejemplo n.º 8
0
    def __init__(self, event):
        self.added_nodes = []
        self.removed_nodes = []
        self.added_flows = []
        self.removed_flows = []

        d = xmltodict.parse(event)
        try:
            p1 = 'notification'
            notification = d[p1]

            p2 = 'eventTime'
            self.timestamp = notification[p2]

            self.events = []
            p3 = 'data-changed-notification'
            p4 = 'data-change-event'
            events = notification[p3][p4]
            if isinstance(events, list):
                for item in events:
                    evt = InventoryChangeEvent(item)
                    self.events.append(evt)
            elif isinstance(events, dict):
                evt = InventoryChangeEvent(events)
                self.events.append(evt)
            else:
                msg = "DEBUG: events=%s, " \
                      "unexpected data format '%s'" % (events, type(events))
                dbg_print(msg)

            for event in self.events:
                if event.created():
                    if event.is_node():
                        self.added_nodes.append(event.get_node_id())
                    elif event.is_flow_entry():
                        flow_info = FlowInfo(event)
                        self.added_flows.append(flow_info)
                elif event.deleted():
                    if event.is_node():
                        self.removed_nodes.append(event.get_node_id())
                    elif event.is_flow_entry():
                        flow_info = FlowInfo(event)
                        self.removed_flows.append(flow_info)
        except(Exception) as e:
            print "Error, %s" % e
Ejemplo n.º 9
0
    def __init__(self, event):
        self.node_id = None
        self.table_id = None
        self.flow_id = None

        if isinstance(event, InventoryChangeEvent) and event.is_flow_entry():
            path = event.get_path()
            try:
                chunks = path.split('/')
                l = []
                p = ':id='
                for s in chunks:
                    idx = s.find(p)
                    if idx >= 0:
                        l.append(s[idx + len(p):].translate(None, "'[]"))
                self.node_id = l[0]
                self.table_id = l[1]
                self.flow_id = l[2]
            except(Exception):
                msg = "DEBUG: unexpected string format: %s" % path
                dbg_print(msg)
        else:
            msg = "wrong class usage"
            dbg_print(msg)
Ejemplo n.º 10
0
    def __init__(self, event):
        self.node_id = None
        self.table_id = None
        self.flow_id = None

        if isinstance(event, InventoryChangeEvent) and event.is_flow_entry():
            path = event.get_path()
            try:
                chunks = path.split('/')
                l = []
                p = ':id='
                for s in chunks:
                    idx = s.find(p)
                    if idx >= 0:
                        l.append(s[idx + len(p):].translate(None, "'[]"))
                self.node_id = l[0]
                self.table_id = l[1]
                self.flow_id = l[2]
            except(Exception):
                msg = "DEBUG: unexpected string format: %s" % path
                dbg_print(msg)
        else:
            msg = "wrong class usage"
            dbg_print(msg)