def get_blueprint_resource(blueprint_id, resource_path):
    """
    Get resource from the manager file server with patch relative to
    the blueprint denoted by ``blueprint_id``.

    :param blueprint_id: the blueprint id of the blueprint to download
                         the resource from
    :param resource_path: path to resource relative to blueprint folder
    :returns: resource content
    """
    base_url = "{0}/{1}".format(utils.get_manager_file_server_blueprints_root_url(), blueprint_id)
    return get_resource(resource_path, base_url=base_url)
def get_blueprint_resource(blueprint_id, resource_path):
    """
    Get resource from the manager file server with patch relative to
    the blueprint denoted by ``blueprint_id``.

    :param blueprint_id: the blueprint id of the blueprint to download
                         the resource from
    :param resource_path: path to resource relative to blueprint folder
    :returns: resource content
    """
    base_url = "{0}/{1}".format(
        utils.get_manager_file_server_blueprints_root_url(), blueprint_id)
    return get_resource(resource_path, base_url=base_url)
def get_resource(blueprint_id, deployment_id, resource_path):
    """
    Get resource from the manager file server with path relative to
    the deployment or blueprint denoted by ``deployment_id`` or
    ``blueprint_id``.

    An attempt will first be made for getting the resource from the deployment
    folder. If not found, an attempt will be made for getting the resource
    from the blueprint folder.

    :param blueprint_id: the blueprint id of the blueprint to download
                         the resource from
    :param deployment_id: the deployment id of the deployment to download the
                          resource from
    :param resource_path: path to resource relative to blueprint folder
    :returns: resource content
    """

    def _get_resource(base_url):
        try:
            return get_resource_from_manager(resource_path, base_url=base_url)
        except HttpException as e:
            if e.code != 404:
                raise
            return None

    resource = None
    if deployment_id is not None:
        deployment_base_url = '{0}/{1}'.format(
            utils.get_manager_file_server_deployments_root_url(),
            deployment_id)
        resource = _get_resource(deployment_base_url)

    if resource is None:
        blueprint_base_url = '{0}/{1}'.format(
                utils.get_manager_file_server_blueprints_root_url(),
                blueprint_id)
        resource = _get_resource(blueprint_base_url)
        if resource is None:
            if deployment_id is None:
                url = blueprint_base_url
            else:
                url = ','.join([deployment_base_url, blueprint_base_url])
            raise HttpException(url, 404, 'Resource not found: {0}'
                                .format(resource_path))
    return resource