Provide API for allowing full stack emulation
[osm/vim-emu.git] / src / emuvim / api / osm / pre_configured_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.openstack_api_endpoint import OpenstackApiEndpoint
20 from emuvim.api.osm.osm import OSM
21 from emuvim.dcemulator.net import DCNetwork
22
23
24 class PreConfiguredOSM:
25 def __init__(self,
26 vca_host=os.environ.get('VCA_HOST'),
27 vca_secret=os.environ.get('VCA_SECRET'),
28 osm_version='releasefive-daily'):
29 self.net = DCNetwork(monitor=False, enable_learning=True)
30 dc1 = self.net.addDatacenter("dc1")
31 self.api = OpenstackApiEndpoint("0.0.0.0", 6001)
32 self.api.connect_datacenter(dc1)
33 self.api.connect_dc_network(self.net)
34
35 s1 = self.net.addSwitch('s1')
36 self.osm = OSM(self.net, s1, vca_host=vca_host, vca_secret=vca_secret, osm_version=osm_version)
37 self.vim_emu_id = None
38
39 def __enter__(self):
40 self.start()
41 return self
42
43 def __exit__(self, exc_type, exc_val, exc_tb):
44 self.stop()
45
46 def start(self):
47 self.net.start()
48 self.api.start()
49 self.osm.start()
50 self.vim_emu_id = self.osm.register_emulated_api('emu-vim1', self.api)
51
52 def stop(self):
53 self.api.stop()
54 self.net.stop()
55
56 def ns_create(self, ns_name, nsd_id):
57 return self.osm.ns_create(ns_name, nsd_id, self.vim_emu_id)
58
59 # forward api related calls
60 def onboard_vnfd(self, *args, **kwargs):
61 return self.osm.onboard_vnfd(*args, **kwargs)
62
63 def onboard_nsd(self, *args, **kwargs):
64 return self.osm.onboard_nsd(*args, **kwargs)
65
66 def ns_list(self):
67 return self.osm.ns_list()
68
69 def ns_delete(self, *args, **kwargs):
70 return self.osm.ns_delete(*args, **kwargs)
71
72 def ns_get(self, *args, **kwargs):
73 return self.osm.ns_get(*args, **kwargs)
74
75 def ns_action(self, *args, **kwargs):
76 return self.osm.ns_action(*args, **kwargs)
77
78 def ns_wait_until_all_in_status(self, *args, **kwargs):
79 return self.osm.ns_wait_until_all_in_status(*args, **kwargs)