Fix: Added gevent monkey patch to fix issue that blocks
[osm/vim-emu.git] / examples / full_stack_emulation_multiple_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
18 from emuvim.api.openstack.openstack_api_endpoint import OpenstackApiEndpoint
19 from emuvim.api.osm.osm import OSM
20 from emuvim.dcemulator.net import DCNetwork
21
22 net = DCNetwork(monitor=False, enable_learning=True)
23 dc1 = net.addDatacenter("dc1")
24 api = OpenstackApiEndpoint("0.0.0.0", 6001)
25 api.connect_datacenter(dc1)
26 api.connect_dc_network(net)
27
28 try:
29 s1 = net.addSwitch('s1')
30 s2 = net.addSwitch('s2')
31 osm1 = OSM(net, s1, name='1')
32 osm2 = OSM(net, s2, name='2')
33
34 net.start()
35 api.start()
36 osm1.start()
37 print('osm1 up!')
38 osm2.start()
39 print('osm2 up!')
40
41 vim_id1 = osm1.register_emulated_api('vim', api)
42 osm1.onboard_vnfd('vnfs/ping_vnf')
43 osm1.onboard_vnfd('vnfs/pong_vnf')
44 nsd_id1 = osm1.onboard_nsd('services/pingpong_ns')
45 ns_id1 = osm1.ns_create('pingpong-test1', nsd_id1, vim_id1)
46
47 vim_id2 = osm2.register_emulated_api('vim', api)
48 osm2.onboard_vnfd('vnfs/ping_vnf')
49 osm2.onboard_vnfd('vnfs/pong_vnf')
50 nsd_id2 = osm2.onboard_nsd('services/pingpong_ns')
51 ns_id2 = osm2.ns_create('pingpong-test2', nsd_id2, vim_id2)
52
53 osm1.ns_wait_until_all_in_status('running')
54 osm2.ns_wait_until_all_in_status('running')
55 print('all ready!')
56
57 osm1.ns_delete(ns_id1)
58 osm2.ns_delete(ns_id2)
59
60 osm1.ns_wait_until_all_in_status('terminated')
61 osm2.ns_wait_until_all_in_status('terminated')
62 print('all deleted!')
63
64 finally:
65 api.stop()
66 net.stop()