Commit a0c375c1 authored by Antoine Millet's avatar Antoine Millet
Browse files

Cleaned up client classes

parent e864cba5
Loading
Loading
Loading
Loading

cloudcontrol/server/client.py

deleted100644 → 0
+0 −90
Original line number Diff line number Diff line
'''
Local client representation classes.
'''

from threading import Lock
from datetime import datetime

from sjrpc.utils import ConnectionProxy

class CCClient(object):
    '''
    Represent a single client connected to the server.
    '''

    def __init__(self, login, role, server, connection):

        # The login of the client:
        self.login = login

        # The role of the client:
        self.role = role

        # The server binded to this client:
        self.server = server

        # The connection of the client (public attribute):
        self.connection = connection

        # The date of connection of the client:
        self._connection_date = datetime.now()

        # The date of the last action:
        self._last_action = datetime.now()

        # The connection proxy:
        self.proxy = ConnectionProxy(connection)

        # Jobs lock for this client:
        self.lock = Lock()

    def get_uptime(self):
        '''
        Get the uptime of the client connection in seconds.

        :return: uptime of the client
        '''

        dt = datetime.now() - self._connection_date
        return dt.seconds + dt.days * 86400

    def get_idle(self):
        '''
        Get the idle time of the client connection in seconds.

        :return: idle of the client
        '''

        dt = datetime.now() - self._last_action
        return dt.seconds + dt.days * 86400

    def top(self):
        '''
        Reset the last_action date to now.
        '''

        self._last_action = datetime.now()

    def get_ip(self):
        peer = self.connection.getpeername()
        return ':'.join(peer.split(':')[:-1])

    def shutdown(self):
        '''
        Shutdown the connection to the client.
        '''

        self.server.rpc.unregister(self.connection, shutdown=True)

    def get_tags(self):
        '''
        Get all server defined tags.
        '''

        tags = {}
        tags['con'] = self.get_uptime()
        tags['ip'] = self.get_ip()
        return tags

    def get_remote_tags(self, tag):
        return self.connection.call('get_tags', (tag,))[tag]
+0 −10
Original line number Diff line number Diff line
@@ -202,13 +202,6 @@ class Client(object):
        self._tql_object.register(CallbackTag('idle', lambda: self.idle, ttl=0))
        self._tql_object.register(CallbackTag('ip', lambda: self.ip))

    def get_tags(self, tags):                                                   # DEPRECATED
        """ Get tags on the remote node.

        :param tags: tags is the list of tags to fetch
        """
        return self._connection.call('get_tags', tags)

    def shutdown(self):
        """ Shutdown the connection to the client.
        """
@@ -229,9 +222,6 @@ class Client(object):
        """
        self._last_action = datetime.now()

    def get_remote_tags(self, tag):                                             # DEPRECATED
        return self.conn.call('get_tags', (tag,))[tag]

    def async_remote_tags(self, watcher, robj, tags):
        """ Asynchronously update tags from the remote client using
            specified watcher.