09-12-2024 07:01 AM
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": {}
}
]
}
}
]
}
}
10-23-2024 03:51 AM
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:
Set Up Your Environment:
pip install cobra |
2. Create a Python Script:
from cobra.mit.access import MoDirectory # APIC credentials and URL # Login to APIC # Query for all node profiles # Print the configuration of each node profile # Logout from APIC |
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.
11-04-2024 11:30 PM
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'
11-05-2024 11:07 PM
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:
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.
API Limitations: There might be limitations or bugs in the API or the SDK (Cobra) that prevent the propInclude parameter from working as expected.
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:
Ensure that you are setting the propInclude parameter correctly in your query. Here is an example of how to set it:
If you are using lookupByClass, you can also set the propInclude parameter:
Refer to the official API documentation to ensure that the propInclude parameter is supported for the specific class and query type you are using.
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:
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.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide