'Create snapshot using SnapOPC.'

@lockutils.synchronized('ETERNUS-vol', 'cinder-', True)
def create_snapshot(self, snapshot):

    LOG.debug('create_snapshot,    snapshot    id:    %(sid)s,    volume    id:    %(vid)s.', {'sid': snapshot['id'], 'vid': snapshot['volume_id']})
    self.conn = self._get_eternus_connection()
    snapshotname = snapshot['name']
    volumename = snapshot['volume_name']
    vol_id = snapshot['volume_id']
    volume = snapshot['volume']
    d_volumename = self._create_volume_name(snapshot['id'])
    s_volumename = self._create_volume_name(vol_id)
    vol_instance = self._find_lun(volume)
    repservice = self._find_eternus_service(REPL)
    if (vol_instance is None):
        msg = (_('create_snapshot,    volumename:    %(s_volumename)s,    source    volume    not    found    on    ETERNUS.') % {'s_volumename': s_volumename})
        LOG.error(msg)
        raise exception.VolumeBackendAPIException(data=msg)
    if (repservice is None):
        msg = (_('create_snapshot,    volumename:    %(volumename)s,    Replication    Service    not    found.') % {'volumename': volumename})
        LOG.error(msg)
        raise exception.VolumeBackendAPIException(data=msg)
    eternus_pool = self._get_drvcfg('EternusSnapPool')
    pool = self._find_pool(eternus_pool)
    if (pool is None):
        msg = (_('create_snapshot,    eternus_pool:    %(eternus_pool)s,    pool    not    found.') % {'eternus_pool': eternus_pool})
        LOG.error(msg)
        raise exception.VolumeBackendAPIException(data=msg)
    LOG.debug('create_snapshot,    snapshotname:    %(snapshotname)s,    source    volume    name:    %(volumename)s,    vol_instance.path:    %(vol_instance)s,    dest_volumename:    %(d_volumename)s,    pool:    %(pool)s,    Invoke    CreateElementReplica.', {'snapshotname': snapshotname, 'volumename': volumename, 'vol_instance': vol_instance.path, 'd_volumename': d_volumename, 'pool': pool})
    (rc, errordesc, job) = self._exec_eternus_service('CreateElementReplica', repservice, ElementName=d_volumename, TargetPool=pool, SyncType=self._pywbem_uint(7, '16'), SourceElement=vol_instance.path)
    if (rc != 0):
        msg = (_('create_snapshot,    snapshotname:    %(snapshotname)s,    source    volume    name:    %(volumename)s,    vol_instance.path:    %(vol_instance)s,    dest    volume    name:    %(d_volumename)s,    pool:    %(pool)s,    Return    code:    %(rc)lu,    Error:    %(errordesc)s.') % {'snapshotname': snapshotname, 'volumename': volumename, 'vol_instance': vol_instance.path, 'd_volumename': d_volumename, 'pool': pool, 'rc': rc, 'errordesc': errordesc})
        LOG.error(msg)
        raise exception.VolumeBackendAPIException(data=msg)
    else:
        element = job['TargetElement']
    LOG.debug('create_snapshot,    volumename:%(volumename)s,    Return    code:%(rc)lu,    Error:%(errordesc)s.', {'volumename': volumename, 'rc': rc, 'errordesc': errordesc})
    element_path = {'classname': element.classname, 'keybindings': {'CreationClassName': element['CreationClassName'], 'SystemName': element['SystemName'], 'DeviceID': element['DeviceID'], 'SystemCreationClassName': element['SystemCreationClassName']}}
    sdv_no = ('0x' + element['DeviceID'][24:28])
    metadata = {'FJ_SDV_Name': d_volumename, 'FJ_SDV_No': sdv_no, 'FJ_Pool_Name': eternus_pool}
    return (element_path, metadata)
