cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2111
Views
2
Helpful
2
Replies

How to setup Python loop to create 3000 ACI BDs

chungewa
Cisco Employee
Cisco Employee

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
Level 4
Level 4
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
Level 4
Level 4
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).

thanks tiphilli!!!

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:


This community is intended for developer topics around Data Center technology and products. If you are looking for a non-developer topic about Data Center, you might find additional information in the Data Center and Cloud community