cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
373
Views
0
Helpful
3
Replies

Reading Configuration of Node Profiles, using Cobra

rhanisch_01
Level 1
Level 1

I want to read the configuration of all node profiles in a fabric using Cobra.
For this purpose, I have written two small functions for testing. One with dnquery and the other with lookupbyClass.
With both, I get the same result.
With both, I have the same problem: all associated classes and children are read, but the 'config-only' attributes from the classes and children are missing.
Does anyone have any idea what I might be doing wrong?

 

def get_aci_node_profile_dn_query(moDir: MoDirectory):
    dnQuery = DnQuery('uni/tn-my_tenant_ten/out-to_esg-t-vpc-001_l3o/lnodep-to_esg-vpc-001-dc4_lnpr')
    
    dnQuery.subtree = 'full'
    dnQuery.propInclude = 'config-only'
    
    l3extLNodeP = moDir.query(dnQuery)
    for NodeP in l3extLNodeP:
        json_str = toJSONStr(NodeP)
        json_dict = json.loads(json_str)
        print (json_str)
        #print(json.dumps(json_dict, indent=2))
		
def get_aci_node_profile_lookup(moDir: MoDirectory, **query_options):
    query_options = {
    "queryTarget": "subtree",
    "subtree": "full",
    "propInclude": "all"
        }
    l3extLNodeP = moDir.lookupByClass("l3extLIfP", 
                parentDn='uni/tn-my_tenant_ten/out-to_esg-t-vpc-001_l3o/lnodep-to_esg-vpc-001-dc4_lnpr',
                **query_options
                )
    for NodeP in l3extLNodeP:
            json_str = toJSONStr(NodeP)
            json_dict = json.loads(json_str)
    print (json_dict)
  Output:
  
{
    "l3extLNodeP": {
        "attributes": {
            "name": "to_esg-vpc-001-dc4_lnpr"
        },
        "children": [
            {
                "l3extRsNodeL3OutAtt": {
                    "attributes": {
                        "tDn": "topology/pod-3/node-2312"
                    },
                    "children": [
                        {
                            "l3extInfraNodeP": {}
                        }
                    ]
                }
            },
            {
                "l3extRsNodeL3OutAtt": {
                    "attributes": {
                        "tDn": "topology/pod-3/node-2311"
                    },
                    "children": [
                        {
                            "l3extInfraNodeP": {}
                        }
                    ]
                }
            },
            {
                "l3extLIfP": {
                    "attributes": {
                        "name": "to_esg-vpc-001-dc4_lipr"
                    },
                    "children": [
                        {
                            "l3extRsPathL3OutAtt": {
                                "attributes": {
                                    "tDn": "topology/pod-3/protpaths-2311-2312/pathep-[v5-a_dialog_ipg]"
                                },
                                "children": [
                                    {
                                        "l3extMember": {
                                            "attributes": {
                                                "side": "A"
                                            }
                                        }
                                    },
                                    {
                                        "l3extMember": {
                                            "attributes": {
                                                "side": "B"
                                            }
                                        }
                                    },
                                    {
                                        "bgpPeerP": {
                                            "attributes": {
                                                "addr": "192.168.253.142"
                                            },
                                            "children": [
                                                {
                                                    "bgpRsPeerPfxPol": {}
                                                },
                                                {
                                                    "bgpLocalAsnP": {}
                                                },
                                                {
                                                    "bgpAsP": {}
                                                }
                                            ]
                                        }
                                    },
                                    {
                                        "bgpPeerP": {
                                            "attributes": {
                                                "addr": "192.168.253.141"
                                            },
                                            "children": [
                                                {
                                                    "bgpRsPeerPfxPol": {}
                                                },
                                                {
                                                    "bgpLocalAsnP": {}
                                                },
                                                {
                                                    "bgpAsP": {}
                                                }
                                            ]
                                        }
                                    }
                                ]
                            }
                        },
                        {
                            "l3extRsPathL3OutAtt": {
                                "attributes": {
                                    "tDn": "topology/pod-3/protpaths-2311-2312/pathep-[v5-b_dialog_ipg]"
                                },
                                "children": [
                                    {
                                        "l3extMember": {
                                            "attributes": {
                                                "side": "B"
                                            }
                                        }
                                    },
                                    {
                                        "l3extMember": {
                                            "attributes": {
                                                "side": "A"
                                            }
                                        }
                                    },
                                    {
                                        "bgpPeerP": {
                                            "attributes": {
                                                "addr": "192.168.253.141"
                                            },
                                            "children": [
                                                {
                                                    "bgpRsPeerPfxPol": {}
                                                },
                                                {
                                                    "bgpLocalAsnP": {}
                                                },
                                                {
                                                    "bgpAsP": {}
                                                }
                                            ]
                                        }
                                    },
                                    {
                                        "bgpPeerP": {
                                            "attributes": {
                                                "addr": "192.168.253.142"
                                            },
                                            "children": [
                                                {
                                                    "bgpRsPeerPfxPol": {}
                                                },
                                                {
                                                    "bgpLocalAsnP": {}
                                                },
                                                {
                                                    "bgpAsP": {}
                                                }
                                            ]
                                        }
                                    }
                                ]
                            }
                        },
                        {
                            "l3extRsNdIfPol": {}
                        },
                        {
                            "l3extRsLIfPCustQosPol": {}
                        },
                        {
                            "l3extRsIngressQosDppPol": {}
                        },
                        {
                            "l3extRsEgressQosDppPol": {}
                        },
                        {
                            "l3extRsArpIfPol": {}
                        }
                    ]
                }
            }
        ]
    }
}

 

 

3 Replies 3

AshSe
Level 4
Level 4

Dear @rhanisch_01 , May I suggest you below method to read the configuration of all node profiles in a fabric using Cobra.

To read the configuration of all node profiles in a Cisco ACI fabric using Cobra, you need to follow these steps:

  1. Set Up Your Environment:

    • Ensure you have Python installed on your system.
    • Install the Cobra SDK. You can do this using pip:

     

    pip install cobra

     

    2. Create a Python Script:

    • Create a Python script to connect to the APIC and retrieve the node profiles. Below is an example script that demonstrates how to do this:

    from cobra.mit.access import MoDirectory
    from cobra.mit.session import LoginSession
    from cobra.mit.request import ClassQuery
    from cobra.model.fabric import NodeIdentP

    # APIC credentials and URL
    apic_url = 'https://<APIC_IP>'
    username = '<username>'
    password = '<password>'

    # Login to APIC
    session = LoginSession(apic_url, username, password)
    mo_dir = MoDirectory(session)
    mo_dir.login()

    # Query for all node profiles
    query = ClassQuery('fabricNodeIdentP')
    node_profiles = mo_dir.query(query)

    # Print the configuration of each node profile
    for node_profile in node_profiles:
    print(f"Node Profile: {node_profile.name}")
    print(f" Node ID: {node_profile.nodeId}")
    print(f" Node Role: {node_profile.role}")
    print(f" Node DN: {node_profile.dn}")
    print()

    # Logout from APIC
    mo_dir.logout()

    Explanation of the Script:

    • Importing Modules: The script imports necessary modules from the Cobra SDK.
    • APIC Credentials: Replace <APIC_IP>, <username>, and <password> with your APIC's IP address, username, and password.
    • Login to APIC: The script creates a session and logs in to the APIC.
    • Query for Node Profiles: The script creates a ClassQuery for fabricNodeIdentP to retrieve all node profiles.
    • Print Configuration: The script iterates through the retrieved node profiles and prints their configuration details.
    • Logout from APIC: The script logs out from the APIC.

    Running the Script:

    • Save the script to a file, for example, read_node_profiles.py.
    • Run the script using Python:
    •  
    python read_node_profiles.py

    This script will connect to your APIC, retrieve all node profiles, and print their configuration details. You can modify the script to include additional attributes or to format the output as needed.

Hi AshSe

Thanks for your response, but that wasn't my question. My script works fine. The question is, why is my output showing without configuration?

For example, BGP Peer Output:

"bgpPeerP": {
                                            "attributes": {
                                                "addr": "192.168.253.142"
                                            },
                                            "children": [
                                                {
                                                    "bgpRsPeerPfxPol": {}
                                                },
                                                {
                                                    "bgpLocalAsnP": {}
                                                },
                                                {
                                                    "bgpAsP": {}

Why are the child elements without configuration?

I have chosen the dn.Query "config-only" but it doesn't work, or maybe my understanding is incorrect.

dnQuery.propInclude = 'config-only'

 

When using the dnQuery with propInclude = 'config-only', it should ideally return only the configuration attributes of the objects. However, if you are not seeing the expected configuration attributes in the output, there could be a few reasons for this behavior:

  1. Scope of propInclude: The propInclude parameter might not be applied to the child objects. This means that while the parent object might be filtered to show only configuration attributes, the child objects might still include all attributes.

  2. API Limitations: There might be limitations or bugs in the API or the SDK (Cobra) that prevent the propInclude parameter from working as expected.

  3. Incorrect Usage: There might be a mistake in how the propInclude parameter is being set or used in your code.

To troubleshoot and resolve this issue, you can try the following steps:

Verify the propInclude Parameter

Ensure that you are setting the propInclude parameter correctly in your query. Here is an example of how to set it:

 

from cobra.mit.access import MoDirectory
from cobra.mit.session import LoginSession f
rom cobra.mit.request import DnQuery
 
# Login to APIC
ls = LoginSession('https://apic-ip', 'username', 'password')
md = MoDirectory(ls)
md.login()
 
# Create a dnQuery dn_query = DnQuery('uni/tn-tenant/ap-app/epg-epg')
dn_query.propInclude = 'config-only'
 
# Execute the query
result = md.query(dn_query)
 
# Process the result
for obj in result:
     print(obj.toXML())
 

 

 

Use lookupByClass with propInclude

If you are using lookupByClass, you can also set the propInclude parameter:

 

from cobra.mit.access import MoDirectory
from cobra.mit.session import LoginSession
from cobra.mit.request import ClassQuery
 
# Login to APIC
ls = LoginSession('https://apic-ip', 'username', 'password')
md = MoDirectory(ls)
md.login()
 
# Create a classQuery
class_query = ClassQuery('bgpPeerP')
class_query.propInclude = 'config-only'
 
# Execute the query
result = md.lookupByClass(class_query)
 
# Process the result
for obj in result:
      print(obj.toXML())
 

 

 

Check the API Documentation

Refer to the official API documentation to ensure that the propInclude parameter is supported for the specific class and query type you are using.

Debugging

To further debug, you can print out the raw JSON response from the APIC to see if the configuration attributes are being returned by the API:

 

import json
 
# Execute the query result = md.query(dn_query)
 
# Print the raw JSON response
print(json.dumps(result, indent=4))
 
 

Contact Support

If the issue persists, consider reaching out to Cisco support or checking the Cisco DevNet forums for any known issues or updates related to the propInclude parameter.

By following these steps, you should be able to identify why the configuration attributes are not being included in your output and take appropriate action to resolve the issue.

Review Cisco Networking for a $25 gift card

Save 25% on Day-2 Operations Add-On License