'Generate the network info and make calls to place it into the
xenstore and the xenstore param list.
vm_ref can be passed in because it will sometimes be different than
what vm_utils.lookup(session, instance[\'name\']) will find (ex: rescue)'

def inject_network_info(self, instance, network_info, vm_ref=None):

    vm_ref = (vm_ref or self._get_vm_opaque_ref(instance))
    LOG.debug('Injecting    network    info    to    xenstore', instance=instance)
    @utils.synchronized(('xenstore-' + instance['uuid']))
    def update_nwinfo():
        for vif in network_info:
            xs_data = self._vif_xenstore_data(vif)
            location = ('vm-data/networking/%s' % vif['address'].replace(':', ''))
            self._add_to_param_xenstore(vm_ref, location, jsonutils.dumps(xs_data))
            try:
                self._write_to_xenstore(instance, location, xs_data, vm_ref=vm_ref)
            except exception.InstanceNotFound:
                pass
    update_nwinfo()
