Loading cloudcontrol/server/clients/__init__.py +4 −0 Original line number Diff line number Diff line Loading @@ -203,6 +203,7 @@ class Client(object): self._connection_date = datetime.now() self._tql_object = None self._children = {} self._server.conf.set_last_connection(self._login) # Remote tags registered: self._remote_tags = set() Loading Loading @@ -306,6 +307,9 @@ class Client(object): def shutdown(self): """ Shutdown the connection to the client. """ self._server.conf.set_last_disconnection(self._login) # Unregister all children: for child in self._children.copy(): self.unregister(child) Loading cloudcontrol/server/conf.py +43 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ import threading import json import os import re import time from functools import wraps def writer(func): Loading Loading @@ -256,6 +257,48 @@ class CCConf(object): conf['password'] = password self._set_conf(login, conf) @writer def set_last_connection(self, login): """ Set last connection time to now on the account. :param login: login of the user :raise CCConf.UnknownAccount: if user login is unknown """ conf = self._get_conf(login) conf['last_connection'] = int(time.time()) self._set_conf(login, conf) @writer def set_last_disconnection(self, login): """ Set last disconnection time to now on the account. :param login: login of the user :raise CCConf.UnknownAccount: if user login is unknown """ conf = self._get_conf(login) conf['last_disconnection'] = int(time.time()) self._set_conf(login, conf) def get_last_connection(self, login): """ Get the last connection time. :param login: login of the user :raise CCConf.UnknownAccount: if user login is unknown """ conf = self._get_conf(login) return conf.get('last_connection') def get_last_disconnection(self, login): """ Get the last disconnection time. :param login: login of the user :raise CCConf.UnknownAccount: if user login is unknown """ conf = self._get_conf(login) return conf.get('last_disconnection') @writer def add_tag(self, login, tag_name, tag_value): """ Add the tag to the user. Loading cloudcontrol/server/server.py +5 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ from cloudcontrol.server.jobs import KillOldCliJob from cloudcontrol.server.repository import Repository from cloudcontrol.server.db import SObject, SRequestor from cloudcontrol.common.tql.db.tag import StaticTag from cloudcontrol.common.tql.db.tag import StaticTag, CallbackTag from cloudcontrol.common.tql.db.db import TqlDatabase, TqlResponse from cloudcontrol.common.jobs import JobsManager, JobsStore from cloudcontrol.server.jobsinterface import ServerJobsManagerInterface Loading Loading @@ -145,6 +145,10 @@ class CCServer(object): obj = SObject(login) obj.register(StaticTag('r', conf['role']), override=True) obj.register(StaticTag('a', login), override=True) obj.register(CallbackTag('lastcon', lambda l: self.conf.get_last_connection(l), ttl=0, extra={'l': login}), override=True) obj.register(CallbackTag('lastdcon', lambda l: self.conf.get_last_disconnection(l), ttl=0, extra={'l': login}), override=True) # Register static tags: for tag, value in self.conf.show(login)['tags'].iteritems(): obj.register(StaticTag(tag, value), override=True) Loading Loading
cloudcontrol/server/clients/__init__.py +4 −0 Original line number Diff line number Diff line Loading @@ -203,6 +203,7 @@ class Client(object): self._connection_date = datetime.now() self._tql_object = None self._children = {} self._server.conf.set_last_connection(self._login) # Remote tags registered: self._remote_tags = set() Loading Loading @@ -306,6 +307,9 @@ class Client(object): def shutdown(self): """ Shutdown the connection to the client. """ self._server.conf.set_last_disconnection(self._login) # Unregister all children: for child in self._children.copy(): self.unregister(child) Loading
cloudcontrol/server/conf.py +43 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ import threading import json import os import re import time from functools import wraps def writer(func): Loading Loading @@ -256,6 +257,48 @@ class CCConf(object): conf['password'] = password self._set_conf(login, conf) @writer def set_last_connection(self, login): """ Set last connection time to now on the account. :param login: login of the user :raise CCConf.UnknownAccount: if user login is unknown """ conf = self._get_conf(login) conf['last_connection'] = int(time.time()) self._set_conf(login, conf) @writer def set_last_disconnection(self, login): """ Set last disconnection time to now on the account. :param login: login of the user :raise CCConf.UnknownAccount: if user login is unknown """ conf = self._get_conf(login) conf['last_disconnection'] = int(time.time()) self._set_conf(login, conf) def get_last_connection(self, login): """ Get the last connection time. :param login: login of the user :raise CCConf.UnknownAccount: if user login is unknown """ conf = self._get_conf(login) return conf.get('last_connection') def get_last_disconnection(self, login): """ Get the last disconnection time. :param login: login of the user :raise CCConf.UnknownAccount: if user login is unknown """ conf = self._get_conf(login) return conf.get('last_disconnection') @writer def add_tag(self, login, tag_name, tag_value): """ Add the tag to the user. Loading
cloudcontrol/server/server.py +5 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ from cloudcontrol.server.jobs import KillOldCliJob from cloudcontrol.server.repository import Repository from cloudcontrol.server.db import SObject, SRequestor from cloudcontrol.common.tql.db.tag import StaticTag from cloudcontrol.common.tql.db.tag import StaticTag, CallbackTag from cloudcontrol.common.tql.db.db import TqlDatabase, TqlResponse from cloudcontrol.common.jobs import JobsManager, JobsStore from cloudcontrol.server.jobsinterface import ServerJobsManagerInterface Loading Loading @@ -145,6 +145,10 @@ class CCServer(object): obj = SObject(login) obj.register(StaticTag('r', conf['role']), override=True) obj.register(StaticTag('a', login), override=True) obj.register(CallbackTag('lastcon', lambda l: self.conf.get_last_connection(l), ttl=0, extra={'l': login}), override=True) obj.register(CallbackTag('lastdcon', lambda l: self.conf.get_last_disconnection(l), ttl=0, extra={'l': login}), override=True) # Register static tags: for tag, value in self.conf.show(login)['tags'].iteritems(): obj.register(StaticTag(tag, value), override=True) Loading