Add WAN TC Device to DB

This commit is contained in:
Ofer Ben-Yacov 2017-01-10 10:53:15 +02:00
parent 48812773be
commit a8b71e78ed
7 changed files with 75 additions and 15 deletions

View File

@ -31,6 +31,9 @@ class TcDriver(agent_api.AgentInterface):
self.ports['lan_port'] = lan_port
self.ports['wan_port'] = wan_port
def get_ports(self):
return self.ports
def clear_all(self):
for port in self.ports.values():
call('sudo tc qdisc del dev %s root' % port, shell=True)

View File

@ -27,7 +27,6 @@ LOG = logging.getLogger(__name__)
class TcAgentManager:
target = messaging.Target(version='1.0')
def __init__(self, host=None, conf=None):
@ -37,11 +36,13 @@ class TcAgentManager:
else:
self.conf = conf
if not host:
host = self.conf.host
self.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)
self.plugin_rpc.agent_up_notification(ctx.get_admin_context(),
self.agent.get_ports())
def init_host(self):
self.agent.clear_all()
@ -60,5 +61,4 @@ class TcAgentManager:
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()))
LOG.info("periodic task")

View File

@ -26,9 +26,15 @@ class TcPluginApi(object):
target = oslo_messaging.Target(topic=topic, version='1.0')
self.client = n_rpc.get_client(target)
def agent_up_notification(self, context):
def agent_up_notification(self, context, ports):
cctxt = self.client.prepare()
return cctxt.cast(context, 'agent_up_notification', host=self.host)
host_info = {
'host': self.host,
'lan_port': ports['lan_port'],
'wan_port': ports['wan_port']
}
return cctxt.cast(context, 'agent_up_notification',
host_info=host_info)
def get_configuration_from_db(self, context):
cctxt = self.client.prepare()
@ -46,4 +52,3 @@ class TcAgentApi(object):
return cctxt.call(context,
'create_wan_qos',
wan_qos_dict)

View File

@ -61,3 +61,13 @@ def upgrade():
'wan_tc_selector', 'wan_tc_class',
['class_id'], ['id'],
)
op.create_table(
'wan_tc_device',
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('host', sa.String(100), nullable=False),
sa.Column('lan_port', sa.String(15), nullable=False),
sa.Column('wan_port', sa.String(15), nullable=False),
sa.Column('uptime', sa.DateTime()),
sa.Column('heartbeat_timestamp', sa.DateTime())
)

View File

@ -13,13 +13,29 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib.db import model_base
import sqlalchemy as sa
from neutron_lib.db import model_base
class WanTcDevice(model_base.BASEV2,
model_base.HasId):
__tablename__ = 'wan_tc_device'
host = sa.Column(sa.String(100), nullable=False)
lan_port = sa.Column(sa.String(15), nullable=False)
wan_port = sa.Column(sa.String(15), nullable=False)
uptime = sa.Column(sa.DateTime())
heartbeat_timestamp = sa.Column(sa.DateTime())
class WanTcClass(model_base.BASEV2,
model_base.HasId, model_base.HasProject):
__tablename__ = 'wan_tc_class'
device_id = sa.Column(sa.String(36),
sa.ForeignKey('wan_tc_device.id',
ondelete='CASCADE'),
nullable=False)
class_ext_id = sa.Column(sa.Integer)
parent_class = sa.Column(sa.String(36),
sa.ForeignKey('wan_tc_class.id',

View File

@ -14,12 +14,39 @@
# under the License.
from oslo_utils import uuidutils
from oslo_utils import timeutils
from oslo_log import log as logging
from wan_qos.db.models import wan_tc as models
from wan_qos.common import constants
LOG = logging.getLogger(__name__)
class WanTcDb(object):
def agent_up_notification(self, context, host_info):
device = context.session.query(models.WanTcDevice).filter_by(
host=host_info['host']
).first()
with context.session.begin(subtransactions=True):
if not device:
LOG.debug('New device connected: %s' % host_info)
wan_tc_device = models.WanTcDevice(
id = uuidutils.generate_uuid(),
host = host_info['host'],
lan_port = host_info['lan_port'],
wan_port = host_info['wan_port'],
uptime = timeutils.utcnow()
)
context.session.add(wan_tc_device)
else:
LOG.debug('updating uptime for device: %s' % host_info['host'])
device.uptime = timeutils.utcnow()
def device_heartbeat(self, context, device_info):
pass
def create_wan_tc_class(self, context, wan_qos_class):
pass

View File

@ -40,9 +40,9 @@ class PluginRpcCallback(object):
self.plugin = plugin
LOG.debug('rpc callback started.')
def agent_up_notification(self, context, host):
LOG.debug('got up notification from %s' % host)
self.plugin.agent_up_notification(host)
def agent_up_notification(self, context, host_info):
LOG.debug('got up notification from %s' % host_info['host'])
self.plugin.agent_up_notification(context, host_info)
class WanQosPlugin(wanqos.WanQosPluginBase):
@ -103,7 +103,6 @@ class WanQosPlugin(wanqos.WanQosPluginBase):
tenant_id = context.tenant_id
return tenant_id
def agent_up_notification(self, host):
LOG.debug('agent %s is up' % host)
return 'OK'
def agent_up_notification(self, context, host_info):
LOG.debug('agent %s is up' % host_info['host'])
self.db.agent_up_notification(context, host_info)