-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpledemo.py
More file actions
120 lines (98 loc) · 2.24 KB
/
Copy pathsimpledemo.py
File metadata and controls
120 lines (98 loc) · 2.24 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from acitoolkit.acitoolkit import *
LOGIN = 'admin'
PASSWORD = 'password'
IPADDR = 'one.apic.local'
URL = 'https://' + IPADDR
session = Session(URL, LOGIN, PASSWORD)
resp = session.login()
if not resp.ok:
print('%% Could not login to APIC')
sys.exit(0)
# Cleanup of existing resources
#
# Delete Tenant
tenant1 = Tenant('Test-1')
tenant1.mark_as_deleted()
resp = tenant1.push_to_apic(session)
# Create Tenants
#
# Tenant 1
tenant1 = Tenant('Test-1')
# Configure Networking
#
#
defaultVRF = Context('VRF-1', tenant1)
bd1 = BridgeDomain('BD-1', tenant1)
bd1.add_context(defaultVRF)
bd2 = BridgeDomain('BD-2', tenant1)
bd2.add_context(defaultVRF)
net1 = Subnet('Subnet-1', bd1)
net1.set_addr('10.25.226.1/24')
net1.set_scope('public')
net2 = Subnet('Subnet-2', bd1)
net2.set_addr('10.25.227.1/24')
net2.set_scope('public')
net3 = Subnet('Subnet-3', bd2)
net3.set_addr('10.25.228.1/24')
net3.set_scope('public')
# Cretae Contracts
#
#
contract1 = Contract('contract-1', tenant1)
entry11 = FilterEntry('entry11',
applyToFrag='no',
arpOpc='unspecified',
dFromPort='80',
dToPort='80',
etherT='ip',
prot='tcp',
sFromPort='1',
sToPort='65535',
tcpRules='unspecified',
parent=contract1)
contract2 = Contract('contract-2', tenant1)
entry21 = FilterEntry('entry11',
applyToFrag='no',
arpOpc='unspecified',
dFromPort='80',
dToPort='80',
etherT='ip',
prot='tcp',
sFromPort='1',
sToPort='65535',
tcpRules='unspecified',
parent=contract2)
entry22 = FilterEntry('entry12',
applyToFrag='no',
arpOpc='unspecified',
dFromPort='443',
dToPort='443',
etherT='ip',
prot='tcp',
sFromPort='1',
sToPort='65535',
tcpRules='unspecified',
parent=contract2)
# Define Application Profiles
#
#
app1 = AppProfile('AP-1', tenant1)
epg1 = EPG('EPG-1', app1)
epg1.add_bd(bd1)
epg2 = EPG('EPG-2', app1)
epg2.add_bd(bd1)
epg3 = EPG('EPG-3', app1)
epg3.add_bd(bd2)
# Contract usage
#
#
epg3.provide(contract1)
epg3.provide(contract2)
epg1.consume(contract1)
epg2.consume(contract2)
# Send configuration to APIC
print tenant1.get_json()
resp = tenant1.push_to_apic(session)
if not resp.ok:
print("%% Oops, something didn't work!")
sys.exit(0)