Rename variable names from volume to volmap
In before, we use the name 'volume' to reference a volume mapping object. This will cause confusion since we have introduced the volume concept recently [1]. This commit rename 'volume' to 'volmap' whenever it is appropriate. [1] https://review.openstack.org/#/c/599902/ Change-Id: I73bd65138e01de2a229d28aa677e266ab13d0856
This commit is contained in:
@@ -169,27 +169,27 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
container.host = None
|
||||
container.save(context)
|
||||
|
||||
def _wait_for_volumes_available(self, context, volumes, container,
|
||||
def _wait_for_volumes_available(self, context, volmaps, container,
|
||||
timeout=60, poll_interval=1):
|
||||
start_time = time.time()
|
||||
request_volumes = copy.deepcopy(volumes)
|
||||
request_volumes = copy.deepcopy(volmaps)
|
||||
try:
|
||||
volumes = itertools.chain(volumes)
|
||||
volume = next(volumes)
|
||||
volmaps = itertools.chain(volmaps)
|
||||
volmap = next(volmaps)
|
||||
while time.time() - start_time < timeout:
|
||||
is_available, is_error = self.driver.is_volume_available(
|
||||
context, volume)
|
||||
context, volmap)
|
||||
if is_available:
|
||||
volume = next(volumes)
|
||||
volmap = next(volmaps)
|
||||
if is_error:
|
||||
break
|
||||
time.sleep(poll_interval)
|
||||
except StopIteration:
|
||||
return
|
||||
for volume in request_volumes:
|
||||
if volume.auto_remove:
|
||||
for volmap in request_volumes:
|
||||
if volmap.auto_remove:
|
||||
try:
|
||||
self.driver.delete_volume(context, volume)
|
||||
self.driver.delete_volume(context, volmap)
|
||||
except Exception:
|
||||
LOG.exception("Failed to delete volume")
|
||||
msg = _("Volumes did not reach available status after"
|
||||
@@ -197,19 +197,19 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
self._fail_container(context, container, msg, unset_host=True)
|
||||
raise exception.Conflict(msg)
|
||||
|
||||
def _wait_for_volumes_deleted(self, context, volumes, container,
|
||||
def _wait_for_volumes_deleted(self, context, volmaps, container,
|
||||
timeout=60, poll_interval=1):
|
||||
start_time = time.time()
|
||||
try:
|
||||
volumes = itertools.chain(volumes)
|
||||
volume = next(volumes)
|
||||
volmaps = itertools.chain(volmaps)
|
||||
volmap = next(volmaps)
|
||||
while time.time() - start_time < timeout:
|
||||
if not volume.auto_remove:
|
||||
volume = next(volumes)
|
||||
if not volmap.auto_remove:
|
||||
volmap = next(volmaps)
|
||||
is_deleted, is_error = self.driver.is_volume_deleted(
|
||||
context, volume)
|
||||
context, volmap)
|
||||
if is_deleted:
|
||||
volume = next(volumes)
|
||||
volmap = next(volmaps)
|
||||
if is_error:
|
||||
break
|
||||
time.sleep(poll_interval)
|
||||
@@ -375,61 +375,61 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
self._fail_container(context, container, six.text_type(e),
|
||||
unset_host=True)
|
||||
|
||||
def _attach_volumes(self, context, container, volumes):
|
||||
def _attach_volumes(self, context, container, volmaps):
|
||||
try:
|
||||
for volume in volumes:
|
||||
volume.container_uuid = container.uuid
|
||||
volume.host = self.host
|
||||
self._attach_volume(context, volume)
|
||||
for volmap in volmaps:
|
||||
volmap.container_uuid = container.uuid
|
||||
volmap.host = self.host
|
||||
self._attach_volume(context, volmap)
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self._fail_container(context, container, six.text_type(e),
|
||||
unset_host=True)
|
||||
|
||||
def _attach_volume(self, context, volume):
|
||||
volume.create(context)
|
||||
def _attach_volume(self, context, volmap):
|
||||
volmap.create(context)
|
||||
context = context.elevated()
|
||||
LOG.info('Attaching volume %(volume_id)s to %(host)s',
|
||||
{'volume_id': volume.cinder_volume_id,
|
||||
{'volume_id': volmap.cinder_volume_id,
|
||||
'host': CONF.host})
|
||||
try:
|
||||
self.driver.attach_volume(context, volume)
|
||||
self.driver.attach_volume(context, volmap)
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error("Failed to attach volume %(volume_id)s to "
|
||||
"container %(container_id)s",
|
||||
{'volume_id': volume.cinder_volume_id,
|
||||
'container_id': volume.container_uuid})
|
||||
if volume.auto_remove:
|
||||
{'volume_id': volmap.cinder_volume_id,
|
||||
'container_id': volmap.container_uuid})
|
||||
if volmap.auto_remove:
|
||||
try:
|
||||
self.driver.delete_volume(context, volume)
|
||||
self.driver.delete_volume(context, volmap)
|
||||
except Exception:
|
||||
LOG.exception("Failed to delete volume %s.",
|
||||
volume.cinder_volume_id)
|
||||
volume.destroy()
|
||||
volmap.cinder_volume_id)
|
||||
volmap.destroy()
|
||||
|
||||
def _detach_volumes(self, context, container, reraise=True):
|
||||
volumes = objects.VolumeMapping.list_by_container(context,
|
||||
volmaps = objects.VolumeMapping.list_by_container(context,
|
||||
container.uuid)
|
||||
for volume in volumes:
|
||||
db_volumes = objects.VolumeMapping.list_by_cinder_volume(
|
||||
context, volume.cinder_volume_id)
|
||||
self._detach_volume(context, volume, reraise=reraise)
|
||||
if volume.auto_remove and len(db_volumes) == 1:
|
||||
self.driver.delete_volume(context, volume)
|
||||
self._wait_for_volumes_deleted(context, volumes, container)
|
||||
for volmap in volmaps:
|
||||
db_volmaps = objects.VolumeMapping.list_by_cinder_volume(
|
||||
context, volmap.cinder_volume_id)
|
||||
self._detach_volume(context, volmap, reraise=reraise)
|
||||
if volmap.auto_remove and len(db_volmaps) == 1:
|
||||
self.driver.delete_volume(context, volmap)
|
||||
self._wait_for_volumes_deleted(context, volmaps, container)
|
||||
|
||||
def _detach_volume(self, context, volume, reraise=True):
|
||||
def _detach_volume(self, context, volmap, reraise=True):
|
||||
context = context.elevated()
|
||||
try:
|
||||
self.driver.detach_volume(context, volume)
|
||||
self.driver.detach_volume(context, volmap)
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception(reraise=reraise):
|
||||
LOG.error("Failed to detach volume %(volume_id)s from "
|
||||
"container %(container_id)s",
|
||||
{'volume_id': volume.cinder_volume_id,
|
||||
'container_id': volume.container_uuid})
|
||||
volume.destroy()
|
||||
{'volume_id': volmap.cinder_volume_id,
|
||||
'container_id': volmap.container_uuid})
|
||||
volmap.destroy()
|
||||
|
||||
def _use_sandbox(self):
|
||||
if CONF.use_sandbox and self.driver.capabilities["support_sandbox"]:
|
||||
@@ -677,9 +677,8 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
self._do_container_start(context, created_container)
|
||||
|
||||
def _get_vol_info(self, context, container):
|
||||
volumes = objects.VolumeMapping.list_by_container(context,
|
||||
container.uuid)
|
||||
return volumes
|
||||
return objects.VolumeMapping.list_by_container(context,
|
||||
container.uuid)
|
||||
|
||||
def _get_network_info(self, context, container):
|
||||
neutron_api = neutron.NeutronAPI(context)
|
||||
|
||||
@@ -75,18 +75,18 @@ class CinderWorkflow(object):
|
||||
self.context = context
|
||||
self.cinder_api = cinder.CinderAPI(self.context)
|
||||
|
||||
def attach_volume(self, volume):
|
||||
def attach_volume(self, volmap):
|
||||
try:
|
||||
return self._do_attach_volume(self.cinder_api, volume)
|
||||
return self._do_attach_volume(self.cinder_api, volmap)
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.exception("Failed to attach volume %(volume_id)s",
|
||||
{'volume_id': volume.cinder_volume_id})
|
||||
self.cinder_api.unreserve_volume(volume.cinder_volume_id)
|
||||
{'volume_id': volmap.cinder_volume_id})
|
||||
self.cinder_api.unreserve_volume(volmap.cinder_volume_id)
|
||||
|
||||
def _do_attach_volume(self, cinder_api, volume):
|
||||
volume_id = volume.cinder_volume_id
|
||||
container_uuid = volume.container_uuid
|
||||
def _do_attach_volume(self, cinder_api, volmap):
|
||||
volume_id = volmap.cinder_volume_id
|
||||
container_uuid = volmap.container_uuid
|
||||
|
||||
cinder_api.reserve_volume(volume_id)
|
||||
conn_info = cinder_api.initialize_connection(
|
||||
@@ -106,14 +106,14 @@ class CinderWorkflow(object):
|
||||
conn_info['data']['device_path'] = device_info['path']
|
||||
mountpoint = device_info['path']
|
||||
try:
|
||||
volume.connection_info = jsonutils.dumps(conn_info)
|
||||
volmap.connection_info = jsonutils.dumps(conn_info)
|
||||
except TypeError:
|
||||
pass
|
||||
# NOTE(hongbin): save connection_info in the database
|
||||
# before calling cinder_api.attach because the volume status
|
||||
# will go to 'in-use' then caller immediately try to detach
|
||||
# the volume and connection_info is required for detach.
|
||||
volume.save()
|
||||
volmap.save()
|
||||
|
||||
try:
|
||||
cinder_api.attach(volume_id=volume_id,
|
||||
@@ -134,7 +134,7 @@ class CinderWorkflow(object):
|
||||
# Cinder-volume might have completed volume attach. So
|
||||
# we should detach the volume. If the attach did not
|
||||
# happen, the detach request will be ignored.
|
||||
cinder_api.detach(volume)
|
||||
cinder_api.detach(volmap)
|
||||
|
||||
return device_info['path']
|
||||
|
||||
@@ -149,15 +149,15 @@ class CinderWorkflow(object):
|
||||
connector = get_volume_connector(protocol)
|
||||
connector.disconnect_volume(conn_info['data'], None)
|
||||
|
||||
def detach_volume(self, context, volume):
|
||||
volume_id = volume.cinder_volume_id
|
||||
def detach_volume(self, context, volmap):
|
||||
volume_id = volmap.cinder_volume_id
|
||||
try:
|
||||
self.cinder_api.begin_detaching(volume_id)
|
||||
except cinder_exception.BadRequest as e:
|
||||
raise exception.Invalid(_("Invalid volume: %s") %
|
||||
six.text_type(e))
|
||||
|
||||
conn_info = jsonutils.loads(volume.connection_info)
|
||||
conn_info = jsonutils.loads(volmap.connection_info)
|
||||
if not self._volume_connection_keep(context, volume_id):
|
||||
try:
|
||||
self._disconnect_volume(conn_info)
|
||||
@@ -169,7 +169,7 @@ class CinderWorkflow(object):
|
||||
|
||||
self.cinder_api.terminate_connection(
|
||||
volume_id, get_volume_connector_properties())
|
||||
self.cinder_api.detach(volume)
|
||||
self.cinder_api.detach(volmap)
|
||||
|
||||
def _volume_connection_keep(self, context, volume_id):
|
||||
host = CONF.host
|
||||
@@ -181,8 +181,8 @@ class CinderWorkflow(object):
|
||||
return False
|
||||
return True
|
||||
|
||||
def delete_volume(self, volume):
|
||||
volume_id = volume.cinder_volume_id
|
||||
def delete_volume(self, volmap):
|
||||
volume_id = volmap.cinder_volume_id
|
||||
try:
|
||||
self.cinder_api.delete_volume(volume_id)
|
||||
except cinder_exception as e:
|
||||
|
||||
@@ -79,10 +79,10 @@ class VolumeDriver(object):
|
||||
def bind_mount(self, *args, **kwargs):
|
||||
raise NotImplementedError()
|
||||
|
||||
def is_volume_available(self, context, volume):
|
||||
def is_volume_available(self, context, volmap):
|
||||
raise NotImplementedError()
|
||||
|
||||
def is_volume_deleted(self, context, volume):
|
||||
def is_volume_deleted(self, context, volmap):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
@@ -91,33 +91,33 @@ class Local(VolumeDriver):
|
||||
supported_providers = ['local']
|
||||
|
||||
@validate_volume_provider(supported_providers)
|
||||
def attach(self, context, volume):
|
||||
mountpoint = mount.get_mountpoint(volume.uuid)
|
||||
def attach(self, context, volmap):
|
||||
mountpoint = mount.get_mountpoint(volmap.uuid)
|
||||
fileutils.ensure_tree(mountpoint)
|
||||
filename = '/'.join([mountpoint, volume.uuid])
|
||||
filename = '/'.join([mountpoint, volmap.uuid])
|
||||
with open(filename, 'wb') as fd:
|
||||
content = utils.decode_file_data(volume.contents)
|
||||
content = utils.decode_file_data(volmap.contents)
|
||||
fd.write(content)
|
||||
|
||||
def _remove_local_file(self, volume):
|
||||
mountpoint = mount.get_mountpoint(volume.uuid)
|
||||
def _remove_local_file(self, volmap):
|
||||
mountpoint = mount.get_mountpoint(volmap.uuid)
|
||||
shutil.rmtree(mountpoint)
|
||||
|
||||
@validate_volume_provider(supported_providers)
|
||||
def detach(self, context, volume):
|
||||
self._remove_local_file(volume)
|
||||
def detach(self, context, volmap):
|
||||
self._remove_local_file(volmap)
|
||||
|
||||
@validate_volume_provider(supported_providers)
|
||||
def delete(self, context, volume):
|
||||
self._remove_local_file(volume)
|
||||
def delete(self, context, volmap):
|
||||
self._remove_local_file(volmap)
|
||||
|
||||
@validate_volume_provider(supported_providers)
|
||||
def bind_mount(self, context, volume):
|
||||
mountpoint = mount.get_mountpoint(volume.uuid)
|
||||
filename = '/'.join([mountpoint, volume.uuid])
|
||||
return filename, volume.container_path
|
||||
def bind_mount(self, context, volmap):
|
||||
mountpoint = mount.get_mountpoint(volmap.uuid)
|
||||
filename = '/'.join([mountpoint, volmap.uuid])
|
||||
return filename, volmap.container_path
|
||||
|
||||
def is_volume_available(self, context, volume):
|
||||
def is_volume_available(self, context, volmap):
|
||||
return True, False
|
||||
|
||||
|
||||
@@ -128,64 +128,64 @@ class Cinder(VolumeDriver):
|
||||
]
|
||||
|
||||
@validate_volume_provider(supported_providers)
|
||||
def attach(self, context, volume):
|
||||
def attach(self, context, volmap):
|
||||
cinder = cinder_workflow.CinderWorkflow(context)
|
||||
devpath = cinder.attach_volume(volume)
|
||||
devpath = cinder.attach_volume(volmap)
|
||||
try:
|
||||
self._mount_device(volume, devpath)
|
||||
self._mount_device(volmap, devpath)
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.exception("Failed to mount device")
|
||||
try:
|
||||
cinder.detach_volume(volume)
|
||||
cinder.detach_volume(volmap)
|
||||
except Exception:
|
||||
LOG.exception("Failed to detach volume")
|
||||
|
||||
def _mount_device(self, volume, devpath):
|
||||
mountpoint = mount.get_mountpoint(volume.uuid)
|
||||
def _mount_device(self, volmap, devpath):
|
||||
mountpoint = mount.get_mountpoint(volmap.uuid)
|
||||
fileutils.ensure_tree(mountpoint)
|
||||
mount.do_mount(devpath, mountpoint, CONF.volume.fstype)
|
||||
|
||||
@validate_volume_provider(supported_providers)
|
||||
def detach(self, context, volume):
|
||||
self._unmount_device(volume)
|
||||
def detach(self, context, volmap):
|
||||
self._unmount_device(volmap)
|
||||
cinder = cinder_workflow.CinderWorkflow(context)
|
||||
cinder.detach_volume(context, volume)
|
||||
cinder.detach_volume(context, volmap)
|
||||
|
||||
@validate_volume_provider(supported_providers)
|
||||
def delete(self, context, volume):
|
||||
def delete(self, context, volmap):
|
||||
cinder = cinder_workflow.CinderWorkflow(context)
|
||||
cinder.delete_volume(volume)
|
||||
cinder.delete_volume(volmap)
|
||||
|
||||
def _unmount_device(self, volume):
|
||||
if hasattr(volume, 'connection_info'):
|
||||
mountpoint = mount.get_mountpoint(volume.uuid)
|
||||
def _unmount_device(self, volmap):
|
||||
if hasattr(volmap, 'connection_info'):
|
||||
mountpoint = mount.get_mountpoint(volmap.uuid)
|
||||
mount.do_unmount(mountpoint)
|
||||
shutil.rmtree(mountpoint)
|
||||
|
||||
@validate_volume_provider(supported_providers)
|
||||
def bind_mount(self, context, volume):
|
||||
mountpoint = mount.get_mountpoint(volume.uuid)
|
||||
return mountpoint, volume.container_path
|
||||
def bind_mount(self, context, volmap):
|
||||
mountpoint = mount.get_mountpoint(volmap.uuid)
|
||||
return mountpoint, volmap.container_path
|
||||
|
||||
@validate_volume_provider(supported_providers)
|
||||
def get_volume_status(self, context, volume):
|
||||
def get_volume_status(self, context, volmap):
|
||||
ca = cinder_api.CinderAPI(context)
|
||||
return ca.get(volume.cinder_volume_id).status
|
||||
return ca.get(volmap.cinder_volume_id).status
|
||||
|
||||
@validate_volume_provider(supported_providers)
|
||||
def check_multiattach(self, context, volume):
|
||||
def check_multiattach(self, context, volmap):
|
||||
ca = cinder_api.CinderAPI(context)
|
||||
return ca.get(volume.cinder_volume_id).multiattach
|
||||
return ca.get(volmap.cinder_volume_id).multiattach
|
||||
|
||||
@validate_volume_provider(supported_providers)
|
||||
def is_volume_available(self, context, volume):
|
||||
status = self.get_volume_status(context, volume)
|
||||
def is_volume_available(self, context, volmap):
|
||||
status = self.get_volume_status(context, volmap)
|
||||
if status == 'available':
|
||||
is_available = True
|
||||
is_error = False
|
||||
elif status == 'in-use':
|
||||
multiattach = self.check_multiattach(context, volume)
|
||||
multiattach = self.check_multiattach(context, volmap)
|
||||
is_available = multiattach
|
||||
is_error = False
|
||||
elif status == 'error':
|
||||
@@ -198,10 +198,10 @@ class Cinder(VolumeDriver):
|
||||
return is_available, is_error
|
||||
|
||||
@validate_volume_provider(supported_providers)
|
||||
def is_volume_deleted(self, context, volume):
|
||||
def is_volume_deleted(self, context, volmap):
|
||||
try:
|
||||
volume = cinder_api.CinderAPI(context).search_volume(
|
||||
volume.cinder_volume_id)
|
||||
volmap.cinder_volume_id)
|
||||
is_deleted = False
|
||||
# Cinder volume error states: 'error', 'error_deleting',
|
||||
# 'error_backing-up', 'error_restoring', 'error_extending',
|
||||
|
||||
Reference in New Issue
Block a user