Create new class in the agent

This commit is contained in:
Ofer Ben-Yacov 2017-01-22 13:30:50 +02:00
parent 8fab78a8cd
commit f12e55bb4d
6 changed files with 74 additions and 34 deletions

View File

@ -24,6 +24,9 @@ from neutron import service as neutron_service
from wan_qos.common import topics
import eventlet
eventlet.monkey_patch()
WANTC_OPTS = [
cfg.StrOpt('lan_port_name',
default='eth0',
@ -45,6 +48,7 @@ def main():
common_config.init(sys.argv[1:])
config.setup_logging()
server = neutron_service.Service.create(
binary='tc_agent2',
topic=topics.TC_AGENT,
report_interval=10,
manager='wan_qos.agent.tc_manager.TcAgentManager')

View File

@ -57,8 +57,10 @@ class TcDriver(agent_api.AgentInterface):
max - maximum traffic rate. if not provide, the maximum rate will
be limitted by parent maximum rate.
"""
LOG.debug('got request for new class: %s' % tc_dict)
tc_dict['command'] = 'add'
self._create_or_update_limiter(tc_dict)
LOG.debug('new class created.')
def update_traffic_limiter(self, tc_dict):
tc_dict['command'] = 'change'
@ -81,7 +83,7 @@ class TcDriver(agent_api.AgentInterface):
tc_dict['parent'], tc_dict['child'],
tc_dict['min']
)
if tc_dict['max']:
if 'max' in tc_dict:
cmd += ' ceil %s' % tc_dict['max']
check_call(cmd, shell=True)

View File

@ -18,6 +18,7 @@ from oslo_log import log as logging
import oslo_messaging as messaging
from neutron import context as ctx
from neutron import manager
from wan_qos.agent import tc_driver
from wan_qos.common import api
@ -26,7 +27,7 @@ from wan_qos.common import topics
LOG = logging.getLogger(__name__)
class TcAgentManager:
class TcAgentManager(manager.Manager):
target = messaging.Target(version='1.0')
def __init__(self, host=None, conf=None):
@ -65,3 +66,28 @@ class TcAgentManager:
def periodic_tasks(self, context, raise_on_error=False):
LOG.info("periodic task")
self.plugin_rpc.device_heartbeat(context, self.host)
def create_wtc_class(self, context, wtc_class_dict):
LOG.debug('got request for new class: %s' % wtc_class_dict)
class_dict = {
'parent': wtc_class_dict['parent_class_ext_id'],
'child': wtc_class_dict['class_ext_id']
}
if wtc_class_dict['min']:
class_dict['min'] = wtc_class_dict['min']
if wtc_class_dict['max']:
class_dict['max'] = wtc_class_dict['max']
if wtc_class_dict['direction'] == 'in' or wtc_class_dict[
'direction'] == 'both':
class_dict['port_side'] = 'lan_port'
self._create_wtc_class(class_dict)
if wtc_class_dict['direction'] == 'out' or wtc_class_dict[
'direction'] == 'both':
class_dict['port_side'] = 'wan_port'
self._create_wtc_class(class_dict)
def _create_wtc_class(self, class_dict):
self.agent.create_traffic_limiter(class_dict)

View File

@ -52,8 +52,8 @@ class TcAgentApi(object):
target = oslo_messaging.Target(topic=topic, version='1.0')
self.client = n_rpc.get_client(target)
def create_wan_qos(self, context, wan_qos_dict):
def create_wtc_class(self, context, wtc_class_dict):
cctxt = self.client.prepare()
return cctxt.call(context,
'create_wan_qos',
wan_qos_dict)
'create_wtc_class',
wtc_class_dict=wtc_class_dict)

View File

@ -20,6 +20,7 @@ from oslo_utils import timeutils
from oslo_log import log as logging
from neutron.db.models import segment
from neutron_lib import exceptions
from wan_qos.db.models import wan_tc as models
from wan_qos.common import constants
@ -77,11 +78,11 @@ class WanTcDb(object):
self._lock.acquire()
if not self._last_class_ext_id:
last_class_ext_id_db, = context.session.query(
last_class_ext_id_db = context.session.query(
models.WanTcClass.class_ext_id).order_by(
models.WanTcClass.class_ext_id.desc()).first()
models.WanTcClass.class_ext_id.desc())
if last_class_ext_id_db:
self._last_class_ext_id = last_class_ext_id_db
self._last_class_ext_id, = last_class_ext_id_db.first()
else:
self._last_class_ext_id = 10
self._last_class_ext_id += 1
@ -98,8 +99,13 @@ class WanTcDb(object):
)
parent = wtc_class['parent']
parent_class_ext_id = 1
if parent:
parent_class = self.get_class_by_id(context, parent)
if not parent_class:
raise exceptions.BadRequest(msg='invalid parent id')
wtc_class_db.parent = parent
parent_class_ext_id = parent_class['class_ext_id']
else:
wtc_class_db.parent = wtc_class_db.id
@ -111,7 +117,9 @@ class WanTcDb(object):
wtc_class_db.max = wtc_class['max']
context.session.add(wtc_class_db)
return self._class_to_dict(wtc_class_db)
class_dict = self._class_to_dict(wtc_class_db)
class_dict['parent_class_ext_id'] = parent_class_ext_id
return class_dict
def delete_wtc_class(self, context, id):
wtc_class_db = context.session.query(models.WanTcClass).filter_by(
@ -139,7 +147,8 @@ class WanTcDb(object):
'id': wtc_class.id,
'direction': wtc_class.direction,
'min': wtc_class.min,
'max': wtc_class.max
'max': wtc_class.max,
'class_ext_id': wtc_class.class_ext_id
}
if wtc_class.parent == wtc_class.id:

View File

@ -87,26 +87,6 @@ class WanQosPlugin(wanqos.WanQosPluginBase,
"""Get description of the plugin."""
return 'Plugin for rate limiting on WAN links.'
def get_wan_tc(self, context, id, fields=None):
pass
def get_wan_tcs(self, context, filters=None, fields=None,
sorts=None, limit=None, marker=None,
page_reverse=False):
pass
def delete_wan_tc(self, context, id):
pass
def update_wan_tc(self, context, id, wan_qos):
pass
def create_wan_tc(self, context, wan_qos):
pass
# self.agent_rpc.create_wan_qos(context, wan_qos)
# tenant_id = self._get_tenant_id_for_create(context, wan_qos_class)
def get_wan_tc_class(self, context, id, fields=None):
return self.db.get_class_by_id(context, id)
@ -116,10 +96,9 @@ class WanQosPlugin(wanqos.WanQosPluginBase,
def create_wan_tc_class(self, context, wan_tc_class):
LOG.debug('got new class request: %s' % wan_tc_class)
wtc_class_db = self.db.create_wan_tc_class(context,
wan_tc_class['wan_tc_class'])
wan_tc_class[
'wan_tc_class'])
self.agent_rpc.create_wtc_class(context, wtc_class_db)
return wtc_class_db
def delete_wan_tc_class(self, context, id):
@ -141,3 +120,23 @@ class WanQosPlugin(wanqos.WanQosPluginBase,
else:
tenant_id = context.tenant_id
return tenant_id
def get_wan_tc(self, context, id, fields=None):
pass
def get_wan_tcs(self, context, filters=None, fields=None,
sorts=None, limit=None, marker=None,
page_reverse=False):
pass
def delete_wan_tc(self, context, id):
pass
def update_wan_tc(self, context, id, wan_qos):
pass
def create_wan_tc(self, context, wan_qos):
pass
# self.agent_rpc.create_wan_qos(context, wan_qos)
# tenant_id = self._get_tenant_id_for_create(context, wan_qos_class)