'Inject instance metadata into xenstore.'

def _inject_instance_metadata(self, instance, vm_ref):

    @utils.synchronized(('xenstore-' + instance['uuid']))
    def store_meta(topdir, data_dict):
        for (key, value) in data_dict.items():
            key = self._sanitize_xenstore_key(key)
            value = (value or '')
            self._add_to_param_xenstore(vm_ref, ('%s/%s' % (topdir, key)), jsonutils.dumps(value))
    store_meta('vm-data/user-metadata', utils.instance_meta(instance))
