Skip to content

Instantly share code, notes, and snippets.

@sorenisanerd
Created July 29, 2015 14:26
Show Gist options
  • Save sorenisanerd/d1a38362d7181ae5a706 to your computer and use it in GitHub Desktop.
Save sorenisanerd/d1a38362d7181ae5a706 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import re
import yaml
nodes = ['ct1', 'stmonleader1', 'stmon1', 'stmon2', 'st1', 'ocdb1', 'oc1', 'gcp1', 'haproxy1', 'bootstrap1'] + ['cp%d' % x for x in range(1,100)]
with open('upgrade.yaml', 'r') as fp:
data = yaml.load(fp)
groups = {}
for group_name in data.get('groups', {}):
groups[group_name] = list()
for regex in data['groups'][group_name]:
regex_c = re.compile(regex)
for node in nodes:
matches = regex_c.match(node)
if matches:
groups[group_name].append(node)
for node in groups[group_name]:
nodes.remove(node)
print 'Detected groups:'
print
for group in groups:
print '%s:' % (group,)
if not groups[group]:
print ' Empty'
else:
for node in groups[group]:
print ' %s' % (node,)
print
if nodes:
print 'Nodes not included in any groups:'
for node in nodes:
print ' %s' % (node,)
print
completed_groups = set()
print 'Upgrade order:'
multiplier = 3
clusters = []
for group in data.get('sequence', []):
group_members = groups[group]
clustersize = 1
while group_members:
cluster, group_members = group_members[:clustersize], group_members[clustersize:]
clusters.append(cluster)
clustersize *= multiplier
completed_groups.add(group)
for cluster in clusters:
print ' %s' % (cluster,)
missing_groups = set(groups.keys()) - completed_groups
if missing_groups:
print 'Groups not in plan:'
for group in missing_groups:
print ' %s' % (group,)
groups:
ceph:
- st.*
ocdb:
- ocdb.*
oc:
- oc\d+
cp:
- g?cp.*
ct:
- ct.*
bootstrap:
- bootstrap.*
haproxy:
- haproxy.*
sequence:
- bootstrap
- haproxy
- ceph
- ocdb
- oc
- ct
- cp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment