Exemple #1
0
def analyze_inventory(nodeId, isConfig=True, ncId=None, ifName=None):
    if isConfig:
        nodes = dsg.get_inventory_config()
        print "Inventory Config:"
    else:
        print "Inventory Operational:"
        nodes = dsg.get_inventory_oper()
    node = nodes.get(nodeId)
    tables = node.get(const.NODE_TABLE)
    groups = node.get(const.NODE_GROUP)
    flow_list = []
    print "Flows:"
    for table in tables:
        for flow in table.get('flow'):
            if not ifName or ifName in utils.nstr(flow.get('flow-name')):
                flow_dict = {}
                flow_dict['table'] = table['id']
                flow_dict['id'] = flow['id']
                flow_dict['name'] = flow.get('flow-name')
                flow_dict['flow'] = flow
                flow_list.append(flow_dict)
    flows = sorted(flow_list, key=lambda x: x['table'])
    for flow in flows:
        print 'Table:', flow['table']
        print 'FlowId:', flow['id'], 'FlowName:', flow.get('name')
Exemple #2
0
def show_all_groups():
    of_nodes = dsg.get_inventory_config()
    groups = get_groups(of_nodes)
    for dpn in groups:
        for group_key in groups[dpn]:
            print 'Dpn:', dpn, 'ID:', group_key, 'Group:', json.dumps(
                groups[dpn][group_key])
Exemple #3
0
def show_all_tables():
    of_nodes = dsg.get_inventory_config()
    tables = set()
    for node in of_nodes.itervalues():
        for table in node[const.NODE_TABLE]:
            if table.get('flow'):
                tables.add(table['id'])
    print list(tables)
Exemple #4
0
def get_groups(ofnodes=None):
    of_nodes = ofnodes or dsg.get_inventory_config()
    key = 'group-id'
    group_dict = collections.defaultdict(dict)
    for node in of_nodes.itervalues():
        dpnid = utils.get_dpn_from_ofnodeid(node['id'])
        for group in node[const.NODE_GROUP]:
            if group_dict.get(dpnid) and group_dict.get(dpnid).get(group[key]):
                print 'Duplicate:', dpnid, group[key]
            group_dict[dpnid][group[key]] = group
    return dict(group_dict)
Exemple #5
0
def get_all_flows(modules=['ifm']):
    if not modules:
        return 'No modules specified'
    ifaces = {}
    ifstates = {}
    ifindexes = {}
    bindings = {}
    einsts = {}
    eifaces = {}
    fibentries = {}
    vpnids = {}
    vpninterfaces = {}
    groups = {}
    if 'all' in modules:
        table_list = list(range(0, 255))
    else:
        table_list = list(
            set([
                table for module in modules
                for table in const.TABLE_MAP[module]
            ]))
    ##table_list = [214, 244]
    of_nodes = dsg.get_inventory_config()
    if 'ifm' in modules:
        ifaces = dsg.get_config_interfaces()
        ifstates = dsg.get_interface_states()
    if 'l3vpn' in modules:
        ifaces = ifaces or dsg.get_config_interfaces()
        ifindexes = ifindexes or dsg.get_ifindexes()
        fibentries = fibentries or dsg.get_fibentries_by_label()
        vpnids = vpnids or dsg.get_vpnids()
        vpninterfaces = vpninterfaces or dsg.get_vpninterfaces()
        groups = groups or get_groups(of_nodes)
    if 'acl' in modules:
        ifaces = ifaces or dsg.get_config_interfaces()
        ifindexes = ifindexes or dsg.get_ifindexes()
        einsts = einsts or dsg.get_elan_instances()
        eifaces = eifaces or dsg.get_elan_interfaces()
    if 'elan' in modules:
        ifaces = ifaces or dsg.get_config_interfaces()
        einsts = einsts or dsg.get_elan_instances()
        eifaces = eifaces or dsg.get_elan_interfaces()
        ifindexes = ifindexes or dsg.get_ifindexes()
    if 'all' in modules:
        groups = groups or get_groups(of_nodes)
        ifaces = ifaces or dsg.get_config_interfaces()
        ifstates = ifstates or dsg.get_interface_states()
        ifindexes = ifindexes or dsg.get_ifindexes()
        fibentries = fibentries or dsg.get_fibentries_by_label()
        vpnids = vpnids or dsg.get_vpnids()
        vpninterfaces = vpninterfaces or dsg.get_vpninterfaces()
        einsts = einsts or dsg.get_elan_instances()
        eifaces = eifaces or dsg.get_elan_interfaces()
    flows = []
    for node in of_nodes.itervalues():
        tables = [x for x in node[const.NODE_TABLE] if x['id'] in table_list]
        for table in tables:
            for flow in table.get('flow', []):
                flow_dict = None
                flow_info = {}
                flow_info['dpnid'] = utils.get_dpn_from_ofnodeid(node['id'])
                flow_dict = fp.get_any_flow(flow, flow_info, groups, ifaces,
                                            ifstates, ifindexes, fibentries,
                                            vpnids, vpninterfaces, einsts,
                                            eifaces)
                if flow_dict is not None:
                    flows.append(flow_dict)
    return flows