summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Piper <andy.piper@arcticwolf.com>2021-11-22 20:13:42 -0500
committerAndy Piper <andy.piper@arcticwolf.com>2021-11-22 20:13:42 -0500
commitef8b7a4da706b41f310f732f2652428d6648fd7b (patch)
tree24b464ac444db75846ded6451fe060b458f3f60f
parentbf41d4c232f2bffb38be8a87d68208fce1416ea9 (diff)
downloadvmdb2-ef8b7a4da706b41f310f732f2652428d6648fd7b.tar.gz
app.py: Add `--variable` param for user-supplied jinja2 variables
The `--variable` command line parameter can be used to supply values for Jinja2 variables in vmdb2 build specification YAML files using the format `name=value`. This is useful for builds which need to be parameterized, e.g they use remote services in different AWS regions and/or accounts.
-rw-r--r--vmdb/app.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/vmdb/app.py b/vmdb/app.py
index 83a8810..65bc568 100644
--- a/vmdb/app.py
+++ b/vmdb/app.py
@@ -68,6 +68,14 @@ class Vmdb2:
p.add_argument("-v", "--verbose", action="store_true")
p.add_argument("--log")
p.add_argument("--version", action="store_true")
+ p.add_argument(
+ "--variable",
+ action="append",
+ default=[],
+ help="Specify the value for a Jinja2 template variable in the "
+ 'build spec file in the format "name=value". This parameter can '
+ "be specified multiple times to define multiple variables.",
+ )
p.add_argument("specfile")
return p.parse_args()
@@ -88,12 +96,27 @@ class Vmdb2:
logging.info(f"Starting vmdb2 version {self._version}")
def template_vars_from_args(self, args):
- return {
+ vars = {
"image": args.image,
"output": args.output,
"rootfs_tarball": args.rootfs_tarball,
}
+ for var_spec in args.variable:
+ name, value = var_spec.split("=")
+ if name in vars:
+ raise RuntimeError(f'Duplicate definition of variable "{name}"')
+
+ # Remove quoes from the value if required
+ if value.startswith("'"):
+ value = value.strip("'")
+ elif value.startswith('"'):
+ value = value.strip('"')
+
+ vars[name] = value
+
+ return vars
+
class Command:
def run(self):