Commit c7b96c31 authored by Nils Goroll's avatar Nils Goroll

add directors.lookup()

parent cddc0974
......@@ -6,7 +6,12 @@ server s1 -repeat 2 -keepalive {
} -start
varnish v1 -vcl+backend {
import directors;
sub vcl_recv {
if (req.url == "/lookup") {
set req.http.foo = directors.lookup("s1");
}
return (pass);
}
......@@ -19,6 +24,10 @@ client c1 {
txreq -url "/"
rxresp
expect resp.http.X-Backend-Name == "s1"
txreq -url "/lookup"
rxresp
expect resp.status == 503
expect resp.reason == "VCL failed"
} -run
varnish v1 -vcl+backend {
......@@ -26,7 +35,7 @@ varnish v1 -vcl+backend {
sub vcl_init {
new bar = directors.random();
bar.add_backend(s1, 1);
bar.add_backend(directors.lookup("s1"), 1);
}
sub vcl_recv {
......
......@@ -104,6 +104,11 @@ VCL
* Added ``req.is_hitmiss`` and ``req.is_hitpass`` (2743_)
bundled vmods
-------------
* Added ``directors.lookup()``
bundled tools
-------------
......
......@@ -5,6 +5,7 @@ libvmod_directors_la_SOURCES = \
vdir.h \
fall_back.c \
hash.c \
misc.c \
random.c \
round_robin.c \
vmod_shard.c \
......
/*-
* Copyright 2019 UPLEX - Nils Goroll Systemoptimierung
* All rights reserved.
*
* Author: Nils Goroll <nils.goroll@uplex.de>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "config.h"
#include "vdef.h"
#include "vrt.h"
#include "vcl.h"
#include "vcc_if.h"
VCL_BACKEND
VPFX(lookup)(VRT_CTX, VCL_STRING name)
{
if ((ctx->method & VCL_MET_TASK_H) == 0) {
VRT_fail(ctx,
"lookup() may only be called from vcl_init / vcl_fini");
return (NULL);
}
return (VRT_LookupDirector(ctx, name));
}
......@@ -687,6 +687,12 @@ This method may only be used in backend context.
For use with the `param` argument of `vmod_directors.shard.backend`_ to associate
this shard parameter set with a shard director.
$Function BACKEND lookup(STRING)
Lookup a backend by its name.
This function can only be used from ``vcl_init{}`` and ``vcl_fini{}``.
ACKNOWLEDGEMENTS
================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment