'Extend volume on ETERNUS.'

@lockutils.synchronized('ETERNUS-vol', 'cinder-', True)
def extend_volume(self, volume, new_size):

    LOG.debug('extend_volume,    volume    id:    %(vid)s,    size:    %(size)s,    new_size:    %(nsize)s.', {'vid': volume['id'], 'size': volume['size'], 'nsize': new_size})
    self.conn = self._get_eternus_connection()
    volumesize = (new_size * units.Gi)
    volumename = self._create_volume_name(volume['id'])
    vol_instance = self._find_lun(volume)
    if (vol_instance is None):
        msg = (_('extend_volume,    volumename:    %(volumename)s,    volume    not    found.') % {'volumename': volumename})
        LOG.error(msg)
        raise exception.VolumeBackendAPIException(data=msg)
    LOG.debug('extend_volume,    volumename:    %(volumename)s,    volumesize:    %(volumesize)u,    volume    instance:    %(vol_instance)s.', {'volumename': volumename, 'volumesize': volumesize, 'vol_instance': vol_instance.path})
    eternus_pool = self._get_drvcfg('EternusPool')
    pool = self._find_pool(eternus_pool)
    if (pool is None):
        msg = (_('extend_volume,    eternus_pool:    %(eternus_pool)s,    pool    not    found.') % {'eternus_pool': eternus_pool})
        LOG.error(msg)
        raise exception.VolumeBackendAPIException(data=msg)
    if ('RSP' in pool['InstanceID']):
        pooltype = RAIDGROUP
    else:
        pooltype = TPPOOL
    configservice = self._find_eternus_service(STOR_CONF)
    if (configservice is None):
        msg = (_('extend_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('extend_volume,    CreateOrModifyElementFromStoragePool,    ConfigService:    %(service)s,    ElementName:    %(volumename)s,    InPool:    %(eternus_pool)s,    ElementType:    %(pooltype)u,    Size:    %(volumesize)u,    TheElement:    %(vol_instance)s.', {'service': configservice, 'volumename': volumename, 'eternus_pool': eternus_pool, 'pooltype': pooltype, 'volumesize': volumesize, 'vol_instance': vol_instance.path})
    (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'), TheElement=vol_instance.path)
    if (rc != 0):
        msg = (_('extend_volume,    volumename:    %(volumename)s,    Return    code:    %(rc)lu,    Error:    %(errordesc)s,    PoolType:    %(pooltype)s.') % {'volumename': volumename, 'rc': rc, 'errordesc': errordesc, 'pooltype': POOL_TYPE_dic[pooltype]})
        LOG.error(msg)
        raise exception.VolumeBackendAPIException(data=msg)
    LOG.debug('extend_volume,    volumename:    %(volumename)s,    Return    code:    %(rc)lu,    Error:    %(errordesc)s,    Pool    Name:    %(eternus_pool)s,    Pool    Type:    %(pooltype)s.', {'volumename': volumename, 'rc': rc, 'errordesc': errordesc, 'eternus_pool': eternus_pool, 'pooltype': POOL_TYPE_dic[pooltype]})
    return eternus_pool
