From 9c7a31f78080f345ceca45e73d36a9d463797c43 Mon Sep 17 00:00:00 2001 From: Ofer Ben-Yacov Date: Thu, 26 Jan 2017 15:41:27 +0200 Subject: [PATCH] get class by agent --- wan_qos/agent/tc_manager.py | 10 ++++++++-- wan_qos/common/api.py | 4 ++++ wan_qos/db/wan_qos_db.py | 7 ++++--- wan_qos/services/plugin.py | 10 +++++++--- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/wan_qos/agent/tc_manager.py b/wan_qos/agent/tc_manager.py index 501f943..f39cb37 100644 --- a/wan_qos/agent/tc_manager.py +++ b/wan_qos/agent/tc_manager.py @@ -60,11 +60,16 @@ class TcAgentManager(manager.Manager): 'max_rate': self.conf.WANTC.wan_max_rate } self.agent.set_root_queue(tc_dict) + context = ctx.get_admin_context() agent_conf = self.plugin_rpc.get_configuration_from_db( - ctx.get_admin_context()) + context) class_tree = agent_conf['class_tree'] if class_tree['id'] == 'root': self.init_child_classes(class_tree['child_list']) + + if 'filters' in agent_conf: + for filter in agent_conf['filters']: + self.create_wtc_filter(context, filter) return raise exceptions.InvalidInput(error_message='Did not get root class') @@ -124,7 +129,8 @@ class TcAgentManager(manager.Manager): def create_wtc_filter(self, context, wtc_filter): - wtc_class = wtc_filter['class'] + wtc_class = self.plugin_rpc.get_class_by_id(context, + wtc_filter['class_id']) tc_dict = { 'child': wtc_class['class_ext_id'], diff --git a/wan_qos/common/api.py b/wan_qos/common/api.py index 3d26145..60295f8 100644 --- a/wan_qos/common/api.py +++ b/wan_qos/common/api.py @@ -45,6 +45,10 @@ class TcPluginApi(object): cctxt = self.client.prepare() return cctxt.call(context, 'get_configuration_from_db', host=self.host) + def get_class_by_id(self, context, id): + cctxt = self.client.prepare() + return cctxt.call(context, 'get_class_by_id', id=id) + class TcAgentApi(object): def __init__(self, host, topic=topics.TC_AGENT): diff --git a/wan_qos/db/wan_qos_db.py b/wan_qos/db/wan_qos_db.py index 32cec58..9312625 100644 --- a/wan_qos/db/wan_qos_db.py +++ b/wan_qos/db/wan_qos_db.py @@ -306,9 +306,10 @@ class WanTcDb(object): return items def _has_attribute(self, model, filters): - for key in filters.keys(): - if not hasattr(model, key): - return False + if filters: + for key in filters.keys(): + if not hasattr(model, key): + return False return True def _get_collection_query(self, context, model, filters=None, diff --git a/wan_qos/services/plugin.py b/wan_qos/services/plugin.py index 8934e0d..088fe2b 100644 --- a/wan_qos/services/plugin.py +++ b/wan_qos/services/plugin.py @@ -51,11 +51,15 @@ class PluginRpcCallback(object): def get_configuration_from_db(self, context, host): conf = { - 'class_tree': self.plugin.db.get_class_tree() + 'class_tree': self.plugin.db.get_class_tree(), + 'filters': self.plugin.db.get_wan_tc_filters(context) } return conf + def get_class_by_id(self, context, id): + return self.plugin.db.get_class_by_id(context, id) + class WanQosPlugin(wantcfilter.WanTcFilterPluginBase, wantcdevice.WanTcDevicePluginBase, @@ -140,8 +144,8 @@ class WanQosPlugin(wantcfilter.WanTcFilterPluginBase, wtc_filter = self.db.create_wan_tc_filter(context, wan_tc_filter[ 'wan_tc_filter']) - wtc_class = self.get_wan_tc_class(context, wtc_filter['class_id']) - wtc_filter['class'] = wtc_class + # wtc_class = self.get_wan_tc_class(context, wtc_filter['class_id']) + # wtc_filter['class'] = wtc_class self.agent_rpc.create_wtc_filter(context, wtc_filter) return wtc_filter