-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathswitch_test.py
More file actions
executable file
·76 lines (59 loc) · 2.79 KB
/
Copy pathswitch_test.py
File metadata and controls
executable file
·76 lines (59 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
'''
Autogenerated code using webarya.py
Original Object Document Input:
{"totalCount":"1","imdata":[{"infraNodeP":{"attributes":{"descr":"","dn":"uni/infra/nprof-Leafs","name":"Leafs","ownerKey":"","ownerTag":""},"children":[{"infraLeafS":{"attributes":{"descr":"","name":"Leafs","ownerKey":"","ownerTag":"","type":"range"},"children":[{"infraNodeBlk":{"attributes":{"descr":"","from_":"201","name":"3a608b521b4633b7","to_":"202"}}}]}},{"infraRsAccPortP":{"attributes":{"tDn":"uni/infra/accportprof-RPIs"}}},{"infraRsAccPortP":{"attributes":{"tDn":"uni/infra/accportprof-Routers"}}}]}}]}
'''
# list of packages that should be imported for this code to work
import cobra.mit.access
import cobra.mit.naming
import cobra.mit.request
import cobra.mit.session
import cobra.model.infra
from cobra.internal.codec.xmlcodec import toXMLStr
# ACI Toolkit packages
import acitoolkit.acitoolkit as ACI
# All the other stuff we need.
import sys, random, string
def hello_message():
print "\nPlease be cautious with this application. The author did very little error checking and can't ensure it will work as expected.\n"
print description
junk = raw_input('Press Enter/Return to continue.')
return
def load_utils():
try:
global GO
import go_utils as GO
except:
print 'Can not find go_utils.py. This file is required.'
exit()
def load_config():
try:
global GO_CONFIG
import go_lab_config as GO_CONFIG
except ImportError:
print 'No config file found (go_lab_config.py). Use "--makeconfig" to create a base file.'
exit()
except:
print 'There is syntax error with your config file. Please use the python interactive interpreture to diagnose. (python; import go_lab_config)'
exit()
load_utils()
load_config()
admin_info = GO.collect_admin(GO_CONFIG)
cobra_md = GO.cobra_login(admin_info)
# the top level object on which operations will be made
# Confirm the dn below is for your top dn
topDn = cobra.mit.naming.Dn.fromString('uni/infra/nprof-Leafs')
topParentDn = topDn.getParent()
topMo = cobra_md.lookupByDn(topParentDn)
# build the request using cobra syntax
infraNodeP = cobra.model.infra.NodeP(topMo, ownerKey=u'', name=u'Leafs', descr=u'', ownerTag=u'')
infraLeafS = cobra.model.infra.LeafS(infraNodeP, ownerKey=u'', type=u'range', name=u'Leafs', descr=u'', ownerTag=u'')
infraNodeBlk = cobra.model.infra.NodeBlk(infraLeafS, from_=u'201', name=u'3a608b521b4633b7', descr=u'', to_=u'202')
infraRsAccPortP = cobra.model.infra.RsAccPortP(infraNodeP, tDn=u'uni/infra/accportprof-RPIs')
infraRsAccPortP2 = cobra.model.infra.RsAccPortP(infraNodeP, tDn=u'uni/infra/accportprof-Routers')
# commit the generated code to APIC
print toXMLStr(topMo)
c = cobra.mit.request.ConfigRequest()
c.addMo(topMo)
cobra_md.commit(c)