Add agent heartbeat
This commit is contained in:
parent
dbb8769b7f
commit
8cca409ce0
|
@ -37,6 +37,8 @@ class TcAgentManager:
|
||||||
self.conf = conf
|
self.conf = conf
|
||||||
if not host:
|
if not host:
|
||||||
self.host = self.conf.host
|
self.host = self.conf.host
|
||||||
|
else:
|
||||||
|
self.host = host
|
||||||
lan_port = self.conf.WANTC.lan_port_name
|
lan_port = self.conf.WANTC.lan_port_name
|
||||||
wan_port = self.conf.WANTC.wan_port_name
|
wan_port = self.conf.WANTC.wan_port_name
|
||||||
self.agent.set_ports(lan_port, wan_port)
|
self.agent.set_ports(lan_port, wan_port)
|
||||||
|
@ -62,3 +64,4 @@ class TcAgentManager:
|
||||||
|
|
||||||
def periodic_tasks(self, context, raise_on_error=False):
|
def periodic_tasks(self, context, raise_on_error=False):
|
||||||
LOG.info("periodic task")
|
LOG.info("periodic task")
|
||||||
|
self.plugin_rpc.device_heartbeat(context, self.host)
|
||||||
|
|
|
@ -33,8 +33,13 @@ class TcPluginApi(object):
|
||||||
'lan_port': ports['lan_port'],
|
'lan_port': ports['lan_port'],
|
||||||
'wan_port': ports['wan_port']
|
'wan_port': ports['wan_port']
|
||||||
}
|
}
|
||||||
return cctxt.cast(context, 'agent_up_notification',
|
cctxt.cast(context, 'agent_up_notification',
|
||||||
host_info=host_info)
|
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):
|
def get_configuration_from_db(self, context):
|
||||||
cctxt = self.client.prepare()
|
cctxt = self.client.prepare()
|
||||||
|
|
|
@ -33,19 +33,26 @@ class WanTcDb(object):
|
||||||
if not device:
|
if not device:
|
||||||
LOG.debug('New device connected: %s' % host_info)
|
LOG.debug('New device connected: %s' % host_info)
|
||||||
wan_tc_device = models.WanTcDevice(
|
wan_tc_device = models.WanTcDevice(
|
||||||
id = uuidutils.generate_uuid(),
|
id=uuidutils.generate_uuid(),
|
||||||
host = host_info['host'],
|
host=host_info['host'],
|
||||||
lan_port = host_info['lan_port'],
|
lan_port=host_info['lan_port'],
|
||||||
wan_port = host_info['wan_port'],
|
wan_port=host_info['wan_port'],
|
||||||
uptime = timeutils.utcnow()
|
uptime=timeutils.utcnow()
|
||||||
)
|
)
|
||||||
context.session.add(wan_tc_device)
|
context.session.add(wan_tc_device)
|
||||||
else:
|
else:
|
||||||
LOG.debug('updating uptime for device: %s' % host_info['host'])
|
LOG.debug('updating uptime for device: %s' % host_info['host'])
|
||||||
device.uptime = timeutils.utcnow()
|
device.uptime = timeutils.utcnow()
|
||||||
|
|
||||||
def device_heartbeat(self, context, device_info):
|
def device_heartbeat(self, context, host):
|
||||||
pass
|
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):
|
def create_wan_tc_class(self, context, wan_qos_class):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -44,11 +44,15 @@ class PluginRpcCallback(object):
|
||||||
LOG.debug('got up notification from %s' % host_info['host'])
|
LOG.debug('got up notification from %s' % host_info['host'])
|
||||||
self.plugin.agent_up_notification(context, host_info)
|
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):
|
class WanQosPlugin(wanqos.WanQosPluginBase):
|
||||||
supported_extension_aliases = ["wan-tc"]
|
supported_extension_aliases = ["wan-tc"]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.db = wan_qos_db.WanTcDb()
|
||||||
rpc_callback = importutils.import_object(
|
rpc_callback = importutils.import_object(
|
||||||
'wan_qos.services.plugin.PluginRpcCallback', self)
|
'wan_qos.services.plugin.PluginRpcCallback', self)
|
||||||
endpoints = (
|
endpoints = (
|
||||||
|
@ -60,8 +64,6 @@ class WanQosPlugin(wanqos.WanQosPluginBase):
|
||||||
fanout=False)
|
fanout=False)
|
||||||
self.conn.consume_in_threads()
|
self.conn.consume_in_threads()
|
||||||
|
|
||||||
self.db = wan_qos_db.WanTcDb()
|
|
||||||
|
|
||||||
def get_plugin_type(self):
|
def get_plugin_type(self):
|
||||||
"""Get type of the plugin."""
|
"""Get type of the plugin."""
|
||||||
return constants.WANTC
|
return constants.WANTC
|
||||||
|
|
Loading…
Reference in New Issue