Ejemplo n.º 1
0
        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)
Ejemplo n.º 2
0
        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.")
Ejemplo n.º 3
0
        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)
Ejemplo n.º 4
0
        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)
Ejemplo n.º 5
0
    class Api(object):
        """Provides a simplified sxclient experience."""

        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)

        def get_cluster_uuid(self):
            return self._sx.get_cluster_uuid()

        def _get_user_data(self, conf):
            if 'admin_key' in conf:
                return UserData.from_key(conf['admin_key'])
            elif 'admin_key_path' in conf:
                return UserData.from_key_path(conf['admin_key_path'])
            else:
                raise ValueError(
                    "You must provide either 'admin_key' or 'admin_key_path' "
                    "in the sx config.")

        def _get_cluster(self, conf):
            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)

        @cached_property
        def has_encryption(self):
            node = self.getNodeStatus(self.listNodes()['nodeList'][0])
            return node['libsxclientVersion'].startswith('2.0')
Ejemplo n.º 6
0
    class Api(object):
        """Provides a simplified sxclient experience."""
        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)

        def get_cluster_uuid(self):
            return self._sx.get_cluster_uuid()

        def _get_user_data(self, conf):
            if 'admin_key' in conf:
                return UserData.from_key(conf['admin_key'])
            elif 'admin_key_path' in conf:
                return UserData.from_key_path(conf['admin_key_path'])
            else:
                raise ValueError(
                    "You must provide either 'admin_key' or 'admin_key_path' "
                    "in the sx config.")

        def _get_cluster(self, conf):
            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)

        @cached_property
        def has_encryption(self):
            node = self.getNodeStatus(self.listNodes()['nodeList'][0])
            return node['libsxclientVersion'].startswith('2.0')
Ejemplo n.º 7
0
    class Api(object):
        """Provides a simplified sxclient experience."""
        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)

        def get_cluster_uuid(self):
            return self._sx.get_cluster_uuid()

        def _get_user_data(self, conf):
            if 'admin_key' in conf:
                return UserData.from_key(conf['admin_key'])
            elif 'admin_key_path' in conf:
                return UserData.from_key_path(conf['admin_key_path'])
            else:
                raise ValueError(
                    "You must provide either 'admin_key' or 'admin_key_path' "
                    "in the sx config.")

        def _get_cluster(self, conf):
            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)

        def get_sx_version(self):
            node_ip = self.listNodes()['nodeList'][0]
            version = self.getNodeStatus(node_ip)['libsxclientVersion']
            return parse_sx_version(version)

        @property
        def has_indexer(self):
            from sxconsole.core import _index_user_names
            return _index_user_names.issubset(self.listUsers())

        @property
        def has_encryption(self):
            version = self.get_sx_version()
            return version.major >= 2

        @property
        def has_volume_rename(self):
            version = self.get_sx_version()
            return version >= (2, 1, False)

        @property
        def has_volume_replica_change(self):
            version = self.get_sx_version()
            return version >= (2, 1, False)
Ejemplo n.º 8
0
    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." \
Ejemplo n.º 9
0
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