

def generate_agents(compute_nodes, accommodation, unique):
    density = (accommodation.get('density') or 1)
    zones = accommodation.get('zones')
    if zones:
        compute_nodes = [c for c in compute_nodes if (c['zone'] in zones)]
        if ('cross_az' in accommodation):
            compute_nodes = prepare_for_cross_az(compute_nodes, zones)
    if accommodation.get('compute_nodes'):
        compute_nodes = random.sample(compute_nodes, accommodation.get('compute_nodes'))
    cn_count = len(compute_nodes)
    iterations = (cn_count * density)
    if (('single_room' in accommodation) and ('pair' in accommodation)):
        iterations //= 2
    node_formula = (lambda x: compute_nodes[(x % cn_count)])
    agents = {
        
    }
    for i in range(iterations):
        if ('pair' in accommodation):
            master_id = ('%s_master_%s' % (unique, i))
            slave_id = ('%s_slave_%s' % (unique, i))
            master = dict(id=master_id, mode='master', slave_id=slave_id)
            slave = dict(id=slave_id, mode='slave', master_id=master_id)
            if ('single_room' in accommodation):
                master_formula = (lambda x: (i * 2))
                slave_formula = (lambda x: ((i * 2) + 1))
            elif ('double_room' in accommodation):
                master_formula = (lambda x: i)
                slave_formula = (lambda x: i)
            else:
                master_formula = (lambda x: i)
                slave_formula = (lambda x: (i + 1))
            m = node_formula(master_formula(i))
            (master['node'], master['zone']) = (m['host'], m['zone'])
            s = node_formula(slave_formula(i))
            (slave['node'], slave['zone']) = (s['host'], s['zone'])
            agents[master['id']] = master
            agents[slave['id']] = slave
        elif ('single_room' in accommodation):
            agent_id = ('%s_agent_%s' % (unique, i))
            agents[agent_id] = dict(id=agent_id, node=node_formula(i)['host'], zone=node_formula(i)['zone'], mode='alone')
    if (not agents):
        raise DeploymentException(('Not enough compute nodes %(cn)s for requested instance accommodation %(acc)s' % dict(cn=compute_nodes, acc=accommodation)))
    for agent in agents.values():
        az = agent['zone']
        if agent['node']:
            az += (':' + agent['node'])
        agent['availability_zone'] = az
    return agents

dataset/ETHPy150Open openstack/shaker/shaker/engine/deploy.py generate_agents/original