Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
bf1d9979
Commit
bf1d9979
authored
Sep 23, 2018
by
Geoff Simmons
Committed by
Dridi Boukelmoune
Oct 16, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add JSON support for the CLI "vcl.list" command.
parent
0a89d2c9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
112 additions
and
2 deletions
+112
-2
cache_vcl.c
bin/varnishd/cache/cache_vcl.c
+47
-1
mgt_vcl.c
bin/varnishd/mgt/mgt_vcl.c
+56
-1
b00032.vtc
bin/varnishtest/tests/b00032.vtc
+4
-0
s00005.vtc
bin/varnishtest/tests/s00005.vtc
+3
-0
v00045.vtc
bin/varnishtest/tests/v00045.vtc
+2
-0
No files found.
bin/varnishd/cache/cache_vcl.c
View file @
bf1d9979
...
...
@@ -664,6 +664,52 @@ vcl_cli_list(struct cli *cli, const char * const *av, void *priv)
}
}
static
void
v_matchproto_
(
cli_func_t
)
vcl_cli_list_json
(
struct
cli
*
cli
,
const
char
*
const
*
av
,
void
*
priv
)
{
struct
vcl
*
vcl
;
(
void
)
priv
;
ASSERT_CLI
();
VCLI_JSON_begin
(
cli
,
2
,
av
);
VCLI_Out
(
cli
,
",
\n
"
);
VTAILQ_FOREACH
(
vcl
,
&
vcl_head
,
list
)
{
VCLI_Out
(
cli
,
"{
\n
"
);
VSB_indent
(
cli
->
sb
,
2
);
VCLI_Out
(
cli
,
"
\"
status
\"
: "
);
if
(
vcl
==
vcl_active
)
{
VCLI_Out
(
cli
,
"
\"
active
\"
,
\n
"
);
}
else
if
(
vcl
->
discard
)
{
VCLI_Out
(
cli
,
"
\"
discarded
\"
,
\n
"
);
}
else
VCLI_Out
(
cli
,
"
\"
available
\"
,
\n
"
);
VCLI_Out
(
cli
,
"
\"
state
\"
:
\"
%s
\"
,
\n
"
,
vcl
->
state
);
VCLI_Out
(
cli
,
"
\"
temperature
\"
:
\"
%s
\"
,
\n
"
,
vcl
->
temp
);
VCLI_Out
(
cli
,
"
\"
busy
\"
: %u,
\n
"
,
vcl
->
busy
);
VCLI_Out
(
cli
,
"
\"
name
\"
:
\"
%s
\"
"
,
vcl
->
loaded_name
);
if
(
vcl
->
label
!=
NULL
)
{
VCLI_Out
(
cli
,
",
\n
"
);
VCLI_Out
(
cli
,
"
\"
label
\"
: {
\n
"
);
VSB_indent
(
cli
->
sb
,
2
);
VCLI_Out
(
cli
,
"
\"
name
\"
:
\"
%s
\"
"
,
vcl
->
label
->
loaded_name
);
if
(
vcl
->
nrefs
)
VCLI_Out
(
cli
,
",
\n\"
refs
\"
: %d"
,
vcl
->
nrefs
);
VCLI_Out
(
cli
,
"
\n
"
);
VCLI_Out
(
cli
,
"}"
);
VSB_indent
(
cli
->
sb
,
-
2
);
}
else
if
(
vcl
->
nlabels
>
0
)
{
VCLI_Out
(
cli
,
",
\n
"
);
VCLI_Out
(
cli
,
"
\"
labels
\"
: %d"
,
vcl
->
nlabels
);
}
VSB_indent
(
cli
->
sb
,
-
2
);
VCLI_Out
(
cli
,
"
\n
}"
);
if
(
VTAILQ_NEXT
(
vcl
,
list
)
!=
NULL
)
VCLI_Out
(
cli
,
",
\n
"
);
}
VCLI_JSON_end
(
cli
);
}
static
void
v_matchproto_
(
cli_func_t
)
vcl_cli_load
(
struct
cli
*
cli
,
const
char
*
const
*
av
,
void
*
priv
)
{
...
...
@@ -823,7 +869,7 @@ vcl_cli_show(struct cli *cli, const char * const *av, void *priv)
static
struct
cli_proto
vcl_cmds
[]
=
{
{
CLICMD_VCL_LOAD
,
""
,
vcl_cli_load
},
{
CLICMD_VCL_LIST
,
""
,
vcl_cli_list
},
{
CLICMD_VCL_LIST
,
""
,
vcl_cli_list
,
vcl_cli_list_json
},
{
CLICMD_VCL_STATE
,
""
,
vcl_cli_state
},
{
CLICMD_VCL_DISCARD
,
""
,
vcl_cli_discard
},
{
CLICMD_VCL_USE
,
""
,
vcl_cli_use
},
...
...
bin/varnishd/mgt/mgt_vcl.c
View file @
bf1d9979
...
...
@@ -795,6 +795,61 @@ mcf_vcl_list(struct cli *cli, const char * const *av, void *priv)
}
}
static
void
v_matchproto_
(
cli_func_t
)
mcf_vcl_list_json
(
struct
cli
*
cli
,
const
char
*
const
*
av
,
void
*
priv
)
{
unsigned
status
;
char
*
p
;
struct
vclprog
*
vp
;
struct
vcldep
*
vd
;
/* NB: Shall generate same output as vcl_cli_list() */
(
void
)
priv
;
if
(
MCH_Running
())
{
if
(
!
mgt_cli_askchild
(
&
status
,
&
p
,
"vcl.list -j
\n
"
))
{
VCLI_SetResult
(
cli
,
status
);
VCLI_Out
(
cli
,
"%s"
,
p
);
}
free
(
p
);
}
else
{
VCLI_JSON_begin
(
cli
,
2
,
av
);
VCLI_Out
(
cli
,
",
\n
"
);
VTAILQ_FOREACH
(
vp
,
&
vclhead
,
list
)
{
VCLI_Out
(
cli
,
"{
\n
"
);
VSB_indent
(
cli
->
sb
,
2
);
VCLI_Out
(
cli
,
"
\"
status
\"
:
\"
%s
\"
,
\n
"
,
vp
==
active_vcl
?
"active"
:
"available"
);
VCLI_Out
(
cli
,
"
\"
state
\"
:
\"
%s
\"
,
\n
"
,
vp
->
state
);
VCLI_Out
(
cli
,
"
\"
temperature
\"
:
\"
%s
\"
,
\n
"
,
vp
->
warm
?
VCL_STATE_WARM
:
VCL_STATE_COLD
);
VCLI_Out
(
cli
,
"
\"
name
\"
:
\"
%s
\"
"
,
vp
->
name
);
if
(
mcf_is_label
(
vp
))
{
vd
=
VTAILQ_FIRST
(
&
vp
->
dfrom
);
AN
(
vd
);
VCLI_Out
(
cli
,
",
\n
"
);
VCLI_Out
(
cli
,
"
\"
label
\"
: {
\n
"
);
VSB_indent
(
cli
->
sb
,
2
);
VCLI_Out
(
cli
,
"
\"
name
\"
:
\"
%s
\"
"
,
vd
->
to
->
name
);
if
(
vp
->
nto
>
0
)
VCLI_Out
(
cli
,
",
\n\"
refs
\"
: %d"
,
vp
->
nto
);
VSB_indent
(
cli
->
sb
,
-
2
);
VCLI_Out
(
cli
,
"
\n
"
);
VCLI_Out
(
cli
,
"}"
);
}
else
if
(
vp
->
nto
>
0
)
{
VCLI_Out
(
cli
,
",
\n
"
);
VCLI_Out
(
cli
,
"
\"
labels
\"
: %d"
,
vp
->
nto
);
}
VSB_indent
(
cli
->
sb
,
-
2
);
VCLI_Out
(
cli
,
"
\n
}"
);
if
(
VTAILQ_NEXT
(
vp
,
list
)
!=
NULL
)
VCLI_Out
(
cli
,
",
\n
"
);
}
VCLI_JSON_end
(
cli
);
}
}
static
void
v_matchproto_
(
cli_func_t
)
mcf_vcl_label
(
struct
cli
*
cli
,
const
char
*
const
*
av
,
void
*
priv
)
{
...
...
@@ -888,7 +943,7 @@ static struct cli_proto cli_vcl[] = {
{
CLICMD_VCL_USE
,
""
,
mcf_vcl_use
},
{
CLICMD_VCL_STATE
,
""
,
mcf_vcl_state
},
{
CLICMD_VCL_DISCARD
,
""
,
mcf_vcl_discard
},
{
CLICMD_VCL_LIST
,
""
,
mcf_vcl_list
},
{
CLICMD_VCL_LIST
,
""
,
mcf_vcl_list
,
mcf_vcl_list_json
},
{
CLICMD_VCL_LABEL
,
""
,
mcf_vcl_label
},
{
NULL
}
};
...
...
bin/varnishtest/tests/b00032.vtc
View file @
bf1d9979
...
...
@@ -11,9 +11,13 @@ varnish v1 -vcl+backend {}
varnish v1 -vcl+backend {}
varnish v1 -cliok vcl.list
varnish v1 -clijson "vcl.list -j"
varnish v1 -cliok start
varnish v1 -cliok vcl.list
varnish v1 -clijson "vcl.list -j"
varnish v1 -cliok "vcl.use vcl1"
varnish v1 -clierr 300 "vcl.discard vcl1"
...
...
bin/varnishtest/tests/s00005.vtc
View file @
bf1d9979
...
...
@@ -39,6 +39,7 @@ varnish v1 -clierr 106 "vcl.label foo vcl0"
varnish v1 -cliok "vcl.label foo vcl2"
varnish v1 -cliok "vcl.label bar vcl2"
varnish v1 -cliok "vcl.list"
varnish v1 -clijson "vcl.list -j"
varnish v1 -clierr 300 "vcl.discard vcl2"
varnish v1 -cliok "vcl.discard bar"
varnish v1 -cliok "vcl.label foo vcl1"
...
...
@@ -100,6 +101,7 @@ varnish v1 -cliok "vcl.label label1 vcl1"
varnish v1 -cliok "vcl.label label2 vcl1"
varnish v1 -cliok "vcl.label label3 vcl1"
varnish v1 -cliok "vcl.list"
varnish v1 -clijson "vcl.list -j"
varnish v1 -start
varnish v1 -cliok "vcl.list"
...
...
@@ -111,6 +113,7 @@ client c1 -run
#######################################################################
varnish v1 -cliok vcl.list
varnish v1 -clijson "vcl.list -j"
varnish v1 -vcl+backend { }
...
...
bin/varnishtest/tests/v00045.vtc
View file @
bf1d9979
...
...
@@ -18,6 +18,7 @@ varnish v1 -cliok "vcl.state vcl1 cold"
delay 1
varnish v1 -cliexpect "cold/cooling.*vcl1" vcl.list
varnish v1 -clijson "vcl.list -j"
# It can't be warmed up yet
delay 1
...
...
@@ -26,6 +27,7 @@ varnish v1 -cliexpect "vmod-debug ref on vcl1" "vcl.state vcl1 warm"
# It will eventually cool down
delay 2
varnish v1 -cliexpect "cold/cold.*vcl1" vcl.list
varnish v1 -clijson "vcl.list -j"
# At this point it becomes possible to warm up again
varnish v1 -cliok "vcl.state vcl1 warm"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment