Updates to scripts after refactor
- Run black to reformat all the scripts
- Update makefile test targets, pylint, and fix some of the issues found
- Update pxeconfig script for refactored nbhelper
- Add start of inventory script
Change-Id: I5f426ac2da840dc72f07f8a6844e199e47d49135
diff --git a/scripts/inventory.py b/scripts/inventory.py
new file mode 100644
index 0000000..26edcdd
--- /dev/null
+++ b/scripts/inventory.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python3
+
+# SPDX-FileCopyrightText: © 2021 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+# inventory.py
+# create an inventory file for a site, in YAML format
+# currently aether specific
+
+import nbhelper
+from ruamel import yaml
+
+if __name__ == "__main__":
+
+ extra_args = {
+ "--generic": {
+ "action": "store_true",
+ "help": "Use generic output, instead of Aether-specific",
+ },
+ }
+
+ args = nbhelper.initialize(extra_args)
+ tenant = nbhelper.Tenant()
+
+ routers = {}
+ servers = {}
+ switches = {}
+
+ for device in tenant.get_devices():
+
+ dev_name = device.data["name"]
+
+ dev_vars = {
+ "ansible_host": str(device.primary_ip),
+ }
+
+ if device.data.device_role.slug == "router":
+ routers[dev_name] = dev_vars
+
+ elif device.data.device_role.slug == "server":
+ servers[dev_name] = dev_vars
+
+ elif device.data.device_role.slug == "switch":
+ switches[dev_name] = dev_vars
+
+ if args.generic:
+ groups = {
+ "routers": {"hosts": routers},
+ "servers": {"hosts": servers},
+ "switches": {"hosts": switches},
+ }
+ else:
+ groups = {
+ "aethermgmt": {"hosts": routers},
+ "aethercompute": {"hosts": servers},
+ "aetherfabric": {"hosts": switches},
+ }
+
+ yaml_out = {"all": {"children": groups}}
+
+ print(yaml.safe_dump(yaml_out, indent=2))