diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-01-02 03:02:30 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-01-02 03:02:30 +0100 |
commit | 27ece44dbb18f521bd9a15f51c1ef14e13bd1fb9 (patch) | |
tree | 9ace50ef1b348e27e571ceaf23c0c45591eff3b0 /files/node-classifier.py | |
parent | Fix X11 config. (diff) | |
download | profiles-27ece44dbb18f521bd9a15f51c1ef14e13bd1fb9.tar.gz profiles-27ece44dbb18f521bd9a15f51c1ef14e13bd1fb9.tar.xz |
Improve node classifier.
Diffstat (limited to 'files/node-classifier.py')
-rw-r--r-- | files/node-classifier.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/files/node-classifier.py b/files/node-classifier.py index 8c28ddb..7fc096f 100644 --- a/files/node-classifier.py +++ b/files/node-classifier.py @@ -2,17 +2,38 @@ import yaml import sys +import configparser # https://puppet.com/docs/puppet/7/nodes_external.html -with open('/nodes.yaml') as f: - data = yaml.load(f) def main(args): if len(args) == 1: print('usage ./node-classifier <node-name>') return + parser = configparser.ConfigParser() + conf_file = '/etc/node-classifier.ini' + if parser.read(conf_file) != [conf_file]: + print(f'Configuration file missing, expected {conf_file}') + return 1 + + try: + fmt = parser.get('common', 'node_fmt') + if fmt != 'yaml': + print(f'Unknown format {fmt}') + return 1 + filename = parser.get('common', 'nodes') + except configparser.NoSectionError as e: + print(e) + return 1 + except NoOptionError as e: + print(e) + return 1 + + with open(filename) as f: + data = yaml.load(f) + nodename = sys.argv[1] instance = data.get(nodename) if not instance: |