bundlesmatching
Prototype: bundlesmatching(name, tag1, tag2, ...)
Return type: slist
Description: Return the list of defined bundles matching name
and any
tags given. Both bundlename and tags are regular expressions. name
is
required, tags are optional.
This function searches for the given anchored name
and tag1
,
tag2
, ... regular expression in the list of currently defined bundles.
Every bundle is prefixed with the namespace, usually default:
.
When any tags are given, only the bundles with those tags are
returned. Bundle tags are set a tags
variable within a meta
promise; see the example below.
This function, used together with the findfiles
function, allows you
to do dynamic inputs and a dynamic bundle call chain. The dynamic
chain is constrained by an explicit regular expression to avoid
accidental or intentional running of unwanted bundles.
Arguments:
name
:string
, in the range:.*
Example:
body common control
{
bundlesequence => { mefirst };
}
bundle common g
{
vars:
# Here we find all bundles in the default namespace whos name starts with
# run.
"todo" slist => bundlesmatching("default:run.*");
}
bundle agent mefirst
{
methods:
# Here, we actuate each of the bundles that were found using
# bundlesmatching in bundle common g.
"" usebundle => $(g.todo);
}
bundle agent run_deprecated
{
meta:
# This bundle is tagged with deprecated
"tags" slist => { "deprecated" };
}
bundle agent run_123_456
{
vars:
# Here we find all bundles in our policy.
"bundles" slist => bundlesmatching(".*");
# Here we find all the bundles that are tagged as deprecated.
"deprecated_bundles" slist => bundlesmatching(".*", "deprecated");
# Here we find all bundles that match 891 (none will).
"no_bundles" slist => bundlesmatching("891");
reports:
# Here we report on our findings:
"bundles = $(bundles)";
"deprecated bundles = $(deprecated_bundles)";
"no bundles = $(no_bundles)";
}
Output:
R: bundles = default:run_123_456
R: bundles = default:run_deprecated
R: bundles = default:mefirst
R: bundles = default:g
R: deprecated bundles = default:run_deprecated
See also: findfiles()
.