seibert-media/automatix

Misleading naming

Closed this issue · 2 comments

Example:

name: foobar
systems:
  darling: some-bundlewrap-node-name

pipeline:
  - python: |
      print(darling_node)

Issues with this syntax:

  • darling_node creates the impression that we’re talking about a normal variable name here. We do not. It is a “composed” name, referring to the “system” darling.
  • Users might (accidentally) clobber this name.
  • If, for some reason, you don’t have bundlewrap: true in your .automatix.cfg.yaml, you just get a name is not defined error by Python. Yes, this is a user error, but it illustrates that it might not be the best idea to use “magic” variable names.

Ideas:

  • Use a function, e.g. get_node(darling) or even get_bw_node(darling).
  • Introduce new objects like NODES, so you can write NODES.darling. @fkusei might want to elaborate on this.
  • Both approaches can be implemented in a backwards-compatible way, so we don’t require rewriting all existing YAML files.

I'm thinking of creating 'wrapper classes' for VARS, SYSTEMS and NODE, so one could use NODE.darling to access the bundlewrap node, SYSTEMS.darling to access the system name (as string, like there's currently system_darling - same for VARS.

Basically, something like this:

diff --git a/automatix/bundlewrap.py b/automatix/bundlewrap.py
index 44952a7..01c7548 100644
--- a/automatix/bundlewrap.py
+++ b/automatix/bundlewrap.py
@@ -27,3 +27,13 @@ class BWCommand(Command):
             return system.replace('hostname!', '')
         node = self.env.config['bw_repo'].get_node(system)
         return node.hostname
+
+class BWNodeWrapper:
+    def __getattr__(self, node_name):
+        try:
+            return BW_REPO.get_node(SYSTEMS_DICT[node_name])
+        except KeyError:
+            LOG.error(f'system {node_name} not defined')
+            # maybe exit here?
+        except NoSuchNode:
+            LOG.warning(f'bw node {node_name} does not exist in repo')

But I don't have any clue how to add this to automatix.

Fixed in 1.8.0