31 from neutron.db import model_base |
31 from neutron.db import model_base |
32 from neutron.plugins.evs.migrate import havana_api |
32 from neutron.plugins.evs.migrate import havana_api |
33 |
33 |
34 import sqlalchemy as sa |
34 import sqlalchemy as sa |
35 from sqlalchemy import MetaData |
35 from sqlalchemy import MetaData |
|
36 from sqlalchemy.orm import sessionmaker |
36 from sqlalchemy.schema import DropConstraint |
37 from sqlalchemy.schema import DropConstraint |
37 from sqlalchemy import sql |
38 from sqlalchemy import sql |
38 |
39 |
39 from oslo.config import cfg |
40 from oslo.config import cfg |
40 from oslo.db import options as db_options |
41 from oslo.db import options as db_options |
41 from oslo.db import exception as excp |
42 from oslo.db import exception as excp |
42 |
43 |
43 |
44 |
44 def create_db_network(nw, engine): |
45 def create_db_network(nw, engine, ext_ro): |
45 ''' Method for creating networks table in the neutron-server DB |
46 ''' Method for creating networks table in the neutron-server DB |
46 Input params: |
47 Input params: |
47 @nw - Dictionary with values from EVS DB |
48 @nw - Dictionary with values from EVS DB |
|
49 @engine - SQL engine |
|
50 @ext_ro - External router |
48 ''' |
51 ''' |
49 # Importing locally because this module ends up importing neutron.wsgi |
52 # Importing locally because these modules end up importing neutron.wsgi |
50 # which causes RAD to hang |
53 # which causes RAD to hang |
51 from neutron.db import db_base_plugin_v2 |
54 from neutron.db import db_base_plugin_v2 |
|
55 from neutron.db import external_net_db as ext_net |
52 model_base.BASEV2.metadata.bind = engine |
56 model_base.BASEV2.metadata.bind = engine |
53 model_base.BASEV2.metadata.create_all(engine) |
57 model_base.BASEV2.metadata.create_all(engine) |
54 ctxt = ctx.get_admin_context() |
58 ctxt = ctx.get_admin_context() |
55 inst = db_base_plugin_v2.NeutronDbPluginV2() |
59 inst = db_base_plugin_v2.NeutronDbPluginV2() |
56 dup = False |
60 dup = False |
57 try: |
61 try: |
58 db_base_plugin_v2.NeutronDbPluginV2.create_network(inst, ctxt, nw) |
62 db_base_plugin_v2.NeutronDbPluginV2.create_network(inst, ctxt, nw) |
59 print "\nnetwork=%s added" % nw['network']['name'] |
63 print "\nnetwork=%s added" % nw['network']['name'] |
|
64 if ext_ro: |
|
65 ext_nw = ext_net.ExternalNetwork(network_id=nw['network']['id']) |
|
66 session = sessionmaker() |
|
67 session.configure(bind=engine) |
|
68 s = session() |
|
69 s.add(ext_nw) |
|
70 s.commit() |
60 except excp.DBDuplicateEntry: |
71 except excp.DBDuplicateEntry: |
61 print "\nnetwork '%s' already exists" % nw['network']['name'] |
72 print "\nnetwork '%s' already exists" % nw['network']['name'] |
62 dup = True |
73 dup = True |
63 return dup |
74 return dup |
64 |
75 |
137 connection=SQL_CONNECTION, |
148 connection=SQL_CONNECTION, |
138 sqlite_db='', max_pool_size=10, |
149 sqlite_db='', max_pool_size=10, |
139 max_overflow=20, pool_timeout=10) |
150 max_overflow=20, pool_timeout=10) |
140 |
151 |
141 neutron_engine = sa.create_engine(SQL_CONNECTION) |
152 neutron_engine = sa.create_engine(SQL_CONNECTION) |
|
153 router_port_ids = {} |
142 |
154 |
143 for e in evsinfo: |
155 for e in evsinfo: |
|
156 ext_ro = False |
|
157 for p in e.props: |
|
158 if p.name == 'OpenStack:router:external' and p.value == 'True': |
|
159 ext_ro = True |
144 # Populate networks table |
160 # Populate networks table |
145 n = { |
161 n = { |
146 'tenant_id': e.tenantname, |
162 'tenant_id': e.tenantname, |
147 'id': e.uuid, |
163 'id': e.uuid, |
148 'name': e.name, |
164 'name': e.name, |
149 'status': 'ACTIVE', |
165 'status': 'ACTIVE', |
150 'admin_state_up': True, |
166 'admin_state_up': True, |
151 'shared': False |
167 'shared': False |
152 } |
168 } |
153 nw = {'network': n} |
169 nw = {'network': n} |
154 dup = create_db_network(nw, neutron_engine) |
170 dup = create_db_network(nw, neutron_engine, ext_ro) |
155 if dup: |
171 if dup: |
156 continue # No need to iterate over subnets and ports |
172 continue # No need to iterate over subnets and ports |
157 |
173 |
158 # Populate subnets table |
174 # Populate subnets table |
159 for i in e.ipnets: |
175 for i in e.ipnets: |
219 mac_address = None |
235 mac_address = None |
220 ipaddr = None |
236 ipaddr = None |
221 for v in j.props: |
237 for v in j.props: |
222 if v.name == 'OpenStack:device_owner': |
238 if v.name == 'OpenStack:device_owner': |
223 device_owner = v.value |
239 device_owner = v.value |
|
240 if v.value in ('network:router_interface', |
|
241 'network:router_gateway'): |
|
242 router_port_ids[j.uuid] = v.value |
224 elif v.name == 'OpenStack:device_id': |
243 elif v.name == 'OpenStack:device_id': |
225 device_id = v.value |
244 device_id = v.value |
226 elif v.name == 'macaddr': |
245 elif v.name == 'macaddr': |
227 mac_address = v.value |
246 mac_address = v.value |
228 elif v.name == 'ipaddr': |
247 elif v.name == 'ipaddr': |
363 with ctxt.session.begin(subtransactions=True): |
383 with ctxt.session.begin(subtransactions=True): |
364 router_db = l3_db.Router(id=router_id, |
384 router_db = l3_db.Router(id=router_id, |
365 tenant_id=r['tenant_id'], |
385 tenant_id=r['tenant_id'], |
366 name=rt['name'], |
386 name=rt['name'], |
367 admin_state_up=rt['admin_state_up'], |
387 admin_state_up=rt['admin_state_up'], |
|
388 gw_port_id=rt['gw_port_id'], |
368 status="ACTIVE") |
389 status="ACTIVE") |
369 ctxt.session.add(router_db) |
390 ctxt.session.add(router_db) |
370 print "\nrouter=%s updated" % rt['name'] |
391 print "\nrouter=%s updated" % rt['name'] |
|
392 with ctxt.session.begin(subtransactions=True): |
|
393 for i, j in router_port_ids.iteritems(): |
|
394 router_port = l3_db.RouterPort( |
|
395 port_id=i, |
|
396 router_id=router_id, |
|
397 port_type=j) |
|
398 ctxt.session.add(router_port) |
371 |
399 |
372 if floatingips: |
400 if floatingips: |
373 ctxt = ctx.get_admin_context() |
401 ctxt = ctx.get_admin_context() |
374 with ctxt.session.begin(subtransactions=True): |
402 with ctxt.session.begin(subtransactions=True): |
375 for i in fl: |
403 for i in fl: |