Fix: Improved performance of REST getStatus endpoint.
[osm/vim-emu.git] / src / emuvim / api / osm / osm.py
1 #!/usr/bin/env python2
2 # Copyright (c) 2019 Erik Schilling
3 # ALL RIGHTS RESERVED.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 import os
18
19 from emuvim.api.openstack.resources.net import Net
20 from emuvim.api.osm.kafka import Kafka
21 from emuvim.api.osm.lcm import LCM
22 from emuvim.api.osm.mongo import Mongo
23 from emuvim.api.osm.mysql import Mysql
24 from emuvim.api.osm.nbi import NBI
25 from emuvim.api.osm.ro import RO
26 from emuvim.api.osm.zookeeper import Zookeeper
27
28
29 class OSM:
30 def __init__(self, net,
31 switch,
32 name='osm',
33 vca_host=os.environ.get('VCA_HOST'),
34 vca_secret=os.environ.get('VCA_SECRET'),
35 osm_version='releasefive-daily',
36 ip_start='10.0.0.100'):
37 ip_int = Net.ip_2_int(ip_start)
38 zookeeper_ip = ip_start
39 kafka_ip = Net.int_2_ip(ip_int + 1)
40 mongo_ip = Net.int_2_ip(ip_int + 2)
41 nbi_ip = Net.int_2_ip(ip_int + 3)
42 ro_db_ip = Net.int_2_ip(ip_int + 4)
43 ro_ip = Net.int_2_ip(ip_int + 5)
44 lcm_ip = Net.int_2_ip(ip_int + 6)
45
46 name_prefix = '%s-' % name
47 self.zookeeper = Zookeeper(net, '%s/16' % zookeeper_ip, name_prefix=name_prefix)
48 self.kafka = Kafka(net, '%s/16' % kafka_ip, zookeeper_ip, name_prefix=name_prefix)
49 self.mongo = Mongo(net, '%s/16' % mongo_ip, name_prefix=name_prefix)
50 self.nbi = NBI(net, '%s/16' % nbi_ip, mongo_ip, kafka_ip, version=osm_version, name_prefix=name_prefix)
51 self.ro_db = Mysql(net, '%s/16' % ro_db_ip, name_prefix=name_prefix)
52 self.ro = RO(net, '%s/16' % ro_ip, ro_db_ip, version=osm_version, name_prefix=name_prefix)
53 self.lcm = LCM(net, '%s/16' % lcm_ip, ro_ip, mongo_ip, kafka_ip,
54 vca_host, vca_secret, version=osm_version, name_prefix=name_prefix)
55
56 net.addLink(self.zookeeper.instance, switch)
57 net.addLink(self.kafka.instance, switch)
58 net.addLink(self.mongo.instance, switch)
59 net.addLink(self.nbi.instance, switch)
60 net.addLink(self.ro_db.instance, switch)
61 net.addLink(self.ro.instance, switch)
62 net.addLink(self.lcm.instance, switch)
63
64 def start(self):
65 self.zookeeper.start()
66 self.kafka.start()
67 self.mongo.start()
68 self.nbi.start()
69 self.ro_db.start()
70 self.ro.start()
71 self.lcm.start()
72
73 # forward api related calls
74 def onboard_vnfd(self, *args, **kwargs):
75 return self.nbi.onboard_vnfd(*args, **kwargs)
76
77 def onboard_nsd(self, *args, **kwargs):
78 return self.nbi.onboard_nsd(*args, **kwargs)
79
80 def register_emulated_api(self, *args, **kwargs):
81 return self.nbi.register_emulated_api(*args, **kwargs)
82
83 def ns_list(self):
84 return self.nbi.ns_list()
85
86 def ns_create(self, *args, **kwargs):
87 return self.nbi.ns_create(*args, **kwargs)
88
89 def ns_delete(self, *args, **kwargs):
90 return self.nbi.ns_delete(*args, **kwargs)
91
92 def ns_get(self, *args, **kwargs):
93 return self.nbi.ns_get(*args, **kwargs)
94
95 def ns_action(self, *args, **kwargs):
96 return self.nbi.ns_action(*args, **kwargs)
97
98 def ns_wait_until_all_in_status(self, *args, **kwargs):
99 return self.nbi.ns_wait_until_all_in_status(*args, **kwargs)