Пример #1
0
def get_store_secret_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))

    definition = volume_settings[volume_name]
    store = definition.get('store')
    secret = definition.get('secret')
    secret_key = definition.get('secretKey')

    if store:
        if store not in stores.VALUES:
            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
Пример #2
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))
    if 'mountPath' not in settings.PERSISTENCE_OUTPUTS[persistence_outputs]:
        raise VolumeNotFoundError('Outputs volume with name `{}` '
                                  'does not define a mountPath.'.format(persistence_outputs))

    return settings.PERSISTENCE_OUTPUTS[persistence_outputs]['mountPath']
Пример #3
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))
        if 'mountPath' not in settings.PERSISTENCE_DATA[persistence]:
            raise VolumeNotFoundError('Data volume with name `{}` '
                                      'does not define a mountPath.'.format(persistence))

        persistence_paths[persistence] = settings.PERSISTENCE_DATA[persistence]['mountPath']

    return persistence_paths
Пример #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(settings.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
Пример #5
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'))
Пример #6
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
Пример #7
0
def get_outputs_store(persistence_outputs):
    store, _, secret_key = get_store_secret_from_definition(
        volume_name=persistence_outputs,
        volume_settings=settings.PERSISTENCE_OUTPUTS)
    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)
Пример #8
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