blob: e53c323c114e5bc9bace8ec8a5bf293f6b0a9526 [file] [log] [blame]
Matteo Scandoloc41467a2016-05-02 18:15:57 -07001import dredd_hooks as hooks
2import sys
3
4# HELPERS
5# NOTE move in separated module
6import os
7import sys
8sys.path.append("/opt/xos")
9os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
10import django
11from core.models import *
12from services.cord.models import *
13from services.vtr.models import *
14import urllib2
15import json
16django.setup()
17
18
19def doLogin(username, password):
20 url = "http://127.0.0.1:8000/xoslib/login?username=%s&password=%s" % (username, password)
21 res = urllib2.urlopen(url).read()
22 parsed = json.loads(res)
23 return {'token': parsed['xoscsrftoken'], 'sessionid': parsed['xossessionid']}
24
25
26def cleanDB():
27 # deleting all subscribers
28 for s in CordSubscriberRoot.objects.all():
29 s.delete(purge=True)
30
31 # deleting all slices
32 for s in Slice.objects.all():
33 s.delete(purge=True)
34
35 # deleting all Services
36 for s in Service.objects.all():
37 s.delete(purge=True)
38
39 # deleting all Tenants
40 for s in Tenant.objects.all():
41 s.delete(purge=True)
42
43 # deleting all Networks
44 for s in Network.objects.all():
45 s.delete(purge=True)
46
47 # deleting all NetworkTemplates
48 for s in NetworkTemplate.objects.all():
49 s.delete(purge=True)
50
51 for s in NetworkSlice.objects.all():
52 s.delete(purge=True)
53
54 for s in AddressPool.objects.all():
55 s.delete(purge=True)
56
57 for s in Flavor.objects.all():
58 s.delete(purge=True)
59
60 for s in Image.objects.all():
61 s.delete(purge=True)
62
63 # print 'DB Cleaned'
64
65
66def createTestSubscriber():
67
68 cleanDB()
69 createFlavors()
70
71 # load user
72 user = User.objects.get(email="padmin@vicci.org")
73
74 # network template
75 private_template = NetworkTemplate()
76 private_template.name = 'Private Network'
77 private_template.save()
78
79 # creating the test subscriber
80 subscriber = CordSubscriberRoot(name='Test Subscriber 1', id=1)
81 subscriber.save()
82
83 # vRouter service
84 vrouter_service = VRouterService()
85 vrouter_service.name = 'service_vrouter'
86 vrouter_service.save()
87
88 # address pools
89 ap_vsg = AddressPool()
90 ap_vsg.service = vrouter_service
91 ap_vsg.name = 'addresses_vsg'
92 ap_vsg.addresses = '10.168.0.0'
93 ap_vsg.gateway_ip = '10.168.0.1'
94 ap_vsg.gateway_mac = '02:42:0a:a8:00:01'
95 ap_vsg.save()
96
97 # print 'vRouter created'
98
99 # Site
100 site = Site.objects.get(name='MySite')
101
102 # vSG service
103 vsg_service = VSGService()
104 vsg_service.name = 'service_vsg'
105
106 # vSG slice
107 vsg_slice = Slice(id=2)
108 vsg_slice.name = site.login_base + "_testVsg"
109 vsg_slice.service = vsg_service.id
110 vsg_slice.site = site
111 vsg_slice.caller = user
112
113 vsg_slice.save()
114
115 vsg_service.save()
116
117 # volt service
118 volt_service = VOLTService()
119 volt_service.name = 'service_volt'
120 volt_service.save()
121
122 # cvpe image
123 createImage('ubuntu-vcpe4')
124
125 # vcpe slice
126 vcpe_slice = Slice(id=3)
127 vcpe_slice.name = site.login_base + "_testVcpe"
128 vcpe_slice.service = Service.objects.get(kind='vCPE')
129 vcpe_slice.site = site
130 vcpe_slice.caller = user
131 vcpe_slice.save()
132
133 # print 'vcpe_slice created'
134
135 # create a lan network
136 lan_net = Network()
137 lan_net.name = 'lan_network'
138 lan_net.owner = vcpe_slice
139 lan_net.template = private_template
140 lan_net.save()
141
142 # print 'lan_network created'
143
144 # add relation between vcpe slice and lan network
145 vcpe_network = NetworkSlice()
146 vcpe_network.network = lan_net
147 vcpe_network.slice = vcpe_slice
148 vcpe_network.save()
149
150 # print 'vcpe network relation added'
151
152 # vbng service
153 vbng_service = VBNGService()
154 vbng_service.name = 'service_vbng'
155 vbng_service.save()
156
157 # print 'vbng_service creater'
158
159 # volt tenant
160 vt = VOLTTenant(subscriber=subscriber.id, id=1)
161 vt.s_tag = "222"
162 vt.c_tag = "432"
163 vt.provider_service_id = volt_service.id
164 vt.caller = user
165 vt.save()
166
167 # print "Subscriber Created"
168
169
170def deleteTruckrolls():
171 for s in VTRTenant.objects.all():
172 s.delete(purge=True)
173
174
175def setUpTruckroll():
176 service_vtr = VTRService()
177 service_vtr.name = 'service_vtr'
178 service_vtr.save()
179
180
181def createTruckroll():
182 setUpTruckroll()
183 tn = VTRTenant(id=1)
184 tn.save()
185
186
187def createFlavors():
188 small = Flavor(id=1)
189 small.name = "m1.small"
190 small.save()
191
192 medium = Flavor(id=2)
193 medium.name = "m1.medium"
194 medium.save()
195
196 large = Flavor(id=3)
197 large.name = "m1.large"
198 large.save()
199
200
201def createSlice():
202 site = Site.objects.get(name='MySite')
203 user = User.objects.get(email="padmin@vicci.org")
204
205 sl = Slice(id=1)
206 sl.name = site.login_base + "_testSlice"
207 sl.site = site
208 sl.caller = user
209 sl.save()
210 return sl
211
212
213def createDeployment():
214 deployment = Deployment(id=1)
215 deployment.name = 'MyTestDeployment'
216 deployment.save()
217 return deployment
218
219
220def createImage(name):
221 img = Image(id=1)
222 img.name = name
223 img.disk_format = 'QCOW2'
224 img.kind = 'vm'
225 img.save()
226 return img
227
228
229def createNode(deployment):
230 site = Site.objects.get(name='MySite')
231
232 site_deployment = SiteDeployment(id=1)
233 site_deployment.site = site
234 site_deployment.deployment = deployment
235 site_deployment.save()
236
237 node = Node(id=1)
238 node.name = 'test-node'
239 node.site = site
240 node.site_deployment = site_deployment
241 node.save()
242 return node
243
244
245def setupInstance():
246 deployment = createDeployment()
247 sl = createSlice()
248 node = createNode(deployment)
249 img = createImage('test-image')
250 print {'image': img.id, 'deployment': deployment.id, 'slice': sl.id}
251 return {'image': img, 'deployment': deployment, 'slice': sl}
252
253
254def createInstance():
255 requirements = setupInstance()
256 user = User.objects.get(email="padmin@vicci.org")
257
258 instance = Instance(id=1)
259 instance.name = 'test-instance'
260 instance.node = Node.objects.all()[0]
261 instance.image = requirements['image']
262 instance.slice = requirements['slice']
263 instance.deployment = requirements['deployment']
264 instance.caller = user
265 instance.save()
266
267setupInstance()
268# createTestSubscriber()
269# createInstance()
270# createNode()