summaryrefslogtreecommitdiff
path: root/tools/cloudconfig-schema
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2017-05-25 11:04:55 -0600
committerScott Moser <smoser@brickies.net>2017-05-31 16:43:12 -0400
commit0a448dd034883c07f85091dbfc9117de7227eb8d (patch)
treefe9610a93f165324fbf343d6748d2964e89f3ef6 /tools/cloudconfig-schema
parent00b678c61a54f176625d3f937971215faf6af2cd (diff)
downloadvyos-cloud-init-0a448dd034883c07f85091dbfc9117de7227eb8d.tar.gz
vyos-cloud-init-0a448dd034883c07f85091dbfc9117de7227eb8d.zip
ntp: Add schema definition and passive schema validation.
cloud-config files are very flexible and permissive. This adds a jsonsschema definition to the cc_ntp module and validation functions in cloudinit/config/schema which will log warnings about invalid configuration values in the ntp section. A cmdline tools/cloudconfig-schema is added which can be used in our dev environments to quickly attempt to exercise the ntp schema. It is also exposed as a main in cloudinit.config.schema. (python3 -m cloudinit.config.schema) LP: #1692916
Diffstat (limited to 'tools/cloudconfig-schema')
-rwxr-xr-xtools/cloudconfig-schema35
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/cloudconfig-schema b/tools/cloudconfig-schema
new file mode 100755
index 00000000..32f0d61e
--- /dev/null
+++ b/tools/cloudconfig-schema
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+# This file is part of cloud-init. See LICENSE file for license information.
+
+"""cloudconfig-schema
+
+Validate existing files against cloud-config schema or provide supported schema
+documentation.
+"""
+
+import os
+import sys
+
+
+def call_entry_point(name):
+ (istr, dot, ent) = name.rpartition('.')
+ try:
+ __import__(istr)
+ except ImportError:
+ # if that import failed, check dirname(__file__/..)
+ # to support ./bin/program with modules in .
+ _tdir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
+ sys.path.insert(0, _tdir)
+ try:
+ __import__(istr)
+ except ImportError as e:
+ sys.stderr.write("Unable to find %s: %s\n" % (name, e))
+ sys.exit(2)
+
+ sys.exit(getattr(sys.modules[istr], ent)())
+
+
+if __name__ == '__main__':
+ call_entry_point("cloudinit.config.schema.main")
+
+# vi: ts=4 expandtab syntax=python