Created
February 19, 2016 23:02
-
-
Save patrick-east/1cff43a04a2d3dc29085 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def init_host(self): | |
"""Perform any required initialization.""" | |
ctxt = context.get_admin_context() | |
LOG.info(_LI("Starting volume driver %(driver_name)s (%(version)s)"), | |
{'driver_name': self.driver.__class__.__name__, | |
'version': self.driver.get_version()}) | |
try: | |
self.driver.do_setup(ctxt) | |
self.driver.check_for_setup_error() | |
except Exception: | |
LOG.exception(_LE("Failed to initialize driver."), | |
resource={'type': 'driver', | |
'id': self.__class__.__name__}) | |
# we don't want to continue since we failed | |
# to initialize the driver correctly. | |
return | |
# Initialize backend capabilities list | |
self.driver.init_capabilities() | |
volumes = objects.VolumeList.get_all_by_host(ctxt, self.host) | |
snapshots = self.db.snapshot_get_by_host(ctxt, self.host) | |
self._sync_provider_info(ctxt, volumes, snapshots) | |
# FIXME volume count for exporting is wrong | |
try: | |
self.stats['pools'] = {} | |
self.stats.update({'allocated_capacity_gb': 0}) | |
for volume in volumes: | |
# available volume should also be counted into allocated | |
if volume['status'] in ['in-use', 'available']: | |
# calculate allocated capacity for driver | |
self._count_allocated_capacity(ctxt, volume) | |
try: | |
if volume['status'] in ['in-use']: | |
self.driver.ensure_export(ctxt, volume) | |
except Exception: | |
LOG.exception(_LE("Failed to re-export volume, " | |
"setting to ERROR."), | |
resource=volume) | |
volume.status = 'error' | |
volume.save() | |
elif volume['status'] in ('downloading', 'creating'): | |
LOG.warning(_LW("Detected volume stuck " | |
"in %(curr_status)s " | |
"status, setting to ERROR."), | |
{'curr_status': volume['status']}, | |
resource=volume) | |
if volume['status'] == 'downloading': | |
self.driver.clear_download(ctxt, volume) | |
volume.status = 'error' | |
volume.save() | |
elif volume.status == 'uploading': | |
# Set volume status to available or in-use. | |
self.db.volume_update_status_based_on_attachment( | |
ctxt, volume.id) | |
else: | |
pass | |
snapshots = objects.SnapshotList.get_by_host( | |
ctxt, self.host, {'status': 'creating'}) | |
for snapshot in snapshots: | |
LOG.warning(_LW("Detected snapshot stuck in creating " | |
"status, setting to ERROR."), resource=snapshot) | |
snapshot.status = 'error' | |
snapshot.save() | |
except Exception: | |
LOG.exception(_LE("Error during re-export on driver init."), | |
resource=volume) | |
return | |
self.driver.set_throttle() | |
# at this point the driver is considered initialized. | |
self.driver.set_initialized() | |
for volume in volumes: | |
if volume['status'] == 'deleting': | |
if CONF.volume_service_inithost_offload: | |
# Offload all the pending volume delete operations to the | |
# threadpool to prevent the main volume service thread | |
# from being blocked. | |
self._add_to_threadpool(self.delete_volume, ctxt, | |
volume['id']) | |
else: | |
# By default, delete volumes sequentially | |
self.delete_volume(ctxt, volume['id']) | |
LOG.info(_LI("Resume volume delete completed successfully."), | |
resource=volume) | |
# collect and publish service capabilities | |
self.publish_service_capabilities(ctxt) | |
# conditionally run replication status task | |
# FIXME(jdg): This should go away or be handled differently | |
# if/when we're ready for V2 replication | |
stats = self.driver.get_volume_stats(refresh=True) | |
if stats and stats.get('replication', False): | |
@periodic_task.periodic_task | |
def run_replication_task(self, ctxt): | |
self._update_replication_relationship_status(ctxt) | |
self.add_periodic_task(run_replication_task) | |
svc_host = vol_utils.extract_host(self.host, 'backend') | |
service = objects.Service.get_by_host_and_topic( | |
context.get_admin_context(), svc_host, | |
CONF.volume_topic) | |
replication_enabled = self.driver.replication_is_configured() | |
# We only accept the following responses as valid from the driver | |
valid_settings = ['not-capable', 'enabled', 'disabled'] | |
if replication_enabled not in valid_settings: | |
LOG.warning(_LW("Backend responded with invalid " | |
"replication_enabled " | |
"setting: %s (setting to \'disabled\'"), | |
replication_enabled) | |
service.replication_enabled = "disabled" | |
service.save() | |
else: | |
service.replication_enabled = replication_enabled | |
service.save() | |
LOG.info(_LI("Driver initialization completed successfully."), | |
resource={'type': 'driver', | |
'id': self.driver.__class__.__name__}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def init_host(self): | |
"""Perform any required initialization.""" | |
ctxt = context.get_admin_context() | |
LOG.info(_LI("Starting volume driver %(driver_name)s (%(version)s)"), | |
{'driver_name': self.driver.__class__.__name__, | |
'version': self.driver.get_version()}) | |
try: | |
self.driver.do_setup(ctxt) | |
self.driver.check_for_setup_error() | |
except Exception: | |
LOG.exception(_LE("Failed to initialize driver."), | |
resource={'type': 'driver', | |
'id': self.__class__.__name__}) | |
# we don't want to continue since we failed | |
# to initialize the driver correctly. | |
return | |
# Initialize backend capabilities list | |
self.driver.init_capabilities() | |
volumes = objects.VolumeList.get_all_by_host(ctxt, self.host) | |
snapshots = self.db.snapshot_get_by_host(ctxt, self.host) | |
self._sync_provider_info(ctxt, volumes, snapshots) | |
# FIXME volume count for exporting is wrong | |
try: | |
self.stats['pools'] = {} | |
self.stats.update({'allocated_capacity_gb': 0}) | |
for volume in volumes: | |
# available volume should also be counted into allocated | |
if volume['status'] in ['in-use', 'available']: | |
# calculate allocated capacity for driver | |
self._count_allocated_capacity(ctxt, volume) | |
try: | |
if volume['status'] in ['in-use']: | |
self.driver.ensure_export(ctxt, volume) | |
except Exception: | |
LOG.exception(_LE("Failed to re-export volume, " | |
"setting to ERROR."), | |
resource=volume) | |
volume.status = 'error' | |
volume.save() | |
elif volume['status'] in ('downloading', 'creating'): | |
LOG.warning(_LW("Detected volume stuck " | |
"in %(curr_status)s " | |
"status, setting to ERROR."), | |
{'curr_status': volume['status']}, | |
resource=volume) | |
if volume['status'] == 'downloading': | |
self.driver.clear_download(ctxt, volume) | |
volume.status = 'error' | |
volume.save() | |
elif volume.status == 'uploading': | |
# Set volume status to available or in-use. | |
self.db.volume_update_status_based_on_attachment( | |
ctxt, volume.id) | |
else: | |
pass | |
snapshots = objects.SnapshotList.get_by_host( | |
ctxt, self.host, {'status': 'creating'}) | |
for snapshot in snapshots: | |
LOG.warning(_LW("Detected snapshot stuck in creating " | |
"status, setting to ERROR."), resource=snapshot) | |
snapshot.status = 'error' | |
snapshot.save() | |
except Exception: | |
LOG.exception(_LE("Error during re-export on driver init."), | |
resource=volume) | |
return | |
self.driver.set_throttle() | |
# at this point the driver is considered initialized. | |
self.driver.set_initialized() | |
for volume in volumes: | |
if volume['status'] == 'deleting': | |
if CONF.volume_service_inithost_offload: | |
# Offload all the pending volume delete operations to the | |
# threadpool to prevent the main volume service thread | |
# from being blocked. | |
self._add_to_threadpool(self.delete_volume, ctxt, | |
volume['id']) | |
else: | |
# By default, delete volumes sequentially | |
self.delete_volume(ctxt, volume['id']) | |
LOG.info(_LI("Resume volume delete completed successfully."), | |
resource=volume) | |
# collect and publish service capabilities | |
self.publish_service_capabilities(ctxt) | |
# conditionally run replication status task | |
# FIXME(jdg): This should go away or be handled differently | |
# if/when we're ready for V2 replication | |
stats = self.driver.get_volume_stats(refresh=True) | |
if stats and stats.get('replication', False): | |
@periodic_task.periodic_task | |
def run_replication_task(self, ctxt): | |
self._update_replication_relationship_status(ctxt) | |
self.add_periodic_task(run_replication_task) | |
# v2 replication setup | |
svc_host = vol_utils.extract_host(self.host, 'backend') | |
service = objects.Service.get_by_host_and_topic( | |
context.get_admin_context(), svc_host, | |
CONF.volume_topic) | |
if service: | |
if stats and stats.get('replication_enabled', False): | |
service.replication_enabled = 'enabled' | |
else: | |
service.replication_enabled = 'disabled' | |
service.save() | |
LOG.info(_LI("Driver initialization completed successfully."), | |
resource={'type': 'driver', | |
'id': self.driver.__class__.__name__}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment