cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2032
Views
10
Helpful
7
Replies

ACI bulk object deletion

Qwr!
Level 1
Level 1

Having several objects with "TEMP_" for example, tenant TEMP_tenant_A, vrf TEMP_vrf_A, TEMP_LIP_A etc. 

was looking for a quick way to delete those objects. Postman is an option, but since the "TEMP_" objects are scattered all over the place, it's difficult to create and manage a collection.

The other option I came across is to via  /mit/uni/infra. I attempted to delete a file or folder containing "TEMP_" but was unsuccessful using CLI or SCP.  missed the opportunity to take a backup, so restoring is not an option for now.

for i in `find *TEMP_*`
do 
echo "removing $i" 
modelete $i
done
moconfig commit

sudo find -type d -name *TEMP_*| xargs sudo rm -rf

search and delete in winsCP

1 Accepted Solution

Accepted Solutions

RedNectar
VIP
VIP

Hi @Qwr! ,

I'm not sure if this is a question that  you'd like answered, or a contribution to help others out - because you've (almost) given the answer to your comment ...


was looking for a quick way to delete those objects. 

... when you listed the modelete method - but unfortunately as written it won't necessarily get ALL objects starting with TEMP_

So if you are looking for an answer to get ALL objects, you'll need to do this (my additions in red) - it will throw a lot of errors which you can ignore (because it's trying to delete relationships that won't exist when the objects they link to are deleted) but it will (fingers crossed) work!

apic1# bash
admin@apic1:~> cd /mit/uni/infra/
admin@apic1:infra~> for i in `find . -name *TEMP_*`
> do 
> echo "removing $i" 
> modelete $i
> done
# POTENTIALLY LOTS OF OUTPUT #
admin@apic1:infra~> moconfig commit

You won't be able to use any sudo commands on the APIC without TAC support

RedNectar aka Chris Welsh.
Forum Tips: 1. Paste images inline - don't attach. 2. Always mark helpful and correct answers, it helps others find what they need.

View solution in original post

7 Replies 7

RedNectar
VIP
VIP

Hi @Qwr! ,

I'm not sure if this is a question that  you'd like answered, or a contribution to help others out - because you've (almost) given the answer to your comment ...


was looking for a quick way to delete those objects. 

... when you listed the modelete method - but unfortunately as written it won't necessarily get ALL objects starting with TEMP_

So if you are looking for an answer to get ALL objects, you'll need to do this (my additions in red) - it will throw a lot of errors which you can ignore (because it's trying to delete relationships that won't exist when the objects they link to are deleted) but it will (fingers crossed) work!

apic1# bash
admin@apic1:~> cd /mit/uni/infra/
admin@apic1:infra~> for i in `find . -name *TEMP_*`
> do 
> echo "removing $i" 
> modelete $i
> done
# POTENTIALLY LOTS OF OUTPUT #
admin@apic1:infra~> moconfig commit

You won't be able to use any sudo commands on the APIC without TAC support

RedNectar aka Chris Welsh.
Forum Tips: 1. Paste images inline - don't attach. 2. Always mark helpful and correct answers, it helps others find what they need.

Qwr!
Level 1
Level 1

@RedNectar For some reason,  when i tried show run I do see lots of leftovers. Just wondering what could be the reason.

template policy-group TEMP_corporate_external
template policy-group TEMP_standard_access
tenant TEMP
leaf-interface-profile TEMP_server1
leaf-interface-profile TEMP_server2
leaf-interface-profile TEMP_phys_act_pass
leaf-interface-profile TEMP_corporate_external
switchport trunk allowed vlan 121 tenant TEMP application Evo epg Web
switchport trunk allowed vlan 123 tenant TEMP application Res epg Web
switchport trunk allowed vlan 125 tenant TEMP application Cha epg Web

also getting errors like ...find: paths must precede expression:

Hi @Qwr! ,

[Edit 2022.10.20 - Scroll down to my later answer for a MUCH FASTER solution]

To remove Tenant TEMP (and probably the switchport trunk ... TEMP application ... run the same command without the _ (underscore) following TEMP

apic1# bash
admin@apic1:~> cd /mit/uni/infra/
admin@apic1:infra~> for i in `find . -name *TEMP*`
> do 
> echo "removing $i" 
> modelete $i
> done
# POTENTIALLY LOTS OF OUTPUT #
admin@apic1:infra~> moconfig commit

The error 

...find: paths must precede expression:

can probably be avoided by putting single quotes around the search term - i.e. entering 

for i in `find . -name '*TEMP*'`

rather than

for i in `find . -name *TEMP*`

From my testing, this also deletes the template policy-group and leaf-interface-profile statements from show running-configtoo, but I actually think they should have been deleted anyway

In fact - I SUSPECT you left out the dot (period) between find and -name in

for i in `find . -name *TEMP*`

 

 

RedNectar aka Chris Welsh.
Forum Tips: 1. Paste images inline - don't attach. 2. Always mark helpful and correct answers, it helps others find what they need.

@RedNectarThank you! - again. Indeed, it works now. but noticed the process is too slow. may be because of the following error? thinking about collecting DNs and simply POSTing them.

This command is being deprecated on APIC controller, please use NXOS-style equivalent command

 

Hi @Qwr! ,

Yep. It is very slow. But I wasn't aiming for speed.  The following would probably be quicker, because it limits the depth of the find command (=big improvement) and limits it to finding just directories (=unknown improvement).

Note the following does NOT remove integrated Hypervisor objects - I did try adding uni/comp/prov-VMware to the list of paths, and the script DID try to remove my VMware VMM domain, but it couldn't remove it for some reason.

apic1# bash
admin@apic1:~> for p in uni uni/infra uni/infra/funcprof
> do
> cd /mit/$p
> for i in `find . -maxdepth 1 -name "*TEMP*" -type d`
> do
> echo Removing $i
> modelete $i
> done
> moconfig commit
> done

I just tried the above on my system - but stuck a date command before and after (i.e. I typed date ; for p in uni uni/infra uni/infra/funcprof ; do cd /mit/$p; for i in `find . -maxdepth 1 -type d -name "*T17:*"`; do echo Removing $i; modelete $i; done; moconfig commit; done ; date) and got:

Thu Oct 20 06:46:31 AEDT 2022
Removing ./l3dom-T17:WAN_L3Dom
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
Removing ./phys-T17:MappedVLANs_PhysDom
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
Committing mo 'uni/phys-T17:MappedVLANs_PhysDom'
Committing mo 'uni/l3dom-T17:WAN_L3Dom'

All mos committed successfully.
Removing ./vlanns-[T17:WAN_VLAN.Pool]-static
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
Removing ./vlanns-[T17:vC_VLAN.Pool]-dynamic
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
Removing ./vlanns-[T17:MappedVLANs_VLAN.Pool]-static
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
Removing ./nprof-T17:L2201_LeafProf
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
Removing ./accportprof-T17:L2202_IntProf
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
Removing ./nprof-T17:L2202_LeafProf
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
Removing ./nprof-T17:L2201..2202VPCs_LeafProf
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
Removing ./accportprof-T17:L2201_IntProf
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
Removing ./accportprof-T17:L2201..2202VPCs_IntProf
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
Removing ./attentp-T17:HostLinks_AAEP
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
Committing mo 'uni/infra/attentp-T17:HostLinks_AAEP'
Committing mo 'uni/infra/accportprof-T17:L2201..2202VPCs_IntProf'
Committing mo 'uni/infra/accportprof-T17:L2201_IntProf'
Committing mo 'uni/infra/nprof-T17:L2201..2202VPCs_LeafProf'
Committing mo 'uni/infra/nprof-T17:L2202_LeafProf'
Committing mo 'uni/infra/accportprof-T17:L2202_IntProf'
Committing mo 'uni/infra/nprof-T17:L2201_LeafProf'
Committing mo 'uni/infra/vlanns-[T17:MappedVLANs_VLAN.Pool]-static'
Committing mo 'uni/infra/vlanns-[T17:vC_VLAN.Pool]-dynamic'
Committing mo 'uni/infra/vlanns-[T17:WAN_VLAN.Pool]-static'

All mos committed successfully.
Removing ./accportgrp-T17:SA.Host_APPG
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
Removing ./accbundle-T17:L2201..2202:1:47_VPCIPG
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
This command is being deprecated on APIC controller, please use NXOS-style equivalent command
Committing mo 'uni/infra/funcprof/accbundle-T17:L2201..2202:1:47_VPCIPG'
Committing mo 'uni/infra/funcprof/accportgrp-T17:SA.Host_APPG'

All mos committed successfully.
Thu Oct 20 06:48:07 AEDT 2022

So 06:48:07-06:46:31=00:01:36 which is not too shabby

I really don't think the This command is being deprecated on APIC controller, please use NXOS-style equivalent command message makes any difference. That message has been around since approx v1.1 but still works

 If you want more speed, better to use the APIs and write a python program - which is essentially the conclusion YOU came to when you said


thinking about collecting DNs and simply POSTing them.

 

RedNectar aka Chris Welsh.
Forum Tips: 1. Paste images inline - don't attach. 2. Always mark helpful and correct answers, it helps others find what they need.

Qwr!
Level 1
Level 1

 RedNectar 

>So 06:48:07-06:46:31=00:01:36 which is not too shabby

Agree, maybe there is some issue with our environment. It took more than 4 hours, but it was still going on. So it could be a different case.

 

>I really don't think the This command is being deprecated on APIC controller, please use NXOS-style equivalent command message makes any difference. That message has been around since approx v1.1 but still works

Noted. Good to know about this. Thank you.

Review Cisco Networking for a $25 gift card

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