Use Meter Label OVO in neutron/db/metering/metering_db.py

This patch includes Meter Label OVO in neutron/db/metering/metering_db.py.

Change-Id: I39e811676b17d89b7bc60873adeb082181fd5786
Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
This commit is contained in:
Lujin 2018-01-24 18:35:41 +09:00
parent 7e3d6a18fb
commit 571206302b
2 changed files with 17 additions and 16 deletions

View File

@ -1067,12 +1067,14 @@ class L3_NAT_with_dvr_db_mixin(_DVRAgentInterfaceMixin,
def is_distributed_router(router):
"""Return True if router to be handled is distributed."""
try:
# See if router is a DB object first
requested_router_type = router.extra_attributes.distributed
except AttributeError:
# if not, try to see if it is a request body
# See if router is a request body
if isinstance(router, dict):
requested_router_type = router.get('distributed')
# If not, see if router DB or OVO object contains Extra Attributes
elif router.extra_attributes:
requested_router_type = router.extra_attributes.distributed
else:
requested_router_type = None
if validators.is_attr_set(requested_router_type):
return requested_router_type
return cfg.CONF.router_distributed

View File

@ -23,7 +23,6 @@ from neutron.db import _utils as db_utils
from neutron.db import api as db_api
from neutron.db import common_db_mixin as base_db
from neutron.db import l3_dvr_db
from neutron.db.models import metering as metering_models
from neutron.extensions import metering
from neutron.objects import base as base_obj
from neutron.objects import metering as metering_objs
@ -188,7 +187,9 @@ class MeteringDbMixin(metering.MeteringPluginBase,
if not routers:
routers = l3_obj.Router.get_objects(context)
else:
routers = label.routers
filters = {
'id': [router.id for router in label.db_obj.routers]}
routers = l3_obj.Router.get_objects(context, **filters)
for router in routers:
if not router['admin_state_up']:
@ -207,14 +208,14 @@ class MeteringDbMixin(metering.MeteringPluginBase,
return list(routers_dict.values())
def get_sync_data_for_rule(self, context, rule):
label = context.session.query(
metering_models.MeteringLabel).get(
rule['metering_label_id'])
label = metering_objs.MeteringLabel.get_object(
context, id=rule['metering_label_id'])
if label.shared:
routers = l3_obj.Router.get_objects(context)
else:
routers = label.routers
filters = {'id': [router.id for router in label.db_obj.routers]}
routers = l3_obj.Router.get_objects(context, **filters)
routers_dict = {}
for router in routers:
@ -227,10 +228,8 @@ class MeteringDbMixin(metering.MeteringPluginBase,
return list(routers_dict.values())
def get_sync_data_metering(self, context, label_id=None):
labels = context.session.query(metering_models.MeteringLabel)
if label_id:
labels = labels.filter(
metering_models.MeteringLabel.id == label_id)
filters = {'id': [label_id]} if label_id else {}
labels = metering_objs.MeteringLabel.get_objects(
context, **filters)
return self._process_sync_metering_data(context, labels)