def mount_volume_task( driverCls, provider, identity, instance_id, volume_id, device_location, mount_location, device_type, mount_prefix=None, *args, **kwargs ): try: celery_logger.debug("mount task started at %s." % timezone.now()) celery_logger.debug("mount_location: %s" % (mount_location, )) driver = get_driver(driverCls, provider, identity) username = identity.get_username() instance = driver.get_instance(instance_id) volume = driver.get_volume(volume_id) try: attach_data = volume.extra['attachments'][0] if not device_location: device_location = attach_data['device'] except (KeyError, IndexError): celery_logger.warn( "Volume %s missing attachments in Extra" % (volume, ) ) if not device_location: raise Exception( "No device_location found or inferred by volume %s" % volume ) if not mount_prefix: mount_prefix = "/vol_" last_char = device_location[-1] # /dev/sdb --> b if not mount_location: mount_location = mount_prefix + last_char playbook_results = deploy_mount_volume( instance.ip, username, instance.id, device_location, mount_location=mount_location, device_type=device_type ) celery_logger.info(playbook_results) if execution_has_failures( playbook_results ) or execution_has_unreachable(playbook_results): raise Exception( "Error encountered while mounting volume: instance_id: {}, volume_id: {}" .format(instance_id, volume_id) ) return mount_location except Exception as exc: celery_logger.warn(exc) mount_volume_task.retry(exc=exc)
def prep_instance_for_snapshot(identity_id, instance_id, **celery_task_args): identity = Identity.objects.get(id=identity_id) try: celery_logger.debug("prep_instance_for_snapshot task started at %s." % timezone.now()) # NOTE: FIXMEIF the assumption that the 'linux username' # is the 'created_by' AtmosphereUser changes. username = identity.created_by.username driver = get_esh_driver(identity) instance = driver.get_instance(instance_id) if instance.extra.get('status', '') != 'active': celery_logger.info("prep_instance_for_snapshot skipped") return playbooks = deploy_prepare_snapshot(instance.ip, username, instance_id) celery_logger.info(playbooks.__dict__) hostname = build_host_name(instance.id, instance.ip) result = False if execution_has_failures(playbooks, hostname)\ or execution_has_unreachable(playbooks, hostname) else True if not result: raise Exception( "Error encountered while preparing instance for snapshot: %s" % playbooks.stats.summarize(host=hostname)) except Exception as exc: celery_logger.warn(exc) prep_instance_for_snapshot.retry(exc=exc)
def unmount_volume_task(driverCls, provider, identity, instance_id, volume_id, *args, **kwargs): try: celery_logger.debug("unmount task started at %s." % timezone.now()) driver = get_driver(driverCls, provider, identity) username = identity.get_username() instance = driver.get_instance(instance_id) volume = driver.get_volume(volume_id) device_location = None try: attach_data = volume.extra['attachments'][0] device_location = attach_data['device'] except (KeyError, IndexError): celery_logger.warn("Volume %s missing attachments in Extra" % (volume, )) if not device_location: raise Exception( "No device_location found or inferred by volume %s" % volume) try: playbooks = deploy_unmount_volume(instance.ip, username, instance.id, device_location) except DeviceBusyException: # Future-Fixme: Update VolumeStatusHistory.extra, set status to 'unmount_failed' raise hostname = build_host_name(instance.id, instance.ip) result = False if execution_has_failures(playbooks, hostname)\ or execution_has_unreachable(playbooks, hostname) else True if not result: raise Exception("Error encountered while unmounting volume: %s" % playbooks.stats.summarize(host=hostname)) return device_location except Exception as exc: celery_logger.warn(exc) unmount_volume_task.retry(exc=exc)
def prep_instance_for_snapshot(identity_id, instance_id, **celery_task_args): identity = Identity.objects.get(id=identity_id) try: celery_logger.debug("prep_instance_for_snapshot task started at %s." % timezone.now()) # NOTE: FIXMEIF the assumption that the 'linux username' # is the 'created_by' AtmosphereUser changes. username = identity.created_by.username driver = get_esh_driver(identity) instance = driver.get_instance(instance_id) if instance.extra.get('status','') != 'active': celery_logger.info("prep_instance_for_snapshot skipped") return playbooks = deploy_prepare_snapshot( instance.ip, username, instance_id) celery_logger.info(playbooks.__dict__) hostname = build_host_name(instance.id, instance.ip) result = False if execution_has_failures(playbooks, hostname)\ or execution_has_unreachable(playbooks, hostname) else True if not result: raise Exception( "Error encountered while preparing instance for snapshot: %s" % playbooks.stats.summarize(host=hostname)) except Exception as exc: celery_logger.warn(exc) prep_instance_for_snapshot.retry(exc=exc)
def check_volume_task( driverCls, provider, identity, instance_id, volume_id, device_type='ext4', *args, **kwargs ): try: celery_logger.debug("check_volume task started at %s." % timezone.now()) driver = get_driver(driverCls, provider, identity) instance = driver.get_instance(instance_id) volume = driver.get_volume(volume_id) username = identity.get_username() attach_data = volume.extra['attachments'][0] device_location = attach_data['device'] celery_logger.info("device_location: %s" % device_location) # One playbook to make two checks: # 1. Voume exists # 2. Volume has a filesystem # (If not, create one of type 'device_type') playbook_results = deploy_check_volume( instance.ip, username, instance.id, device_location, device_type=device_type ) success = not ( execution_has_failures(playbook_results) or execution_has_unreachable(playbook_results) ) if not success: raise Exception( "Error encountered while checking volume for filesystem: instance_id: {}, volume_id: {}" .format(instance_id, volume_id) ) return success except Exception as exc: celery_logger.warn(exc) check_volume_task.retry(exc=exc)
def check_volume_task(driverCls, provider, identity, instance_id, volume_id, device_type='ext4', *args, **kwargs): try: celery_logger.debug("check_volume task started at %s." % datetime.now()) driver = get_driver(driverCls, provider, identity) instance = driver.get_instance(instance_id) volume = driver.get_volume(volume_id) username = identity.get_username() attach_data = volume.extra['attachments'][0] device_location = attach_data['device'] celery_logger.info("device_location: %s" % device_location) # One playbook to make two checks: # 1. Voume exists # 2. Volume has a filesystem # (If not, create one of type 'device_type') playbooks = deploy_check_volume(instance.ip, username, instance.id, device_location, device_type=device_type) celery_logger.info(playbooks.__dict__) hostname = build_host_name(instance.id, instance.ip) result = False if execution_has_failures(playbooks, hostname)\ or execution_has_unreachable(playbooks, hostname) else True if not result: raise Exception( "Error encountered while checking volume for filesystem: %s" % playbooks.stats.summarize(host=hostname)) return result except LibcloudDeploymentError as exc: celery_logger.exception(exc) except Exception as exc: celery_logger.warn(exc) check_volume_task.retry(exc=exc)
def unmount_volume_task( driverCls, provider, identity, instance_id, volume_id, *args, **kwargs ): try: celery_logger.debug("unmount task started at %s." % timezone.now()) driver = get_driver(driverCls, provider, identity) username = identity.get_username() instance = driver.get_instance(instance_id) volume = driver.get_volume(volume_id) device_location = None try: attach_data = volume.extra['attachments'][0] device_location = attach_data['device'] except (KeyError, IndexError): celery_logger.warn( "Volume %s missing attachments in Extra" % (volume, ) ) if not device_location: raise Exception( "No device_location found or inferred by volume %s" % volume ) try: playbook_results = deploy_unmount_volume( instance.ip, username, instance.id, device_location ) except DeviceBusyException: # Future-Fixme: Update VolumeStatusHistory.extra, set status to 'unmount_failed' raise if execution_has_failures( playbook_results ) or execution_has_unreachable(playbook_results): raise Exception( "Error encountered while unmounting volume: instance_id: {}, volume_id: {}" .format(instance_id, volume_id) ) return device_location except Exception as exc: celery_logger.warn(exc) unmount_volume_task.retry(exc=exc)