Re: Deleting vrf's

From: karthik thatikonda <get2explore_at_gmail.com>
Date: Wed, 25 Aug 2010 19:16:06 -0700

Ok. Got it. Thanks.

On Wed, Aug 25, 2010 at 7:13 PM, Adam Booth <adam.booth_at_gmail.com> wrote:

> Hi Karthik,
>
> If you look at the example below the script; after the script is pasted
> into the tclsh level of the exec shell, it was then called - unfortunately
> if you close the tclsh session, the script is lost and you have to paste the
> script in each time you want to call it.
>
> However what you could do is copy the script to your flash (scp, tftp
> whatever it from a pc to the router)
>
> Then if it's now stored on your router as flash:delvrf.tcl in your config
> you could set up an alias:
>
> alias exec delvrf tclsh flash:delvrf.tcl
>
> Then you should just be able to type delvrf to call the script each time
> without having to enter it in again.
>
> Cheers,
> Adam
>
>
>
>
> On Thu, Aug 26, 2010 at 12:03 PM, karthik thatikonda <
> get2explore_at_gmail.com> wrote:
>
>> Hi,
>>
>> One more question. I created a script for creating 1000 vrf's and on the
>> router issued tclsh and pasted the script and it got installed. But, if I do
>> sh run config won't show up. Do I need to apply using another command?. Do
>> they get stored some where else?
>>
>> Thanks,
>>
>> Karthik.
>>
>> On Wed, Aug 25, 2010 at 8:31 AM, karthik thatikonda <
>> get2explore_at_gmail.com> wrote:
>>
>>> Thanks Adam.
>>>
>>>
>>> On Wed, Aug 25, 2010 at 5:40 AM, Adam Booth <adam.booth_at_gmail.com>wrote:
>>>
>>>> Before I started playing with tclsh I would have created a script in
>>>> perl or something parsing an offline copy of the config
>>>>
>>>> Here's my attempt at a tcl script (I'm been interested in this for the
>>>> last few days but I think I've started to have enough)
>>>>
>>>> Existing R4 vrf related Config:
>>>>
>>>> ip vrf A
>>>> rd 1:1
>>>> route-target export 1:1
>>>> route-target import 1:1
>>>> !
>>>> ip vrf B
>>>> rd 1:2
>>>> route-target export 1:2
>>>> route-target import 1:2
>>>> !
>>>> ip vrf C
>>>> rd 1:3
>>>> !
>>>> ip vrf D
>>>> rd 1:4
>>>> !
>>>> interface Serial2/0
>>>> ip vrf forwarding A
>>>> ip address 1.1.1.1 255.255.255.252
>>>> !
>>>> interface Loopback1
>>>> ip vrf forwarding A
>>>> ip address 2.2.2.2 255.255.255.255
>>>> !
>>>> interface Loopback2
>>>> ip vrf forwarding B
>>>> ip address 3.3.3.3 255.255.255.255
>>>> !
>>>> interface Loopback4
>>>> ip vrf forwarding D
>>>> ip address 3.3.3.3 255.255.255.255
>>>> !
>>>>
>>>> delvrf deletes vrfs and removes associated loopbacks if they exist:
>>>>
>>>> proc delvrf {} {
>>>> set cmdout [exec "sh ip vrf | exclude ^__Name"]
>>>> set currentinterface "first"
>>>> set currentvrf "first"
>>>> foreach line [split $cmdout "\n"] {
>>>> set oldvrf $currentvrf
>>>> set oldinterface $currentinterface
>>>> if [regexp {^\ (\S+)\s+(\S+)\s+(\S+)} $line match vrf rd
>>>> interface] {
>>>> set currentvrf $vrf
>>>> set currentinterface $interface
>>>> } elseif [regexp {^\ (\S+)\s+(\S+)} $line match vrf rd] {
>>>> set currentvrf $vrf
>>>> } elseif [regexp {^\s+(\S+)} $line match interface] {
>>>> set currentinterface $interface
>>>> }
>>>> if [string compare $currentinterface "first"] {
>>>> if {[string compare $currentvrf $oldvrf] & [string compare
>>>> $oldvrf "first"]} {
>>>> ios_config "no ip vrf $oldvrf"
>>>> }
>>>> if {[string compare $currentinterface $oldinterface] & [regexp
>>>> {^(Lo)} $currentinterface ]} {
>>>> ios_config "no interface $currentinterface"
>>>> }
>>>> }
>>>> }
>>>> ios_config "no ip vrf $currentvrf"
>>>> }
>>>>
>>>> This is it cleaning up R4
>>>>
>>>> R4#tclsh
>>>> R4(tcl)#proc delvrf {} {
>>>> +>(tcl)# set cmdout [exec "sh ip vrf | exclude ^__Name"]
>>>> +>(tcl)# set currentinterface "first"
>>>> +>(tcl)# set currentvrf "first"
>>>> +>(tcl)# foreach line [split $cmdout "\n"] {
>>>> +>(tcl)# set oldvrf $currentvrf
>>>> +>(tcl)# set oldinterface $currentinterface
>>>> +>(tcl)#$regexp {^\ (\S+)\s+(\S+)\s+(\S+)} $line match vrf rd
>>>> interface] {
>>>> +>(tcl)# set currentvrf $vrf
>>>> +>(tcl)# set currentinterface $interface
>>>> +>(tcl)# } elseif [regexp {^\ (\S+)\s+(\S+)} $line match vrf rd]
>>>> {
>>>> +>(tcl)# set currentvrf $vrf
>>>> +>(tcl)# } elseif [regexp {^\s+(\S+)} $line match interface] {
>>>> +>(tcl)# set currentinterface $interface
>>>> +>(tcl)# }
>>>> +>(tcl)# if [string compare $currentinterface "first"] {
>>>> +>(tcl)#$ compare $currentvrf $oldvrf] & [string compare $oldvrf
>>>> "first"]} {
>>>> +>(tcl)# ios_config "no ip vrf $oldvrf"
>>>> +>(tcl)# }
>>>> +>(tcl)#$erface $oldinterface] & [regexp {^(Lo)} $currentinterface ]} {
>>>> +>(tcl)# ios_config "no interface $currentinterface"
>>>> +>(tcl)# }
>>>> +>(tcl)# }
>>>> +>(tcl)# }
>>>> +>(tcl)# ios_config "no ip vrf $currentvrf"
>>>> +>(tcl)#}
>>>>
>>>> R4(tcl)#delvrf
>>>>
>>>> % IPv4 addresses from all interfaces in VRF D have been removed
>>>> R4(tcl)#
>>>> *Aug 25 22:31:04.591: %LINK-5-CHANGED: Interface Loopback1, changed
>>>> state to administratively down
>>>> *Aug 25 22:31:05.203: %LINK-5-CHANGED: Interface Loopback2, changed
>>>> state to administratively down
>>>> *Aug 25 22:31:05.591: %LINEPROTO-5-UPDOWN: Line protocol on Interface
>>>> Loopback1, changed state to down
>>>> *Aug 25 22:31:05.887: %LINK-5-CHANGED: Interface Loopback4, changed
>>>> state to administratively down
>>>> *Aug 25 22:31:06.203: %LINEPROTO-5-UPDOWN: Line protocol on Interface
>>>> Loopback2, changed state to down
>>>> *Aug 25 22:31:06.887: %LINEPROTO-5-UPDOWN: Line protocol on Interface
>>>> Loopback4, changed state to down
>>>> R4(tcl)#exit
>>>> R4#sh ip vrf
>>>>
>>>> R4#sh ip int brie
>>>> Interface IP-Address OK? Method
>>>> Status Protocol
>>>> FastEthernet0/0 unassigned YES NVRAM
>>>> up up
>>>> FastEthernet0/1 unassigned YES NVRAM
>>>> up up
>>>> Serial2/0 unassigned YES manual administratively
>>>> down down
>>>> Serial2/1 unassigned YES NVRAM administratively
>>>> down down
>>>> Serial2/2 unassigned YES NVRAM administratively
>>>> down down
>>>> Serial2/3 unassigned YES NVRAM administratively
>>>> down down
>>>> SSLVPN-VIF0 unassigned NO unset
>>>> up up
>>>> R4#
>>>>
>>>>
>>>> Cheers,
>>>> Adam
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Wed, Aug 25, 2010 at 8:04 PM, garry baker <baker.garry_at_gmail.com>wrote:
>>>>
>>>>> probably a tcl script could help you out also...
>>>>>
>>>>> --
>>>>> Garry L. Baker
>>>>>
>>>>> "There is no 'patch' for stupidity." - www.sqlsecurity.com
>>>>>
>>>>>
>>>>> On Wed, Aug 25, 2010 at 12:13 PM, William McCall
>>>>> <william.mccall_at_gmail.com>wrote:
>>>>>
>>>>> > Without nuking the config? You'd have to remove them per entry.
>>>>> >
>>>>> > --
>>>>> > William McCall, CCIE #25044
>>>>> >
>>>>> > On Wed, Aug 25, 2010 at 4:00 AM, karthik thatikonda
>>>>> > <get2explore_at_gmail.com> wrote:
>>>>> > > Hello,
>>>>> > >
>>>>> > > I have a question. For example if I had configured 1000 vrf's on a
>>>>> router
>>>>> > > and if I need to delete all vrf's simultaneously how can I achieve
>>>>> that
>>>>> > > behavior?
>>>>> > >
>>>>> > > Thanks,
>>>>> > >
>>>>> > > Karthik.
>>>>>
>>>>> > >
>>>>> > >
>>>>> > > Blogs and organic groups at http://www.ccie.net
>>>>> > >
>>>>> > >
>>>>> _______________________________________________________________________
>>>>> > > Subscription information may be found at:
>>>>> > > http://www.groupstudy.com/list/CCIELab.html
>>>>> >
>>>>> >
>>>>> > Blogs and organic groups at http://www.ccie.net
>>>>> >
>>>>> >
>>>>> _______________________________________________________________________
>>>>> > Subscription information may be found at:
>>>>> > http://www.groupstudy.com/list/CCIELab.html
>>>>>
>>>>>
>>>>> Blogs and organic groups at http://www.ccie.net
>>>>>
>>>>> _______________________________________________________________________
>>>>> Subscription information may be found at:
>>>>> http://www.groupstudy.com/list/CCIELab.html

Blogs and organic groups at http://www.ccie.net
Received on Wed Aug 25 2010 - 19:16:06 ART

This archive was generated by hypermail 2.2.0 : Wed Sep 01 2010 - 11:20:53 ART