cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
945
Views
2
Helpful
2
Replies
chungewa
Cisco Employee

How to setup Python loop to create 3000 ACI BDs

HI, Experts

from the following 2 python line script,it can create ONE BD into the tenant,

BUT what i need is creating 3000 BDs,

So how can i setup a Python loop to dynamically replace the following colorful text

Thanks a lot!

/Ja

==========================

    fvBD8 = cobra.model.fv.BD(fvTenant, ownerKey=u'', name=u'BD8', descr=u'', unkMacUcastAct=u'proxy', arpFlood=u'no', mac=u'00:22:BD:F8:19:FF', unicastRoute=u'yes', ownerTag=u'', unkMcastAct=u'flood')

    fvRsABDPolMonPol8 = cobra.model.fv.RsABDPolMonPol(fvBD8, tnMonEPGPolName=u'default')

=========================

1 ACCEPTED SOLUTION

Accepted Solutions
tigephillips
Enthusiast

for num in range (1,3001):

  my_string =  "fvBD{0} = cobra.model.fv.BD(fvTenant, ownerKey=u'', name=u'BD{0}', descr=u'', unkMacUcastAct=u'proxy', arpFlood=u'no', mac=u'00:22:BD:F8:19:FF', unicastRoute=u'yes', ownerTag=u'', unkMcastAct=u'flood') fvRsABDPolMonPol{0} = cobra.model.fv.RsABDPolMonPol(fvBD{0}, tnMonEPGPolName=u'default')".format (num)

  print my_string

This will change each of the {0} in the string into whatever is in "num".   The other key to the code is the .format (num)   on the end of the string.  I'm printing it out, but you probably will want to do something with it instead.  You will get numbers from 1 - 3000 (range gives you one less than what you specify).

View solution in original post

2 REPLIES 2
tigephillips
Enthusiast

for num in range (1,3001):

  my_string =  "fvBD{0} = cobra.model.fv.BD(fvTenant, ownerKey=u'', name=u'BD{0}', descr=u'', unkMacUcastAct=u'proxy', arpFlood=u'no', mac=u'00:22:BD:F8:19:FF', unicastRoute=u'yes', ownerTag=u'', unkMcastAct=u'flood') fvRsABDPolMonPol{0} = cobra.model.fv.RsABDPolMonPol(fvBD{0}, tnMonEPGPolName=u'default')".format (num)

  print my_string

This will change each of the {0} in the string into whatever is in "num".   The other key to the code is the .format (num)   on the end of the string.  I'm printing it out, but you probably will want to do something with it instead.  You will get numbers from 1 - 3000 (range gives you one less than what you specify).

View solution in original post

thanks tiphilli!!!

Content for Community-Ad