コード例 #1
0
ファイル: forms.py プロジェクト: rmayhue/sxshare
        def validate_access_key():
            # Obtain access key
            try:
                access_key = self.cleaned_data['access_key']
            except KeyError:
                raise forms.ValidationError("Access key is missing.")

            # Validate access key
            try:
                user_data = UserData.from_key(access_key)
            except InvalidUserKeyError:
                raise forms.ValidationError("Invalid access key.")

            # Check if this access key has access to given volume
            user_sx = SXController(cluster, user_data)
            full_path = self.cleaned_data['path']
            volume, path = core.split_path(full_path)
            with timeout(error_message=""
                         "ShareFileForm.clean.validate_access_key: "
                         "File listing timed out."):
                try:
                    user_sx.listFiles.json_call(volume, path)
                except SXClusterClientError:
                    raise forms.ValidationError("Provide a valid access key. "
                                                "Make sure you have access to "
                                                "the file you want to share.")
コード例 #2
0
ファイル: api.py プロジェクト: s3vdev/sxconsole-lite
        def __init__(self, conf):
            self._cluster = self._get_cluster(conf)
            self._user_data = self._get_user_data(conf)
            self._sx = SXController(self._cluster, self._user_data)

            for name in self._sx.available_operations:
                # Wrap api functions
                func = getattr(self._sx, name).json_call
                # Log performed actions
                func = logged_calls(func)
                setattr(self, name, func)

            self.downloader = SXFileCat(self._sx)
            self.uploader = SXFileUploader(self._sx)
コード例 #3
0
ファイル: sx_api.py プロジェクト: rmayhue/sxconsole
        def __init__(self, conf):
            self._cluster = self._get_cluster(conf)
            self._user_data = self._get_user_data(conf)
            self._sx = SXController(self._cluster,
                                    self._user_data,
                                    request_timeout=conf.get('request_timeout')
                                    or 5)

            for name in self._sx.available_operations:
                # Wrap api functions
                operation = getattr(self._sx, name)
                func = logged_calls(operation.json_call)
                func.__doc__ = operation.__doc__
                func.call_on_node = logged_calls(operation.call_on_node)
                setattr(self, name, func)

            self.downloader = SXFileCat(self._sx)
            self.uploader = SXFileUploader(self._sx)
コード例 #4
0
ファイル: api.py プロジェクト: rmayhue/sxshare
    ip_addresses = conf.get('ip_addresses')
    if isinstance(ip_addresses, basestring):
        ip_addresses = [ip_addresses]
    kwargs = {
        'name': conf.get('cluster'),
        'ip_addresses': ip_addresses,
        'is_secure': conf.get('is_secure', True),
        'port': conf.get('port'),
        'verify_ssl_cert': conf.get('certificate') or conf.get('verify_ca')
    }
    return Cluster(**kwargs)


cluster = _get_cluster()
user_data = _get_user_data()
sx = SXController(cluster, user_data)

downloader = SXFileCat(sx)
uploader = SXFileUploader(sx)


@register()
def sx_check(app_configs, **kwargs):
    """Smoketest the connection with SX cluster."""
    errors = []
    try:
        sx.listUsers.call()
    except SXClientException as e:
        logger.critical("Couldn't initialize sx console. Error message: " +
                        e.message)
        hint = "Check if your sx user has admin priveleges." \
コード例 #5
0
ファイル: core.py プロジェクト: rmayhue/sxconsole
def get_user_volumes(username):
    key = get_user_key(username)
    user_sx = SXController(sx._sx.cluster, UserData.from_key(key))
    volumes = user_sx.listVolumes.json_call(includeMeta=True,
                                            includeCustomMeta=True)
    return volumes