Commit e531d099 authored by Antoine Millet's avatar Antoine Millet

"con" tag management.

parent 857fbf59
......@@ -130,16 +130,15 @@ class CCServer(object):
if login in self._connected:
client = self._connected[login]
tags['con'] = client.get_uptime()
try:
tags.update(client.connection.call('get_tags',
tuple(requested_tags)))
except Exception as err:
logging.error('Error while calling get_tags on '
'%s: %s' % (client.login, err))
else:
tags['status'] = 'online'
else:
tags['status'] = 'offline'
tags['con'] = 'offline'
# Apply all user specified tags:
tags.update(conf['tags'])
......
#!/usr/bin/env python
#coding=utf8
from datetime import datetime
class CCClient(object):
'''
Represent a single client connected to the server.
......@@ -20,20 +22,15 @@ class CCClient(object):
# The connection of the client (public attribute):
self.connection = connection
def get_tags(self, tags=None):
'''
Get the tags of the object.
# The date of connection of the client:
self._connection_date = datetime.now()
:param tags: the list of tags to fetch, or None for all
def get_uptime(self):
'''
Get the uptime of the client connection in seconds.
# Get the tags from the server
tags = self.connection.call('get_tags', tags)
# Add the static tags:
tags['a'] = self.login
tags['hv'] = self.login
tags['role'] = self.role
# Update it with the locally defined tags:
tags.update(self.server.conf.show(self.login)['tags'])
return tags
:return: uptime of the client
'''
dt = datetime.now() - self._connection_date
return dt.seconds + dt.days * 86400
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment