Skip to content
ccnode.py 1.29 KiB
Newer Older
Benziane Chakib's avatar
Benziane Chakib committed
import socket
import threading
import ssl
import logging
from sjrpc.client import SimpleRpcClient
from sjrpc.utils import ConnectionProxy
from sjrpc.core import RpcError
from ccnodehandlers import *


class CCNode(object):
    '''
    This class handles node initialization and connection and authentication
    '''
    def __init__(self, server, port, hypervisor, cert=None):
        self.manager = SimpleRpcClient.from_addr(server, port, enable_ssl=True,
                                default_handler=NodeHandler(self, hypervisor))
Benziane Chakib's avatar
Benziane Chakib committed
        self.server = ConnectionProxy(self.manager)

    def run(self):
        self.manager.run()

    def authentify(self, login, password):
        logging.debug('Authenticating user %s with password <%s>' % (login,
                      password))
        try:
            role = self.server.authentify(login, password)
        except RpcError as err:
            if err.exception == 'AuthenticationError':
                logging.warning('Authentication error')
            else:
                logging.warning('Unknown error while authenticating: %s' % err)
            return False
        else:
                logging.warning('Bad role affected by server: %s' % role)
                return False
            else:
                return True