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

Harmonization of docstring style

parent 32b162ee
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
'''
CloudControl server libraries.
'''
""" CloudControl server libraries.
"""

__version__ = '24~dev'
+16 −21
Original line number Diff line number Diff line
'''
Main class of cc-server.
'''
""" Main class of cc-server.
"""

from fnmatch import fnmatch as glob

@@ -37,15 +36,14 @@ class WelcomeHandler(RpcHandler):


class CCServer(object):
    '''
    CloudControl server main class.
    """ CloudControl server main class.

    :param conf_dir: the directory that store the client configuration
    :param certfile: the path to the ssl certificate
    :param keyfile: the path to the ssl key
    :param address: the interface to bind
    :param port: the port to bind
    '''
    """

    # These tags are reserved and cannot be setted by an user:
    RESERVED_TAGS = ('id', 'a', 'r', 'close', 'con', 'ip', 'p')
@@ -82,9 +80,8 @@ class CCServer(object):
        self.logger.info('Server started to running')

    def _update_accounts(self):
        '''
        Update the database with accounts.
        '''
        """ Update the database with accounts.
        """

        db_accounts = set((obj['a'].value for obj in self.db.objects if 'a' in obj))
        accounts = set(self.conf.list_accounts())
@@ -146,13 +143,12 @@ class CCServer(object):
            return client.role

    def register(self, login, role, connection):
        '''
        Register a new connected account on the server.
        """ Register a new connected account on the server.

        :param login: login of the account
        :param connection: connection to register
        :param tags: tags to add for the client
        '''
        """
        client = Client.from_role(role, None, login, self, connection)
        client.logger = self.logger.getChild('clients.%s' % client.login)
        if client.login in self._clients:
@@ -170,9 +166,8 @@ class CCServer(object):
        del self._clients[client.login]

    def run(self):
        '''
        Run the server mainloop.
        '''
        """ Run the server mainloop.
        """

        # Register accounts on the database:
        self._update_accounts()
@@ -193,13 +188,12 @@ class CCServer(object):
        return self._clients[login]

    def kill(self, login):
        '''
        Disconnect from the server the client identified by provided login.
        """ Disconnect from the server the client identified by provided login.

        :param login: the login of the user to disconnect
        :throws NotConnectedAccount: when provided account is not connected (or
            if account doesn't exists).
        '''
        """

        client = self._clients.get(login)
        if client is None:
@@ -208,14 +202,13 @@ class CCServer(object):
        client.shutdown()

    def check(self, login, method, tql=None):
        '''
        Check if the user can call the specified method with specified TQL.
        """ Check if the user can call the specified method with specified TQL.

        :param login: the login of the user
        :param method: the method to call
        :param tql: the tql passed in argument of the method
        :return: True if user have rights, else False
        '''
        """

        rights = self.conf.show(login)['rights']
        if tql is not None:
@@ -232,5 +225,7 @@ class CCServer(object):
        return False

    def list(self, query, show=None):
        """ List objects from database.
        """
        self._update_accounts()
        return self.db.query(query, show)
+6 −10
Original line number Diff line number Diff line
@@ -17,8 +17,7 @@ class HypervisorHandler(RegisteredCCHandler):

    @listed
    def register(self, obj_id, role):
        '''
        Register an object managed by the calling node.
        """ Register an object managed by the calling node.

        .. note:
           the obj_id argument passed to this handler is the object id of the
@@ -27,13 +26,12 @@ class HypervisorHandler(RegisteredCCHandler):

        :param obj_id: the id of the object to register
        :param role: the role of the object to register
        '''
        """
        self.client.register(obj_id, role)

    @listed
    def unregister(self, obj_id):
        '''
        Unregister an object managed by the calling node.
        """ Unregister an object managed by the calling node.

        .. note:
           the obj_id argument passed to this handler is the object id of the
@@ -41,7 +39,7 @@ class HypervisorHandler(RegisteredCCHandler):
           preprend the id by "node_id." itself).

        :param obj_id: the id of the object to unregister
        '''
        """
        self.client.unregister(obj_id)

    @listed
@@ -58,8 +56,7 @@ class HypervisorHandler(RegisteredCCHandler):

    @listed
    def sub_tags_unregister(self, obj_id, name):
        """
        Unregister a remote tag for a child of the client.
        """ Unregister a remote tag for a child of the client.

        :param obj_id: child name
        :param name: name of the tag to unregister
@@ -160,8 +157,7 @@ class HvClient(HostClient):
        self._children[obj_id].register(tag)

    def sub_tags_unregister(self, obj_id, name):
        """
        Unregister a remote tag for a child of the client.
        """ Unregister a remote tag for a child of the client.

        :param obj_id: child name
        :param name: name of the tag to unregister
+41 −59
Original line number Diff line number Diff line
'''
This module provide an abstraction to the clients configuration directory.
""" This module provide an abstraction to the clients configuration directory.

The client configuration directory contains a list of ``.json`` files, each
file contains the configuration for one client. The username of the client is
@@ -31,7 +30,7 @@ u'node'
 'perms': None}
>>> conf.remove_account('rms')
>>>
'''
"""

import hashlib
import base64
@@ -43,10 +42,9 @@ import re
from functools import wraps

def writer(func):
    '''
    Decorator used to threadsafize methods that made write operations on
    """ Decorator used to threadsafize methods that made write operations on
        client configuration tree.
    '''
    """

    @wraps(func)
    def f(self, *args, **kwargs):
@@ -56,11 +54,10 @@ def writer(func):
    return f

class CCConf(object):
    '''
    Create a new configuration interface.
    """ Create a new configuration interface.

    :param path_directory: the directory to store the configuration files
    '''
    """

    CONF_TEMPLATE = {'password': None,
                     'role': None,
@@ -81,13 +78,13 @@ class CCConf(object):
        return self._lock.__exit__(*args, **kwargs)

    def _get_conf(self, login):
        '''
        """
        Return the configuration of a client by its login.

        :param login: login of the client
        :return: the configuration of the client
        :raise CCConf.UnknownAccount: if user login is unknown
        '''
        """

        filename = os.path.join(self._path, '%s.json' % login)
        if os.path.isfile(filename):
@@ -98,13 +95,12 @@ class CCConf(object):
            raise CCConf.UnknownAccount('%s is not a file' % filename)

    def _set_conf(self, login, conf, create=False):
        '''
        Update the configuration of a client by its login.
        """ Update the configuration of a client by its login.

        :param login: login of the client
        :param conf: configuration to set for the client
        :raise CCConf.UnknownAccount: if user login is unknown
        '''
        """

        filename = os.path.join(self._path, '%s.json' % login)
        self.logger.debug('Writing configuration %s: %s', filename, conf)
@@ -114,29 +110,26 @@ class CCConf(object):
            raise CCConf.UnknownAccount('%s is not a file' % filename)

    def acquire(self):
        '''
        Acquire the configuration writing lock for non-atomic configuration
        """ Acquire the configuration writing lock for non-atomic configuration
            changes.

        .. warning::
           Don't forget to call the :meth:`release` method after your changes
           for each :meth:`acquire` you made.
        '''
        """
        self._lock.acquire()

    def release(self):
        '''
        Release the configuration writing lock.
        '''
        """ Release the configuration writing lock.
        """
        self._lock.release()

    def show(self, login):
        '''
        Show the configuration for specified account.
        """ Show the configuration for specified account.

        :param login: the login of the client
        :return: configuration of user
        '''
        """

        return self._get_conf(login)

@@ -180,13 +173,12 @@ class CCConf(object):
        return provided_passwd

    def _hash_password(self, password, method='ssha'):
        '''
        Hash a password using given method and return it.
        """ Hash a password using given method and return it.

        :param password: the password to hash
        :param method: the hashing method
        :return: hashed password
        '''
        """

        meth = '_auth_%s' % method.lower()
        if hasattr(self, meth):
@@ -196,15 +188,14 @@ class CCConf(object):
            raise CCConf.BadMethodError('Bad hashing method: %s' % repr(method))

    def authentify(self, login, password):
        '''
        Authentify the client providing its login and password. The function
        """ Authentify the client providing its login and password. The function
            return the role of the client on success, or ``None``.

        :param login: the login of the client
        :param password: the password of the client
        :return: the client's role or None on failed authentication
        :raise CCConf.UnknownAccount: if user login is unknown
        '''
        """

        conf = self._get_conf(login)
        passwd_conf = conf['password']
@@ -236,14 +227,13 @@ class CCConf(object):

    @writer
    def set_password(self, login, password, method='ssha'):
        '''
        Update the client's password in the configuration.
        """ Update the client's password in the configuration.

        :param login: login of the user
        :param password: new password
        :param method: the hashing method to use
        :raise CCConf.UnknownAccount: if user login is unknown
        '''
        """

        conf = self._get_conf(login)
        password = self._hash_password(password, method)
@@ -252,14 +242,13 @@ class CCConf(object):

    @writer
    def add_tag(self, login, tag_name, tag_value):
        '''
        Add the tag to the user.
        """ Add the tag to the user.

        :param login: login of the user
        :param tag_name: tag name to add to the user
        :param tag_value: the tag value
        :raise CCConf.UnknownAccount: if user login is unknown
        '''
        """

        self.logger.debug('Added tag %s:%s for %s account',
                          tag_name, tag_value, login)
@@ -269,13 +258,12 @@ class CCConf(object):

    @writer
    def remove_tag(self, login, tag):
        '''
        Remove the tag to the user.
        """ Remove the tag to the user.

        :param login: login of the user
        :param tag: tag to remove to the user
        :raise CCConf.UnknownAccount: if user login is unknown
        '''
        """

        self.logger.debug('Removed tag %s for %s account', login, tag)
        conf = self._get_conf(login)
@@ -285,12 +273,11 @@ class CCConf(object):

    @writer
    def remove_account(self, login):
        '''
        Remove the configuration of the account.
        """ Remove the configuration of the account.

        :param login: login of the account to remove
        :raise CCConf.UnknownAccount: if user login is unknown
        '''
        """

        self.logger.debug('Removed %s account', login)
        filename = os.path.join(self._path, '%s.json' % login)
@@ -301,14 +288,13 @@ class CCConf(object):

    @writer
    def create_account(self, login, role, password):
        '''
        Create a new account.
        """ Create a new account.

        :param login: login of the new user
        :param password: password of the new user
        :param role: the role of the new user
        :raise CCConf.AlreadyExistingAccount: if the login is already
        '''
        """

        self.logger.debug('Creating %s account with role %s', login, role)
        filename = os.path.join(self._path, '%s.json' % login)
@@ -324,15 +310,14 @@ class CCConf(object):

    @writer
    def copy_account(self, copy_login, login, password):
        '''
        Create a new account based on another.
        """ Create a new account based on another.

        :param copy_login: the login of the account to copy.
        :param password: password of the new user
        :param role: the role of the new user
        :raise CCConf.AlreadyExistingAccount: if the login is already
        :raise CCConf.UnknownAccount: if the copy login doesn't exist
        '''
        """

        conf_copy = self._get_conf(copy_login)
        self.create_account(login, conf_copy['role'], password)
@@ -342,8 +327,7 @@ class CCConf(object):

    @writer
    def add_right(self, login, tql, method=None, target='allow', index=None):
        '''
        Add a right rule to the provided account.
        """ Add a right rule to the provided account.

        :param login: the login of the account
        :param tql: the TQL request to allow
@@ -355,7 +339,7 @@ class CCConf(object):
        .. note::
           If the index is out of range, the rule will be added to the end of
           the ruleset.
        '''
        """

        conf = self._get_conf(login)
        rights = conf['rights']
@@ -367,12 +351,11 @@ class CCConf(object):

    @writer
    def remove_right(self, login, index):
        '''
        Remove a right rule from the provided account.
        """ Remove a right rule from the provided account.

        :param login: the login of the account
        :param index: the index of the rule to delete or None for all rules
        '''
        """

        conf = self._get_conf(login)
        if index is None:
@@ -386,12 +369,11 @@ class CCConf(object):
        self._set_conf(login, conf)

    def list_accounts(self):
        '''
        List all registered accounts.
        """ List all registered accounts.

        :return: :class:`tuple` of :class:`str`, each item being an
            account login
        '''
        """

        logins = []
        for filename in os.listdir(self._path):
+7 −10
Original line number Diff line number Diff line
'''
This module contains the hypervisor destination election stuff.
'''
""" This module contains the hypervisor destination election stuff.
"""

from copy import copy

@@ -8,9 +7,8 @@ from cloudcontrol.server.exceptions import (UnknownElectionAlgo, UnknownElection
                                 ElectionError)

def tags(*args):
    '''
    Decorator used to declare tags used by a filter.
    '''
    """ Decorator used to declare tags used by a filter.
    """

    def decorator(func):
        func.__tags__ = set(args)
@@ -59,13 +57,12 @@ class Elector(object):
        self._login = login

    def election(self, mtype, algo):
        '''
        Generate a new migration plan for this election. You must specify the
        migration type and the distribution algoritm.
        """ Generate a new migration plan for this election. You must specify
            the migration type and the distribution algoritm.

        :param mtype: the migration type
        :param algo: the distribution algoritm
        '''
        """

        # Check the choosen election method:
        if mtype not in self.ALGO_BY_TYPES:
Loading