added REST API endpoint to OpenStack example to have son-emu-cli working
[osm/vim-emu.git] / src / emuvim / examples / openstack_single_dc.py
1 """
2 Copyright (c) 2015 SONATA-NFV
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 Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION]
18 nor the names of its contributors may be used to endorse or promote
19 products derived from this software without specific prior written
20 permission.
21
22 This work has been performed in the framework of the SONATA project,
23 funded by the European Commission under Grant number 671517 through
24 the Horizon 2020 and 5G-PPP programmes. The authors would like to
25 acknowledge the contributions of their colleagues of the SONATA
26 partner consortium (www.sonata-nfv.eu).
27 """
28 import logging
29 from mininet.log import setLogLevel
30 from emuvim.dcemulator.net import DCNetwork
31 from emuvim.api.rest.rest_api_endpoint import RestApiEndpoint
32 from emuvim.api.openstack.openstack_api_endpoint import OpenstackApiEndpoint
33
34 logging.basicConfig(level=logging.INFO)
35
36
37 def create_topology():
38 net = DCNetwork(monitor=False, enable_learning=False)
39
40 dc1 = net.addDatacenter("dc1")
41 # add OpenStack-like APIs to the emulated DC
42 api1 = OpenstackApiEndpoint("0.0.0.0", 6001)
43 api1.connect_datacenter(dc1)
44 api1.start()
45 api1.connect_dc_network(net)
46 # add the command line interface endpoint to the emulated DC (REST API)
47 rapi1 = RestApiEndpoint("0.0.0.0", 5001)
48 rapi1.connectDCNetwork(net)
49 rapi1.connectDatacenter(dc1)
50 rapi1.start()
51
52 net.start()
53 net.CLI()
54 # when the user types exit in the CLI, we stop the emulator
55 net.stop()
56
57
58 def main():
59 setLogLevel('info') # set Mininet loglevel
60 create_topology()
61
62
63 if __name__ == '__main__':
64 main()