blob: a977564aca8a4452b95055ed8d30fbba09125a71 [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 *
Scott Baker16d4ac32016-06-13 11:48:41 -070012from services.volt.models import *
13from services.vsg.models import *
Matteo Scandoloc41467a2016-05-02 18:15:57 -070014from services.vtr.models import *
15import urllib2
16import json
Matteo Scandolod9f92a72016-05-05 15:44:13 -070017from django.utils import timezone
Matteo Scandoloc41467a2016-05-02 18:15:57 -070018django.setup()
19
20
21def doLogin(username, password):
22 url = "http://127.0.0.1:8000/xoslib/login?username=%s&password=%s" % (username, password)
23 res = urllib2.urlopen(url).read()
24 parsed = json.loads(res)
25 return {'token': parsed['xoscsrftoken'], 'sessionid': parsed['xossessionid']}
26
27
28def cleanDB():
29 # deleting all subscribers
30 for s in CordSubscriberRoot.objects.all():
31 s.delete(purge=True)
32
33 # deleting all slices
34 for s in Slice.objects.all():
35 s.delete(purge=True)
36
37 # deleting all Services
38 for s in Service.objects.all():
39 s.delete(purge=True)
40
41 # deleting all Tenants
42 for s in Tenant.objects.all():
43 s.delete(purge=True)
44
45 # deleting all Networks
46 for s in Network.objects.all():
47 s.delete(purge=True)
48
49 # deleting all NetworkTemplates
50 for s in NetworkTemplate.objects.all():
51 s.delete(purge=True)
52
53 for s in NetworkSlice.objects.all():
54 s.delete(purge=True)
55
56 for s in AddressPool.objects.all():
57 s.delete(purge=True)
58
59 for s in Flavor.objects.all():
60 s.delete(purge=True)
61
62 for s in Image.objects.all():
63 s.delete(purge=True)
64
65 # print 'DB Cleaned'
66
67
68def createTestSubscriber():
69
70 cleanDB()
71 createFlavors()
72
73 # load user
74 user = User.objects.get(email="padmin@vicci.org")
75
76 # network template
77 private_template = NetworkTemplate()
78 private_template.name = 'Private Network'
79 private_template.save()
80
81 # creating the test subscriber
82 subscriber = CordSubscriberRoot(name='Test Subscriber 1', id=1)
Matteo Scandolod9f92a72016-05-05 15:44:13 -070083 subscriber.created = timezone.now()
Matteo Scandoloc41467a2016-05-02 18:15:57 -070084 subscriber.save()
85
86 # vRouter service
87 vrouter_service = VRouterService()
88 vrouter_service.name = 'service_vrouter'
89 vrouter_service.save()
90
91 # address pools
92 ap_vsg = AddressPool()
93 ap_vsg.service = vrouter_service
94 ap_vsg.name = 'addresses_vsg'
95 ap_vsg.addresses = '10.168.0.0'
96 ap_vsg.gateway_ip = '10.168.0.1'
97 ap_vsg.gateway_mac = '02:42:0a:a8:00:01'
98 ap_vsg.save()
99
100 # print 'vRouter created'
101
102 # Site
103 site = Site.objects.get(name='MySite')
104
105 # vSG service
106 vsg_service = VSGService()
107 vsg_service.name = 'service_vsg'
108
109 # vSG slice
110 vsg_slice = Slice(id=2)
111 vsg_slice.name = site.login_base + "_testVsg"
112 vsg_slice.service = vsg_service.id
113 vsg_slice.site = site
114 vsg_slice.caller = user
115
116 vsg_slice.save()
117
118 vsg_service.save()
119
120 # volt service
121 volt_service = VOLTService()
122 volt_service.name = 'service_volt'
123 volt_service.save()
124
125 # cvpe image
126 createImage('ubuntu-vcpe4')
127
128 # vcpe slice
129 vcpe_slice = Slice(id=3)
130 vcpe_slice.name = site.login_base + "_testVcpe"
131 vcpe_slice.service = Service.objects.get(kind='vCPE')
132 vcpe_slice.site = site
133 vcpe_slice.caller = user
134 vcpe_slice.save()
135
136 # print 'vcpe_slice created'
137
138 # create a lan network
Matteo Scandolod9f92a72016-05-05 15:44:13 -0700139 lan_net = Network(id=1)
Matteo Scandoloc41467a2016-05-02 18:15:57 -0700140 lan_net.name = 'lan_network'
141 lan_net.owner = vcpe_slice
142 lan_net.template = private_template
143 lan_net.save()
144
145 # print 'lan_network created'
146
147 # add relation between vcpe slice and lan network
148 vcpe_network = NetworkSlice()
149 vcpe_network.network = lan_net
150 vcpe_network.slice = vcpe_slice
151 vcpe_network.save()
152
153 # print 'vcpe network relation added'
154
155 # vbng service
156 vbng_service = VBNGService()
157 vbng_service.name = 'service_vbng'
158 vbng_service.save()
159
160 # print 'vbng_service creater'
161
162 # volt tenant
163 vt = VOLTTenant(subscriber=subscriber.id, id=1)
164 vt.s_tag = "222"
165 vt.c_tag = "432"
166 vt.provider_service_id = volt_service.id
167 vt.caller = user
168 vt.save()
169
170 # print "Subscriber Created"
171
172
173def deleteTruckrolls():
174 for s in VTRTenant.objects.all():
175 s.delete(purge=True)
176
177
178def setUpTruckroll():
179 service_vtr = VTRService()
180 service_vtr.name = 'service_vtr'
181 service_vtr.save()
182
183
184def createTruckroll():
185 setUpTruckroll()
186 tn = VTRTenant(id=1)
Matteo Scandolod9f92a72016-05-05 15:44:13 -0700187 tn.created = timezone.now()
Matteo Scandoloc41467a2016-05-02 18:15:57 -0700188 tn.save()
189
190
191def createFlavors():
192 small = Flavor(id=1)
193 small.name = "m1.small"
Matteo Scandolod9f92a72016-05-05 15:44:13 -0700194 small.created = timezone.now()
Matteo Scandoloc41467a2016-05-02 18:15:57 -0700195 small.save()
196
197 medium = Flavor(id=2)
198 medium.name = "m1.medium"
Matteo Scandolod9f92a72016-05-05 15:44:13 -0700199 medium.created = timezone.now()
Matteo Scandoloc41467a2016-05-02 18:15:57 -0700200 medium.save()
201
202 large = Flavor(id=3)
203 large.name = "m1.large"
Matteo Scandolod9f92a72016-05-05 15:44:13 -0700204 large.created = timezone.now()
Matteo Scandoloc41467a2016-05-02 18:15:57 -0700205 large.save()
206
207
208def createSlice():
209 site = Site.objects.get(name='MySite')
210 user = User.objects.get(email="padmin@vicci.org")
211
212 sl = Slice(id=1)
Matteo Scandolod9f92a72016-05-05 15:44:13 -0700213 sl.created = timezone.now()
Matteo Scandoloc41467a2016-05-02 18:15:57 -0700214 sl.name = site.login_base + "_testSlice"
215 sl.site = site
216 sl.caller = user
217 sl.save()
218 return sl
219
220
221def createDeployment():
222 deployment = Deployment(id=1)
Matteo Scandolod9f92a72016-05-05 15:44:13 -0700223 deployment.created = timezone.now()
Matteo Scandoloc41467a2016-05-02 18:15:57 -0700224 deployment.name = 'MyTestDeployment'
225 deployment.save()
226 return deployment
227
228
229def createImage(name):
230 img = Image(id=1)
231 img.name = name
Matteo Scandolod9f92a72016-05-05 15:44:13 -0700232 img.created = timezone.now()
Matteo Scandoloc41467a2016-05-02 18:15:57 -0700233 img.disk_format = 'QCOW2'
234 img.kind = 'vm'
235 img.save()
236 return img
237
238
239def createNode(deployment):
240 site = Site.objects.get(name='MySite')
241
242 site_deployment = SiteDeployment(id=1)
243 site_deployment.site = site
Matteo Scandolod9f92a72016-05-05 15:44:13 -0700244 site_deployment.created = timezone.now()
Matteo Scandoloc41467a2016-05-02 18:15:57 -0700245 site_deployment.deployment = deployment
246 site_deployment.save()
247
248 node = Node(id=1)
249 node.name = 'test-node'
Matteo Scandolod9f92a72016-05-05 15:44:13 -0700250 node.created = timezone.now()
Matteo Scandoloc41467a2016-05-02 18:15:57 -0700251 node.site = site
252 node.site_deployment = site_deployment
253 node.save()
254 return node
255
256
257def setupInstance():
258 deployment = createDeployment()
259 sl = createSlice()
260 node = createNode(deployment)
261 img = createImage('test-image')
Matteo Scandolod9f92a72016-05-05 15:44:13 -0700262 # print {'image': img.id, 'deployment': deployment.id, 'slice': sl.id}
Matteo Scandoloc41467a2016-05-02 18:15:57 -0700263 return {'image': img, 'deployment': deployment, 'slice': sl}
264
265
266def createInstance():
267 requirements = setupInstance()
268 user = User.objects.get(email="padmin@vicci.org")
269
270 instance = Instance(id=1)
271 instance.name = 'test-instance'
Matteo Scandolod9f92a72016-05-05 15:44:13 -0700272 instance.created = timezone.now()
Matteo Scandoloc41467a2016-05-02 18:15:57 -0700273 instance.node = Node.objects.all()[0]
274 instance.image = requirements['image']
275 instance.slice = requirements['slice']
276 instance.deployment = requirements['deployment']
277 instance.caller = user
278 instance.save()
279
Matteo Scandolod9f92a72016-05-05 15:44:13 -0700280
Matteo Scandolof2ec12b2016-05-16 10:31:32 -0700281def createService():
282 service = Service(id=1)
283 service.name = 'test-service'
284 service.save()
285
Matteo Scandolod9f92a72016-05-05 15:44:13 -0700286# setupInstance()
287# depl = createDeployment()
Matteo Scandolof2ec12b2016-05-16 10:31:32 -0700288# createTestSubscriber()
Matteo Scandoloc41467a2016-05-02 18:15:57 -0700289# createInstance()
Matteo Scandolod9f92a72016-05-05 15:44:13 -0700290# createSlice()
291# createNode(depl)
292# createImage('test-image')
293# createFlavors()
294# createTruckroll()
Matteo Scandolof2ec12b2016-05-16 10:31:32 -0700295# setUpTruckroll()
296createService()