示例#1
0
def _assignRolesByMaxs(role_bundles, lower_roles, unassigned_hosts,
                       bundled_maxs):
    '''Assign roles to host by max restriction.'''
    available_lists = []
    default_roles = []
    for bundled_role in role_bundles.keys():
        if bundled_maxs[bundled_role] > 0:
            available_lists.append([bundled_role] * bundled_maxs[bundled_role])
        else:
            default_roles.append(bundled_role)
    available_list = util.getListWithPossibility(available_lists)

    for bundled_role in available_list:
        if not unassigned_hosts:
            break
        host = unassigned_hosts.pop(0)
        lower_roles[host] = list(role_bundles[bundled_role])

    logging.debug('assigned roles after assigning max: %s', lower_roles)
    logging.debug('unassigned_hosts after assigning maxs: %s',
                  unassigned_hosts)

    if default_roles:
        default_iter = itertools.cycle(default_roles)
        while unassigned_hosts:
            host = unassigned_hosts.pop(0)
            bundled_role = default_iter.next()
            lower_roles[host] = list(role_bundles[bundled_role])

    logging.debug('assigned roles are %s', lower_roles)
    logging.debug('unassigned hosts: %s', unassigned_hosts)
def _assignRolesByMaxs(role_bundles, lower_roles, unassigned_hosts,
                       bundled_maxs):
    '''Assign roles to host by max restriction.'''
    available_lists = []
    default_roles = []
    for bundled_role in role_bundles.keys():
        if bundled_maxs[bundled_role] > 0:
            available_lists.append(
                [bundled_role]*bundled_maxs[bundled_role])
        else:
            default_roles.append(bundled_role)
    available_list = util.getListWithPossibility(available_lists)

    for bundled_role in available_list:
        if not unassigned_hosts:
            break
        host = unassigned_hosts.pop(0)
        lower_roles[host] = list(role_bundles[bundled_role])

    logging.debug('assigned roles after assigning max: %s', lower_roles)
    logging.debug('unassigned_hosts after assigning maxs: %s',
                  unassigned_hosts)

    if default_roles:
        default_iter = itertools.cycle(default_roles)
        while unassigned_hosts:
            host = unassigned_hosts.pop(0)
            bundled_role = default_iter.next()
            lower_roles[host] = list(role_bundles[bundled_role])

    logging.debug('assigned roles are %s', lower_roles)
    logging.debug('unassigned hosts: %s', unassigned_hosts)
示例#3
0
 def test_simple_case(self):
     lists = [['role1'], ['role2'], ['role3']]
     self.assertEqual(util.getListWithPossibility(lists),
                      ['role1', 'role2', 'role3'])
     lists = [['role1', 'role1'], ['role2'], ['role3']]
     self.assertEqual(util.getListWithPossibility(lists),
                      ['role1', 'role2', 'role3', 'role1'])
     lists = [['role1', 'role1', 'role1'], ['role2', 'role2'], ['role3']]
     self.assertEqual(
         util.getListWithPossibility(lists),
         ['role1', 'role2', 'role3', 'role1', 'role2', 'role1'])
     lists = [['role1', 'role1', 'role1', 'role1'], ['role2', 'role2'],
              ['role3']]
     self.assertEqual(
         util.getListWithPossibility(lists),
         ['role1', 'role2', 'role3', 'role1', 'role1', 'role2', 'role1'])
     lists = [['role3'], ['role2', 'role2'],
              ['role1', 'role1', 'role1', 'role1']]
     self.assertEqual(
         util.getListWithPossibility(lists),
         ['role1', 'role2', 'role3', 'role1', 'role1', 'role2', 'role1'])
示例#4
0
 def test_simple_case(self):
     lists = [['role1'], ['role2'], ['role3']]
     self.assertEqual(util.getListWithPossibility(lists),
                      ['role1', 'role2', 'role3'])
     lists = [['role1', 'role1'], ['role2'], ['role3']]
     self.assertEqual(util.getListWithPossibility(lists),
                      ['role1', 'role2', 'role3', 'role1'])
     lists = [['role1', 'role1', 'role1'], ['role2', 'role2'], ['role3']]
     self.assertEqual(util.getListWithPossibility(lists),
                      ['role1', 'role2', 'role3',
                       'role1', 'role2', 'role1'])
     lists = [['role1', 'role1', 'role1', 'role1'],
              ['role2', 'role2'], ['role3']]
     self.assertEqual(util.getListWithPossibility(lists),
                      ['role1', 'role2', 'role3', 'role1',
                       'role1', 'role2', 'role1'])
     lists = [['role3'],
              ['role2', 'role2'],
              ['role1', 'role1', 'role1', 'role1']]
     self.assertEqual(util.getListWithPossibility(lists),
                      ['role1', 'role2', 'role3', 'role1',
                       'role1', 'role2', 'role1'])