Add agent heartbeat

This commit is contained in:
Ofer Ben-Yacov 2017-01-10 15:12:51 +02:00
parent dbb8769b7f
commit 8cca409ce0
4 changed files with 28 additions and 11 deletions

View File

@ -37,6 +37,8 @@ class TcAgentManager:
self.conf = conf
if not host:
self.host = self.conf.host
else:
self.host = host
lan_port = self.conf.WANTC.lan_port_name
wan_port = self.conf.WANTC.wan_port_name
self.agent.set_ports(lan_port, wan_port)
@ -62,3 +64,4 @@ class TcAgentManager:
def periodic_tasks(self, context, raise_on_error=False):
LOG.info("periodic task")
self.plugin_rpc.device_heartbeat(context, self.host)

View File

@ -33,8 +33,13 @@ class TcPluginApi(object):
'lan_port': ports['lan_port'],
'wan_port': ports['wan_port']
}
return cctxt.cast(context, 'agent_up_notification',
host_info=host_info)
cctxt.cast(context, 'agent_up_notification',
host_info=host_info)
def device_heartbeat(self, context, host):
cctxt = self.client.prepare()
cctxt.cast(context, 'device_heartbeat',
host=host)
def get_configuration_from_db(self, context):
cctxt = self.client.prepare()

View File

@ -33,19 +33,26 @@ class WanTcDb(object):
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()
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 device_heartbeat(self, context, host):
device = context.session.query(models.WanTcDevice).filter_by(
host=host
).first()
if device:
with context.session.begin(subtransactions=True):
device.heartbeat_timestamp = timeutils.utcnow()
else:
LOG.error('Got heartbeat for non-existing device: %s' % host)
def create_wan_tc_class(self, context, wan_qos_class):
pass

View File

@ -44,11 +44,15 @@ class PluginRpcCallback(object):
LOG.debug('got up notification from %s' % host_info['host'])
self.plugin.agent_up_notification(context, host_info)
def device_heartbeat(self, context, host):
self.plugin.db.device_heartbeat(context, host)
class WanQosPlugin(wanqos.WanQosPluginBase):
supported_extension_aliases = ["wan-tc"]
def __init__(self):
self.db = wan_qos_db.WanTcDb()
rpc_callback = importutils.import_object(
'wan_qos.services.plugin.PluginRpcCallback', self)
endpoints = (
@ -60,8 +64,6 @@ class WanQosPlugin(wanqos.WanQosPluginBase):
fanout=False)
self.conn.consume_in_threads()
self.db = wan_qos_db.WanTcDb()
def get_plugin_type(self):
"""Get type of the plugin."""
return constants.WANTC