summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Siraut <csiraut@entrouvert.com>2020-06-12 15:03:49 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2020-12-30 11:05:52 (GMT)
commit3f2f4786318f0ed011ff2190736a0ee8ffb5161b (patch)
treedb6010c77dbac1f79ae41241cf891399b1c8e8de
parente1dda1cc35514e6a6cf5938390ddf81dbe49595a (diff)
downloadmisc-fred-3f2f4786318f0ed011ff2190736a0ee8ffb5161b.zip
misc-fred-3f2f4786318f0ed011ff2190736a0ee8ffb5161b.tar.gz
misc-fred-3f2f4786318f0ed011ff2190736a0ee8ffb5161b.tar.bz2
eoptasks: use servers.yaml instead of deprecated servergroups.yaml
-rwxr-xr-xeoptasks/eoptasks.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/eoptasks/eoptasks.py b/eoptasks/eoptasks.py
index 1daa700..f1d1927 100755
--- a/eoptasks/eoptasks.py
+++ b/eoptasks/eoptasks.py
@@ -16,7 +16,7 @@
#
# Configuration: ~/.config/eoptasks.ini
# [config]
-# servergroups = /path/to/servergroups.yaml
+# servers = /path/to/servers.yaml
# ignore = server1, server2
# stripsuffix = .entrouvert.org
#
@@ -51,12 +51,14 @@ import time
import libtmux
import yaml
+
class Server:
- def __init__(self, servername, group='', display_name=''):
+ def __init__(self, servername, tags=[], display_name=''):
self.name = servername
self.display_name = display_name or self.name
- self.keywords = set(re.split(r'[-_ \.]', servername + ' ' + group))
- self.keywords.add(group)
+ self.keywords = set(re.split(r'[-_ \.]', servername))
+ for tag in tags:
+ self.keywords.add(tag)
# add all possible hostname parts as keywords,
# ex: node1.dev.entrouvert.org will add:
@@ -76,17 +78,16 @@ def get_servers():
servers = []
config = configparser.ConfigParser()
config.read(os.path.join(os.path.expanduser('~/.config/eoptasks.ini')))
- servergroup = config.get('config', 'servergroups', fallback=None)
- if servergroup is None:
+ serversfile = config.get('config', 'servers', fallback=None)
+ if serversfile is None:
print("You need to create ~/.config/eoptasks.ini with such a content:\n"
"\n"
" [config]\n"
- " servergroups = /home/user/src/puppet/data/servergroups.yaml\n")
+ " servers = /home/user/src/puppet/data/servers.yaml\n")
sys.exit(1)
ignorelist = [x.strip() for x in config.get('config', 'ignore', fallback='').split(',')]
stripsuffixes = [x.strip() for x in config.get('config', 'stripsuffix', fallback='').split(',')]
- servergroups = yaml.safe_load(open(servergroup))['servergroups']
def get_display_name(x):
for stripsuffix in stripsuffixes:
@@ -94,13 +95,15 @@ def get_servers():
return x[:-len(stripsuffix)]
return x
- for group in servergroups:
- for servername in servergroups[group]:
- if servername in ignorelist:
- continue
- servers.append(Server(servername, group, display_name=get_display_name(servername)))
+ for s in yaml.safe_load(open(serversfile))['servers']:
+ servername, tags = s.get('name'), s.get('tags', [])
+ if servername in ignorelist:
+ continue
+ servers.append(Server(servername, tags, display_name=get_display_name(servername)))
+
return servers
+
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-l', '--list-servers', action='store_true')