Featured image of post ACI - Delete multiple objects by DN on the APIC

ACI - Delete multiple objects by DN on the APIC

Easy way to delete multiple objects via DN directly on the APIC

Home / Posts / ACI - Delete multiple objects by DN on the APIC

Usecase

You have multiple objects identified that you want to delete, for example a bunch of EPGs, some static bindings, etc. For these objects you got a DN, maybe through a moquery command.

In our example we want to delete all the EPGs in the “Network” Tenant, that have an “X” in them.

EPG overview in Tenant “Network”

With an easy moquery command we can find the DNs of our objects.

1
2
3
APIC1# moquery -c fvAEPg | grep "dn" | grep "X"
dn                   : uni/tn-Network/ap-AP/epg-7-X
dn                   : uni/tn-Network/ap-AP/epg-8-X

If you want to learn more about Moquery, check out my detailed post..

Delete multiple objects by DN

Alright, we got our DNs, through whatever means :) Now we add them to a file, which we then use to delete them. You can name the file howere you want, I go for a simple dn.txt here. Then but the DNs in it.

1
2
3
APIC1# cat dn.txt
uni/tn-Network/ap-AP/epg-7-X
uni/tn-Network/ap-AP/epg-8-X

Now we are ready to launch the magic and delete the DNs from the APIC.

Please be careful! Make sure that you understand what this script does before you launch it! I can’t and won’t take any responsibility for this script and the output of it

We cat the file and then loop over each line and assume it’s a DN. With the help of icurl we delete it then from the fabric.

1
cat dn.txt | while read f; do icurl -k -X DELETE https://localhost/api/mo/"${f}".json; done;

That’s it, the DNs are gone for good! This can be really helpful if you got a lot of DNs to delete 👍

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy