Created
August 11, 2015 19:06
-
-
Save bodepd/06a7749d00d01923ee76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def upgrade_list(self, instructions): | |
status = self.upgrade_status() | |
updates = {'roles': [], 'hosts': []} | |
# parse rolling_rules from instructions | |
if instructions.get('rolling_rules'): | |
# reformat upgrade status to be keyed off role | |
pending = self.key_host_list_off_role(status['pending']) | |
upgraded = self.key_host_list_off_role(status['upgraded']) | |
upgrading = self.key_host_list_off_role(status['upgrading']) | |
# get the upgrade instructions | |
roles = instructions['rolling_rules'].get('roles') | |
global_num = instructions['rolling_rules'].get('global') | |
# iterate through all things that are pending | |
for role, hosts in pending.iteritems(): | |
# for every role that is still pending, | |
# figure out if we need to update any hosts of that | |
# role | |
# zero means just upgrade everything | |
number = 0 | |
# figure out the rolling_upgrade number | |
num = roles.get(role) or global_num | |
if num == 0 or num => len(hosts) + len(upgrading[role]) | |
# append role as ready to be upgraded | |
updates['roles'].append(role) | |
elif len(upgrading[role]) < num | |
num_hosts = num - len(upgrading[role]) | |
# append the first N num_hosts, sort to reduce race conditions | |
updates['roles'].append(sorted(hosts)[:num_hosts]) | |
return updates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment