Beispiel #1
0
    def get_data_paths(persistences):
        import conf
        from stores.validators import validate_persistence_data

        persistence_data = validate_persistence_data(
            persistence_data=persistences)
        persistence_paths = {}
        for persistence in persistence_data:
            if persistence not in conf.get('PERSISTENCE_DATA'):
                raise VolumeNotFoundError(
                    'Data volume with name `{}` was defined in specification, '
                    'but was not found'.format(persistence))
            persistence_type_condition = (
                'mountPath' not in conf.get('PERSISTENCE_DATA')[persistence]
                and 'bucket' not in conf.get('PERSISTENCE_DATA')[persistence])
            if persistence_type_condition:
                raise VolumeNotFoundError(
                    'Data volume with name `{}` '
                    'does not define a mountPath or bucket.'.format(
                        persistence))

            persistence_paths[persistence] = (
                conf.get('PERSISTENCE_DATA')[persistence].get('mountPath')
                or conf.get('PERSISTENCE_DATA')[persistence].get('bucket'))

        return persistence_paths
Beispiel #2
0
    def get_outputs_path(persistence):
        import conf
        from stores.validators import validate_persistence_outputs

        persistence_outputs = validate_persistence_outputs(
            persistence_outputs=persistence)
        if persistence_outputs not in conf.get('PERSISTENCE_OUTPUTS'):
            raise VolumeNotFoundError(
                'Outputs volume with name `{}` was defined in specification, '
                'but was not found'.format(persistence_outputs))
        persistence_type_condition = (
            'mountPath'
            not in conf.get('PERSISTENCE_OUTPUTS')[persistence_outputs]
            and 'bucket'
            not in conf.get('PERSISTENCE_OUTPUTS')[persistence_outputs])
        if persistence_type_condition:
            raise VolumeNotFoundError(
                'Outputs volume with name `{}` '
                'does not define a mountPath or bucket.'.format(
                    persistence_outputs))

        return (
            conf.get('PERSISTENCE_OUTPUTS')[persistence_outputs].get(
                'mountPath') or
            conf.get('PERSISTENCE_OUTPUTS')[persistence_outputs].get('bucket'))
Beispiel #3
0
def get_store_secret_for_persistence(volume_name, volume_settings):
    if volume_name not in volume_settings:
        raise VolumeNotFoundError(
            'Volume with name `{}` was defined in specification, '
            'but was not found'.format(volume_name))

    definition = volume_settings[volume_name]
    return get_store_secret_from_definition(definition)
Beispiel #4
0
def validate_persistence_outputs(persistence_outputs):
    # If no persistence is defined we mount the first one as default
    if not persistence_outputs:
        return list(conf.get(PERSISTENCE_OUTPUTS).keys())[0]
    if not isinstance(persistence_outputs, str):
        raise VolumeNotFoundError('Persistence outputs value is not valid `{}`, '
                                  'it should be a string.'.format(persistence_outputs))
    return persistence_outputs
Beispiel #5
0
    def get_logs_paths(persistence_logs='default'):
        persistence_type_condition = (
            'mountPath' not in settings.PERSISTENCE_LOGS
            and 'bucket' not in settings.PERSISTENCE_LOGS)
        if persistence_type_condition:
            raise VolumeNotFoundError(
                'Logs volume does not define a mountPath or bucket.')

        return settings.PERSISTENCE_LOGS.get(
            'mountPath') or settings.PERSISTENCE_LOGS.get('bucket')
Beispiel #6
0
    def _get_store(store, secret_key):
        if not store or not secret_key:
            return StoreManager()
        try:
            store_access = config.get_dict(secret_key)
        except RheaError:
            raise VolumeNotFoundError(
                'Could not create store for path,'
                'received a store type `{}` without valid access key.'.format(store))

        return StoreManager.get_for_type(store_type=store, store_access=store_access)
Beispiel #7
0
    def get_outputs_paths(persistence_outputs):
        persistence_outputs = validate_persistence_outputs(
            persistence_outputs=persistence_outputs)
        if persistence_outputs not in settings.PERSISTENCE_OUTPUTS:
            raise VolumeNotFoundError(
                'Outputs volume with name `{}` was defined in specification, '
                'but was not found'.format(persistence_outputs))
        persistence_type_condition = (
            'mountPath'
            not in settings.PERSISTENCE_OUTPUTS[persistence_outputs] and
            'bucket' not in settings.PERSISTENCE_OUTPUTS[persistence_outputs])
        if persistence_type_condition:
            raise VolumeNotFoundError(
                'Outputs volume with name `{}` '
                'does not define a mountPath or bucket.'.format(
                    persistence_outputs))

        return (
            settings.PERSISTENCE_OUTPUTS[persistence_outputs].get('mountPath')
            or settings.PERSISTENCE_OUTPUTS[persistence_outputs].get('bucket'))
Beispiel #8
0
def get_store_secret_from_definition(definition):
    store = definition.get('store')
    secret = definition.get('secret')
    secret_key = definition.get('secretKey')

    if store:
        if store not in StoreTypes.CLOUD_STORES:
            raise VolumeNotFoundError(
                'Volume with store class `{}` is not supported.'.format(store))

        if not secret:
            raise VolumeNotFoundError(
                'Volume with store class `{}` does not define a secret.'.
                format(store))

        if not secret_key:
            raise VolumeNotFoundError(
                'Volume with store class `{}` does not define a secretKey.'.
                format(store))

    return store, secret, secret_key
Beispiel #9
0
    def get_logs_path(persistence='default'):
        import conf

        persistence_type_condition = (
            'mountPath' not in conf.get('PERSISTENCE_LOGS')
            and 'bucket' not in conf.get('PERSISTENCE_LOGS'))
        if persistence_type_condition:
            raise VolumeNotFoundError(
                'Logs volume does not define a mountPath or bucket.')

        return (conf.get('PERSISTENCE_LOGS').get('bucket')
                or conf.get('PERSISTENCE_LOGS').get('mountPath'))
Beispiel #10
0
    def get_data_paths(persistence_data):
        persistence_data = validate_persistence_data(
            persistence_data=persistence_data)
        persistence_paths = {}
        for persistence in persistence_data:
            if persistence not in settings.PERSISTENCE_DATA:
                raise VolumeNotFoundError(
                    'Data volume with name `{}` was defined in specification, '
                    'but was not found'.format(persistence))
            persistence_type_condition = (
                'mountPath' not in settings.PERSISTENCE_DATA[persistence]
                and 'bucket' not in settings.PERSISTENCE_DATA[persistence])
            if persistence_type_condition:
                raise VolumeNotFoundError(
                    'Data volume with name `{}` '
                    'does not define a mountPath or bucket.'.format(
                        persistence))

            persistence_paths[persistence] = (
                settings.PERSISTENCE_DATA[persistence].get('mountPath')
                or settings.PERSISTENCE_DATA[persistence].get('bucket'))

        return persistence_paths
Beispiel #11
0
def get_volume_from_definition(volume_name, volume_settings):
    if volume_name not in volume_settings:
        raise VolumeNotFoundError(
            'Volume with name `{}` was defined in specification, '
            'but was not found'.format(volume_name))
    volumes = []
    volume_mounts = []
    definition = volume_settings[volume_name]
    mount_path = definition.get('mountPath')
    claim_name = definition.get('existingClaim')
    host_path = definition.get('hostPath')
    read_only = definition.get('readOnly', False)
    if mount_path:
        volumes.append(
            get_volume(volume=volume_name,
                       claim_name=claim_name,
                       host_path=host_path,
                       read_only=read_only))
        volume_mounts.append(
            get_volume_mount(volume=volume_name,
                             volume_mount=mount_path,
                             read_only=read_only))

    return volumes, volume_mounts