~ubuntu-branches/ubuntu/raring/quantum/raring

« back to all changes in this revision

Viewing changes to quantum/plugins/metaplugin/meta_quantum_plugin.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-09-21 13:01:18 UTC
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20120921130118-6x31znohp1psfc74
Tags: upstream-2012.2~rc2
ImportĀ upstreamĀ versionĀ 2012.2~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
149
149
        raise AttributeError
150
150
 
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
154
154
 
155
155
    def _is_l3_plugin(self, plugin):
169
169
            LOG.debug("Created network: %s with flavor %s " % (net['id'],
170
170
                                                               flavor))
171
171
            try:
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']))
173
174
            except:
174
175
                LOG.exception('failed to add flavor bindings')
175
176
                plugin.delete_network(context, net['id'])
180
181
        return net
181
182
 
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)
190
191
        return net
191
192
 
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)
196
197
 
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)
201
202
        net['id'] = id
231
232
                for net in nets]
232
233
        return nets
233
234
 
234
 
    def _get_flavor_by_network_id(self, network_id):
235
 
        return meta_db_v2.get_flavor_by_network(network_id)
236
 
 
237
 
    def _get_flavor_by_router_id(self, router_id):
238
 
        return meta_db_v2.get_flavor_by_router(router_id)
239
 
 
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)
 
237
 
 
238
    def _get_flavor_by_router_id(self, context, router_id):
 
239
        return meta_db_v2.get_flavor_by_router(context.session, router_id)
 
240
 
 
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)
243
244
 
244
245
    def create_port(self, context, port):
245
246
        p = port['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)
250
251
 
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)
255
257
 
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,
 
272
                                                s['network_id'])
269
273
        return plugin.create_subnet(context, subnet)
270
274
 
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,
 
278
                                                s['network_id'])
274
279
        return plugin.update_subnet(context, id, subnet)
275
280
 
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,
 
284
                                                s['network_id'])
279
285
        return plugin.delete_subnet(context, id)
280
286
 
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
284
290
 
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'],
293
 
                                                          flavor))
294
 
        try:
295
 
            meta_db_v2.add_router_flavor_binding(flavor, str(r_in_db['id']))
296
 
        except:
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'],
 
300
                                                              flavor))
 
301
            meta_db_v2.add_router_flavor_binding(context.session,
 
302
                                                 flavor, str(r_in_db['id']))
300
303
 
301
304
        LOG.debug("Created router: %s" % r_in_db['id'])
302
305
        self._extend_router_dict(context, r_in_db)
303
306
        return r_in_db
304
307
 
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)
309
312
 
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)
314
317
 
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: