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 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
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))
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
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
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
""" import logging import os from time import time from django.conf import settings from django.utils.translation import ugettext_lazy as _ from common.utils import ServerProxy from wi.utils.exceptions import RestErrorException from wi.utils.messages_ajax import error, success from wi.utils.messages_codes import get_error, auth_error_text REDIRECT_FIELD_NAME = 'next' CLM = ServerProxy(settings.CLOUD_MANAGER_ADDRESS) def check_response_errors(response, session): """ Checks status of response response and throws appropriate error. """ if response['status'] != 'ok': from wi.utils.auth import logout error_code = response['status'] error_msg = get_error(error_code) raise RestErrorException(error_msg) return response