tc-as-a-service/wan_qos/agent/tc_manager.py

65 lines
2.0 KiB
Python

# Copyright 2016 Huawei corp.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging as messaging
from neutron import context as ctx
from wan_qos.agent import tc_driver
from wan_qos.common import api
from wan_qos.common import topics
LOG = logging.getLogger(__name__)
class TcAgentManager:
target = messaging.Target(version='1.0')
def __init__(self, host=None, conf=None):
self.agent = tc_driver.TcDriver()
if not conf:
self.conf = cfg.CONF
else:
self.conf = conf
if not host:
host = self.conf.host
lan_port = self.conf.WANQOS.lan_port_name
wan_port = self.conf.WANQOS.wan_port_name
self.agent.set_ports(lan_port, wan_port)
self.plugin_rpc = api.TcPluginApi(host, topics.TC_PLUGIN)
def init_host(self):
self.agent.clear_all()
tc_dict = {
'port_side': 'lan_port',
'max_rate': self.conf.WANQOS.lan_max_rate
}
self.agent.set_root_queue(tc_dict)
tc_dict = {
'port_side': 'wan_port',
'max_rate': self.conf.WANQOS.wan_max_rate
}
self.agent.set_root_queue(tc_dict)
def after_start(self):
LOG.info("WAN QoS agent started")
def periodic_tasks(self, context, raise_on_error=False):
LOG.info(
self.plugin_rpc.agent_up_notification(ctx.get_admin_context()))