'Create volume from snapshot.'

@utils.trace_method
def create_volume_from_snapshot(self, volume, snapshot):

    LOG.debug('Create    volume    from    snapshot')
    model_update = {}
    try:
        LOG.debug('Clone    new    volume    %(t_id)s    from    snapshot    with    id    %(s_id)s', {'t_id': volume['id'], 's_id': volume['snapshot_id']})
        rt_key = None
        snap_vol = snapshot['volume']
        metadata = snap_vol['metadata']
        rt_key = self._get_volume_metadata_value(metadata, 'current_dn_owner')
        if (rt_key is None):
            rt_key = self.dn_routing_key
        util.message_data_plane(rt_key, 'hyperscale.storage.dm.volume.clone.create', pool_name=POOL_NAME, display_name=util.get_guid_with_curly_brackets(volume['id']), version_name=util.get_guid_with_curly_brackets(volume['snapshot_id']), volume_raw_size=volume['size'], volume_qos=1, parent_volume_guid=util.get_guid_with_curly_brackets(snapshot['volume_id']), user_id=util.get_guid_with_curly_brackets(volume['user_id']), project_id=util.get_guid_with_curly_brackets(volume['project_id']), volume_guid=util.get_guid_with_curly_brackets(volume['id']))
        LOG.debug('Volume    created    successfully    on    data    node')
        volume_metadata = self._get_volume_metadata(volume)
        parent_cur_dn = self._get_volume_metadata_value(metadata, 'current_dn_ip')
        metadata_update = {}
        metadata_update['snapshot_id'] = snapshot['id']
        metadata_update['parent_volume_guid'] = util.get_guid_with_curly_brackets(snapshot['volume_id'])
        metadata_update['Primary_datanode_ip'] = parent_cur_dn
        metadata_update['current_dn_owner'] = rt_key
        metadata_update['current_dn_ip'] = parent_cur_dn
        (rt_key, rt_dn_ip) = self._select_rt(volume, volume_metadata, only_select=True)
        if (rt_key and rt_dn_ip):
            metadata_update['Potential_secondary_key'] = rt_key
            metadata_update['Potential_secondary_ip'] = rt_dn_ip
    except (exception.UnableToExecuteHyperScaleCmd, exception.UnableToProcessHyperScaleCmdOutput):
        with excutils.save_and_reraise_exception():
            LOG.exception('Exception    in    creating    volume    from    snapshot')
    except exception.InvalidMetadataType:
        with excutils.save_and_reraise_exception():
            LOG.exception('Exception    updating    metadata    in    create    volume    from    snapshot')
    volume_metadata.update(metadata_update)
    volume['provider_location'] = PROVIDER_LOCATION
    model_update = {'provider_location': volume['provider_location'], 'metadata': volume_metadata}
    return model_update
