~niedbalski/ubuntu/vivid/neutron/fixes-1447803

« back to all changes in this revision

Viewing changes to neutron/db/metering/metering_db.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-10-03 18:45:23 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20141003184523-4mt6dy1q3j8n30c9
Tags: 1:2014.2~rc1-0ubuntu1
* New upstream release candidate:
  - d/p/*: Refreshed.
  - d/control: Add python-requests-mock to BD's.
  - d/control: Align versioned requirements with upstream.
* Transition linuxbridge and openvswitch plugin users to modular
  layer 2 plugin (LP: #1323729):
  - d/control: Mark removed plugin packages as transitional, depend
    on neutron-plugin-ml2, mark oldlibs/extra.
  - d/neutron-plugin-{linuxbridge,openvswitch}.install: Drop.
  - d/control: Depend on neutron-plugin-ml2 for linuxbridge
    agent package.
  - d/neutron-plugin-linuxbridge-agent.upstart: Use ml2 plugin
    configuration files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
2
2
#
3
 
# Author: Sylvain Afchain <sylvain.afchain@enovance.com>
4
 
#
5
3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
4
# not use this file except in compliance with the License. You may obtain
7
5
# a copy of the License at
54
52
        primaryjoin="MeteringLabel.tenant_id==Router.tenant_id",
55
53
        foreign_keys='MeteringLabel.tenant_id',
56
54
        uselist=True)
 
55
    shared = sa.Column(sa.Boolean, default=False, server_default=sql.false())
57
56
 
58
57
 
59
58
class MeteringDbMixin(metering.MeteringPluginBase,
66
65
        res = {'id': metering_label['id'],
67
66
               'name': metering_label['name'],
68
67
               'description': metering_label['description'],
 
68
               'shared': metering_label['shared'],
69
69
               'tenant_id': metering_label['tenant_id']}
70
70
        return self._fields(res, fields)
71
71
 
77
77
            metering_db = MeteringLabel(id=uuidutils.generate_uuid(),
78
78
                                        description=m['description'],
79
79
                                        tenant_id=tenant_id,
80
 
                                        name=m['name'])
 
80
                                        name=m['name'],
 
81
                                        shared=m['shared'])
81
82
            context.session.add(metering_db)
82
83
 
83
84
        return self._make_metering_label_dict(metering_db)
207
208
 
208
209
        return res
209
210
 
210
 
    def _process_sync_metering_data(self, labels):
 
211
    def _process_sync_metering_data(self, context, labels):
 
212
        all_routers = None
 
213
 
211
214
        routers_dict = {}
212
215
        for label in labels:
213
 
            routers = label.routers
 
216
            if label.shared:
 
217
                if not all_routers:
 
218
                    all_routers = self._get_collection_query(context,
 
219
                                                             l3_db.Router)
 
220
                routers = all_routers
 
221
            else:
 
222
                routers = label.routers
 
223
 
214
224
            for router in routers:
215
225
                router_dict = routers_dict.get(
216
226
                    router['id'],
234
244
            labels = (labels.join(MeteringLabel.routers).
235
245
                      filter(l3_db.Router.id.in_(router_ids)))
236
246
 
237
 
        return self._process_sync_metering_data(labels)
 
247
        return self._process_sync_metering_data(context, labels)