149
149
raise AttributeError
151
151
def _extend_network_dict(self, context, network):
152
flavor = self._get_flavor_by_network_id(network['id'])
152
flavor = self._get_flavor_by_network_id(context, network['id'])
153
153
network[FLAVOR_NETWORK] = flavor
155
155
def _is_l3_plugin(self, plugin):
169
169
LOG.debug("Created network: %s with flavor %s " % (net['id'],
172
meta_db_v2.add_network_flavor_binding(flavor, str(net['id']))
172
meta_db_v2.add_network_flavor_binding(context.session,
173
flavor, str(net['id']))
174
175
LOG.exception('failed to add flavor bindings')
175
176
plugin.delete_network(context, net['id'])
182
183
def update_network(self, context, id, network):
183
flavor = meta_db_v2.get_flavor_by_network(id)
184
flavor = meta_db_v2.get_flavor_by_network(context.session, id)
184
185
plugin = self._get_plugin(flavor)
185
186
with context.session.begin(subtransactions=True):
186
187
net = plugin.update_network(context, id, network)
192
193
def delete_network(self, context, id):
193
flavor = meta_db_v2.get_flavor_by_network(id)
194
flavor = meta_db_v2.get_flavor_by_network(context.session, id)
194
195
plugin = self._get_plugin(flavor)
195
196
return plugin.delete_network(context, id)
197
198
def get_network(self, context, id, fields=None):
198
flavor = meta_db_v2.get_flavor_by_network(id)
199
flavor = meta_db_v2.get_flavor_by_network(context.session, id)
199
200
plugin = self._get_plugin(flavor)
200
201
net = plugin.get_network(context, id, fields)
234
def _get_flavor_by_network_id(self, network_id):
235
return meta_db_v2.get_flavor_by_network(network_id)
237
def _get_flavor_by_router_id(self, router_id):
238
return meta_db_v2.get_flavor_by_router(router_id)
240
def _get_plugin_by_network_id(self, network_id):
241
flavor = self._get_flavor_by_network_id(network_id)
235
def _get_flavor_by_network_id(self, context, network_id):
236
return meta_db_v2.get_flavor_by_network(context.session, network_id)
238
def _get_flavor_by_router_id(self, context, router_id):
239
return meta_db_v2.get_flavor_by_router(context.session, router_id)
241
def _get_plugin_by_network_id(self, context, network_id):
242
flavor = self._get_flavor_by_network_id(context, network_id)
242
243
return self._get_plugin(flavor)
244
245
def create_port(self, context, port):
246
247
if not 'network_id' in p:
247
248
raise exc.NotFound
248
plugin = self._get_plugin_by_network_id(p['network_id'])
249
plugin = self._get_plugin_by_network_id(context, p['network_id'])
249
250
return plugin.create_port(context, port)
251
252
def update_port(self, context, id, port):
252
253
port_in_db = self.get_port(context, id)
253
plugin = self._get_plugin_by_network_id(port_in_db['network_id'])
254
plugin = self._get_plugin_by_network_id(context,
255
port_in_db['network_id'])
254
256
return plugin.update_port(context, id, port)
256
258
def delete_port(self, context, id, l3_port_check=True):
257
259
port_in_db = self.get_port(context, id)
258
plugin = self._get_plugin_by_network_id(port_in_db['network_id'])
260
plugin = self._get_plugin_by_network_id(context,
261
port_in_db['network_id'])
259
262
if l3_port_check:
260
263
self.prevent_l3_port_deletion(context, id)
261
264
self.disassociate_floatingips(context, id)
265
268
s = subnet['subnet']
266
269
if not 'network_id' in s:
267
270
raise exc.NotFound
268
plugin = self._get_plugin_by_network_id(s['network_id'])
271
plugin = self._get_plugin_by_network_id(context,
269
273
return plugin.create_subnet(context, subnet)
271
275
def update_subnet(self, context, id, subnet):
272
276
s = self.get_subnet(context, id)
273
plugin = self._get_plugin_by_network_id(s['network_id'])
277
plugin = self._get_plugin_by_network_id(context,
274
279
return plugin.update_subnet(context, id, subnet)
276
281
def delete_subnet(self, context, id):
277
282
s = self.get_subnet(context, id)
278
plugin = self._get_plugin_by_network_id(s['network_id'])
283
plugin = self._get_plugin_by_network_id(context,
279
285
return plugin.delete_subnet(context, id)
281
287
def _extend_router_dict(self, context, router):
282
flavor = self._get_flavor_by_router_id(router['id'])
288
flavor = self._get_flavor_by_router_id(context, router['id'])
283
289
router[FLAVOR_ROUTER] = flavor
285
291
def create_router(self, context, router):
288
294
if not str(flavor) in self.l3_plugins:
289
295
flavor = self.default_l3_flavor
290
296
plugin = self._get_l3_plugin(flavor)
291
r_in_db = plugin.create_router(context, router)
292
LOG.debug("Created router: %s with flavor %s " % (r_in_db['id'],
295
meta_db_v2.add_router_flavor_binding(flavor, str(r_in_db['id']))
297
LOG.exception('failed to add flavor bindings')
298
plugin.delete_router(context, r_in_db['id'])
299
raise FaildToAddFlavorBinding()
297
with context.session.begin(subtransactions=True):
298
r_in_db = plugin.create_router(context, router)
299
LOG.debug("Created router: %s with flavor %s " % (r_in_db['id'],
301
meta_db_v2.add_router_flavor_binding(context.session,
302
flavor, str(r_in_db['id']))
301
304
LOG.debug("Created router: %s" % r_in_db['id'])
302
305
self._extend_router_dict(context, r_in_db)
305
308
def update_router(self, context, id, router):
306
flavor = meta_db_v2.get_flavor_by_router(id)
309
flavor = meta_db_v2.get_flavor_by_router(context.session, id)
307
310
plugin = self._get_l3_plugin(flavor)
308
311
return plugin.update_router(context, id, router)
310
313
def delete_router(self, context, id):
311
flavor = meta_db_v2.get_flavor_by_router(id)
314
flavor = meta_db_v2.get_flavor_by_router(context.session, id)
312
315
plugin = self._get_l3_plugin(flavor)
313
316
return plugin.delete_router(context, id)
315
318
def get_router(self, context, id, fields=None):
316
flavor = meta_db_v2.get_flavor_by_router(id)
319
flavor = meta_db_v2.get_flavor_by_router(context.session, id)
317
320
plugin = self._get_l3_plugin(flavor)
318
321
router = plugin.get_router(context, id, fields)
319
322
if not fields or FLAVOR_ROUTER in fields: