def _get_cluster_master_slaves(instances: list) ->(
    'boto3.resources.factory.ec2.Instance', list):
    """
    Get the master and slave instances from a set of raw EC2 instances representing
    a Flintrock cluster.
    """
    master_instance = None
    slave_instances = []
    for instance in instances:
        if not instance.tags:
            continue
        for tag in instance.tags:
            if tag['Key'] == 'flintrock-role':
                if tag['Value'] == 'master':
                    if master_instance is not None:
                        raise Exception('More than one master found.')
                    else:
                        master_instance = instance
                        break
                elif tag['Value'] == 'slave':
                    slave_instances.append(instance)
    return master_instance, slave_instances
