'Add a compute host to an aggregate.'

def add_to_aggregate(self, context, aggregate, host, slave_info=None):

    if (not pool_states.is_hv_pool(aggregate.metadata)):
        return
    if CONF.xenserver.independent_compute:
        raise exception.NotSupportedWithOption(operation='adding    to    a    XenServer    pool', option='CONF.xenserver.independent_compute')
    invalid = {pool_states.CHANGING: _('setup    in    progress'), pool_states.DISMISSED: _('aggregate    deleted'), pool_states.ERROR: _('aggregate    in    error')}
    if (aggregate.metadata[pool_states.KEY] in invalid.keys()):
        raise exception.InvalidAggregateActionAdd(aggregate_id=aggregate.id, reason=invalid[aggregate.metadata[pool_states.KEY]])
    if (aggregate.metadata[pool_states.KEY] == pool_states.CREATED):
        aggregate.update_metadata({pool_states.KEY: pool_states.CHANGING})
    if (len(aggregate.hosts) == 1):
        self._init_pool(aggregate.id, aggregate.name)
        metadata = {'master_compute': host, host: self._host_uuid, pool_states.KEY: pool_states.ACTIVE}
        aggregate.update_metadata(metadata)
    else:
        master_compute = aggregate.metadata['master_compute']
        if ((master_compute == CONF.host) and (master_compute != host)):
            self._join_slave(aggregate.id, host, slave_info.get('compute_uuid'), slave_info.get('url'), slave_info.get('user'), slave_info.get('passwd'))
            metadata = {host: slave_info.get('xenhost_uuid')}
            aggregate.update_metadata(metadata)
        elif (master_compute and (master_compute != host)):
            slave_info = self._create_slave_info()
            self.compute_rpcapi.add_aggregate_host(context, host, aggregate, master_compute, slave_info)
