'Generates mac addresses and creates vif rows in db for them.'

def _allocate_mac_addresses(self, context, instance_uuid, networks, macs, requested_networks):

    if (macs is not None):
        available_macs = set(macs)
    if requested_networks:
        tags_by_network = {network.network_id: (network.tag if ('tag' in network) else None) for network in requested_networks}
    else:
        tags_by_network = {}
    for network in networks:
        if (macs is None):
            self._add_virtual_interface(context, instance_uuid, network['id'], tag=tags_by_network.get(network['uuid']))
        else:
            try:
                mac = available_macs.pop()
            except KeyError:
                raise exception.VirtualInterfaceCreateException()
            self._add_virtual_interface(context, instance_uuid, network['id'], mac, tag=tags_by_network.get(network['uuid']))
