'Create volume on ETERNUS.'

def create_volume(self, volume):

    LOG.debug('create_volume,    volume    id:    %(vid)s,    volume    size:    %(vsize)s.', {'vid': volume['id'], 'vsize': volume['size']})
    self.conn = self._get_eternus_connection()
    volumesize = (int(volume['size']) * units.Gi)
    volumename = self._create_volume_name(volume['id'])
    LOG.debug('create_volume,    volumename:    %(volumename)s,    volumesize:    %(volumesize)u.', {'volumename': volumename, 'volumesize': volumesize})
    eternus_pool = self._get_drvcfg('EternusPool')
    pool = self._find_pool(eternus_pool)
    if ('RSP' in pool['InstanceID']):
        pooltype = RAIDGROUP
    else:
        pooltype = TPPOOL
    configservice = self._find_eternus_service(STOR_CONF)
    if (configservice is None):
        msg = (_('create_volume,    volume:    %(volume)s,    volumename:    %(volumename)s,    eternus_pool:    %(eternus_pool)s,    Storage    Configuration    Service    not    found.') % {'volume': volume, 'volumename': volumename, 'eternus_pool': eternus_pool})
        LOG.error(msg)
        raise exception.VolumeBackendAPIException(data=msg)
    LOG.debug('create_volume,    CreateOrModifyElementFromStoragePool,    ConfigService:    %(service)s,    ElementName:    %(volumename)s,    InPool:    %(eternus_pool)s,    ElementType:    %(pooltype)u,    Size:    %(volumesize)u.', {'service': configservice, 'volumename': volumename, 'eternus_pool': eternus_pool, 'pooltype': pooltype, 'volumesize': volumesize})
    (rc, errordesc, job) = self._exec_eternus_service('CreateOrModifyElementFromStoragePool', configservice, ElementName=volumename, InPool=pool, ElementType=self._pywbem_uint(pooltype, '16'), Size=self._pywbem_uint(volumesize, '64'))
    if (rc == VOLUMENAME_IN_USE):
        LOG.warning('create_volume,    volumename:    %(volumename)s,    Element    Name    is    in    use.', {'volumename': volumename})
        vol_instance = self._find_lun(volume)
        element = vol_instance
    elif (rc != 0):
        msg = (_('create_volume,    volumename:    %(volumename)s,    poolname:    %(eternus_pool)s,    Return    code:    %(rc)lu,    Error:    %(errordesc)s.') % {'volumename': volumename, 'eternus_pool': eternus_pool, 'rc': rc, 'errordesc': errordesc})
        LOG.error(msg)
        raise exception.VolumeBackendAPIException(data=msg)
    else:
        element = job['TheElement']
    try:
        systemnamelist = self._enum_eternus_instances('FUJITSU_StorageProduct')
    except Exception:
        msg = (_('create_volume,    volume:    %(volume)s,    EnumerateInstances,    cannot    connect    to    ETERNUS.') % {'volume': volume})
        LOG.error(msg)
        raise exception.VolumeBackendAPIException(data=msg)
    LOG.debug('create_volume,    volumename:    %(volumename)s,    Return    code:    %(rc)lu,    Error:    %(errordesc)s,    Backend:    %(backend)s,    Pool    Name:    %(eternus_pool)s,    Pool    Type:    %(pooltype)s.', {'volumename': volumename, 'rc': rc, 'errordesc': errordesc, 'backend': systemnamelist[0]['IdentifyingNumber'], 'eternus_pool': eternus_pool, 'pooltype': POOL_TYPE_dic[pooltype]})
    element_path = {'classname': element.classname, 'keybindings': {'CreationClassName': element['CreationClassName'], 'SystemName': element['SystemName'], 'DeviceID': element['DeviceID'], 'SystemCreationClassName': element['SystemCreationClassName']}}
    volume_no = ('0x' + element['DeviceID'][24:28])
    metadata = {'FJ_Backend': systemnamelist[0]['IdentifyingNumber'], 'FJ_Volume_Name': volumename, 'FJ_Volume_No': volume_no, 'FJ_Pool_Name': eternus_pool, 'FJ_Pool_Type': POOL_TYPE_dic[pooltype]}
    return (element_path, metadata)
