Exemplo n.º 1
0
class CM:
    def __init__(self, cm_id):
        """
        Create object representing CM.

        @parameter{cm_id,int} id of the CM

        @returns{common.utils.ServerProxy} instance of CM proxy server
        """
        cluster = Cluster.get(cm_id)
        self.server = ServerProxy('http://%s:%s' %
                                  (cluster.address, cluster.port))

    def send_request(self, *args, **kw):
        """
        Make request to particular CM.
        """
        resp = self.server.send_request(*args, **kw)
        if resp['status'] != 'ok':
            raise CLMException(resp['status'])
        if 'messages' in resp:
            for user_id, msgs in resp['messages'].iteritems():
                for msg in msgs:
                    message.add(user_id, msg)
        return resp
Exemplo n.º 2
0
def authenticate(parameters):
    clm = ServerProxy(CLM_ADDRESS)

    temp_input = parameters['input']
    temp_file_wrapper = parameters['file_wrapper']

    del parameters['input']
    del parameters['file_wrapper']

    data = {'parameters': parameters}
    response = clm.send_request(CLM_AUTHENTICATE, **data)
    status = response['status']

    print response

    if status != 'ok':
        raise AuthFailure()

    parameters['input'] = temp_input
    parameters['file_wrapper'] = temp_file_wrapper

    user_name = parameters['authorization'].split(' ')[1].split(':')[0]
    print 'Username:'******'..') != -1:
        raise InvalidAccessKeyId

    bucket_path = os.path.join(BUCKETS_PATH, user_name)
    print 'Bucket path:', bucket_path

    if not os.path.exists(bucket_path): # TODO przenieść to do innych funkcji
        print 'User\'s directory does not exists, creating'
        os.mkdir(bucket_path)

    print 'Authentication process successful'
    return True
Exemplo n.º 3
0
class CloudManager(object):

    def __init__(self, uri, aws_key=None, parameters=None, signature=None):
        self.aws_key = aws_key
        self.parameters = parameters
        self.signature = signature

        self._cluster_managers_data = None
        self._proxy_server = ServerProxy(uri)

    def cluster_managers(self):
        if not self._cluster_managers_data:
            self._cluster_managers_data = \
                self._proxy_server.send_request("guest/cluster/list_names/")['data']

        print self._cluster_managers_data
        cluster_managers = []
        for cluster_manager_data in self._cluster_managers_data:
            cluster_manager = ClusterManager(
                cluster_manager_data['cluster_id'],
                cluster_manager_data['name'],
                self
            )
            cluster_managers.append(cluster_manager)
        return cluster_managers

    def get_cluster_manager(self, by_environ=None, by_id=None, by_name=None):
        cluster_manager = None
        if by_environ:
            name = by_environ['HTTP_HOST'].split('.')[0]
            cluster_manager = self.get_cluster_manager(by_name=name)
        else:
            if by_id:
                for cm in self.cluster_managers():
                    if cm.id == by_id:
                        cluster_manager = cm
                        break
            elif by_name:
                for cm in self.cluster_managers():
                    if cm.name == by_name:
                        cluster_manager = cm
                        break
        return cluster_manager
Exemplo n.º 4
0
class CloudManager(object):
    def __init__(self, uri, aws_key=None, parameters=None, signature=None):
        self.aws_key = aws_key
        self.parameters = parameters
        self.signature = signature

        self._cluster_managers_data = None
        self._proxy_server = ServerProxy(uri)

    def cluster_managers(self):
        if not self._cluster_managers_data:
            self._cluster_managers_data = \
                self._proxy_server.send_request("guest/cluster/list_names/")['data']

        print self._cluster_managers_data
        cluster_managers = []
        for cluster_manager_data in self._cluster_managers_data:
            cluster_manager = ClusterManager(
                cluster_manager_data['cluster_id'],
                cluster_manager_data['name'], self)
            cluster_managers.append(cluster_manager)
        return cluster_managers

    def get_cluster_manager(self, by_environ=None, by_id=None, by_name=None):
        cluster_manager = None
        if by_environ:
            name = by_environ['HTTP_HOST'].split('.')[0]
            cluster_manager = self.get_cluster_manager(by_name=name)
        else:
            if by_id:
                for cm in self.cluster_managers():
                    if cm.id == by_id:
                        cluster_manager = cm
                        break
            elif by_name:
                for cm in self.cluster_managers():
                    if cm.name == by_name:
                        cluster_manager = cm
                        break
        return cluster_manager
Exemplo n.º 5
0
Arquivo: cm.py Projeto: cc1-cloud/cc1
class CM:
    def __init__(self, cm_id):
        """
        Create object representing CM.

        @parameter{cm_id,int} id of the CM

        @returns{common.utils.ServerProxy} instance of CM proxy server
        """
        cluster = Cluster.get(cm_id)
        self.server = ServerProxy('http://%s:%s' % (cluster.address, cluster.port))

    def send_request(self, *args, **kw):
        """
        Make request to particular CM.
        """
        resp = self.server.send_request(*args, **kw)
        if resp['status'] != 'ok':
            raise CLMException(resp['status'])
        if 'messages' in resp:
            for user_id, msgs in resp['messages'].iteritems():
                for msg in msgs:
                    message.add(user_id, msg)
        return resp