def attach_volume(core_identity, driver, instance_id, volume_id, device_location=None, mount_location=None, *args, **kwargs): """ Attach (And mount, if possible) volume to instance device_location and mount_location assumed if empty """ logger.info("Attach: %s --> %s" % (volume_id, instance_id)) logger.info("device_location:%s, mount_location: %s" % (device_location, mount_location)) try: init_task = attach_task.si(driver.__class__, driver.provider, driver.identity, instance_id, volume_id, device_location) mount_chain = _get_mount_chain(core_identity, driver, instance_id, volume_id, device_location, mount_location) init_task.link(mount_chain) print_task_chain(init_task) init_task.apply_async() except Exception as e: raise VolumeMountConflict(instance_id, volume_id) return mount_location
def attach_volume_task(core_identity, driver, instance_id, volume_id, device_location=None, mount_location=None, *args, **kwargs): """ Attach (And mount, if possible) volume to instance device_location and mount_location assumed if empty """ logger.info("Attach: %s --> %s" % (volume_id, instance_id)) logger.info("device_location:%s, mount_location: %s" % (device_location, mount_location)) try: attach_volume = attach_task.si( driver.__class__, driver.provider, driver.identity, instance_id, volume_id, device_location) if not hasattr(driver, 'deploy_to'): # Do not attempt to mount if we don't have sh access attach_volume.apply_async() # No mount location, return None return None mount_chain = _get_mount_chain(core_identity, driver, instance_id, volume_id, device_location, mount_location) attach_volume.link(mount_chain) attach_volume.apply_async() except Exception as e: raise VolumeMountConflict(instance_id, volume_id) return mount_location
def mount_volume_task(core_identity, driver, instance_id, volume_id, device=None, mount_location=None, *args, **kwargs): """ Mount, if possible, the volume to instance Device and mount_location assumed if empty """ logger.info("Mount ONLY: %s --> %s" % (volume_id, instance_id)) logger.info("device_location:%s --> mount_location: %s" % (device, mount_location)) try: if not hasattr(driver, 'deploy_to'): # Do not attempt to mount if we don't have sh access return None vol = driver.get_volume(volume_id) existing_mount = vol.extra.get('metadata', {}).get('mount_location') if existing_mount: raise VolumeMountConflict( instance_id, volume_id, "Volume already mounted at %s. Run 'unmount_volume' first!" % existing_mount) if not driver._connection.ex_volume_attached_to_instance( vol, instance_id): raise VolumeMountConflict( instance_id, volume_id, "Cannot mount volume %s " "-- Not attached to instance %s" % (volume_id, instance_id)) mount_chain = _get_mount_chain(core_identity, driver, instance_id, volume_id, device, mount_location) mount_chain.apply_async() except VolumeMountConflict: raise except Exception as e: logger.exception("Exc occurred") raise VolumeMountConflict(instance_id, volume_id) return mount_location
def mount_volume(core_identity, driver, instance_id, volume_id, device=None, mount_location=None, *args, **kwargs): """ This task-caller will: - verify that volume is not already mounted - raise exceptions that can be handled _prior_ to running async tasks - create an async "task chain" and execute if all pre-conditions are met. """ logger.info("Mount ONLY: %s --> %s" % (volume_id, instance_id)) logger.info("device_location:%s --> mount_location: %s" % (device, mount_location)) try: vol = driver.get_volume(volume_id) existing_mount = vol.extra.get('metadata', {}).get('mount_location') if existing_mount: raise VolumeMountConflict( instance_id, volume_id, "Volume already mounted at %s. Run 'unmount_volume' first!" % existing_mount) if not driver._connection.ex_volume_attached_to_instance( vol, instance_id): raise VolumeMountConflict( instance_id, volume_id, "Cannot mount volume %s " "-- Not attached to instance %s" % (volume_id, instance_id)) mount_chain = _get_mount_chain(core_identity, driver, instance_id, volume_id, device, mount_location) mount_chain.apply_async() except VolumeMountConflict: raise except Exception as e: logger.exception("Exc occurred") raise VolumeMountConflict(instance_id, volume_id) return mount_location
def unmount_volume_task(driver, instance_id, volume_id, *args, **kwargs): try: logger.info("UN-Mount ONLY: %s --> %s" % (volume_id, instance_id)) if not hasattr(driver, 'deploy_to'): raise Exception("Cannot mount " "-- Driver does not have a deploy_to method") # Only attempt to umount if we have sh access vol = driver.get_volume(volume_id) if not driver._connection.ex_volume_attached_to_instance( vol, instance_id): raise VolumeMountConflict("Cannot unmount volume %s " "-- Not attached to instance %s" % (volume_id, instance_id)) umount_chain = _get_umount_chain(driver, instance_id, volume_id) umount_chain.apply_async() return (True, None) except Exception as exc: logger.exception("Exception occurred creating the unmount task") return (False, exc.message)
def attach_volume_task(driver, instance_id, volume_id, device=None, mount_location=None, *args, **kwargs): logger.info("P_device - %s" % device) logger.info("P_mount_location - %s" % mount_location) try: attach_task.delay(driver.__class__, driver.provider, driver.identity, instance_id, volume_id, device).get() if not hasattr(driver, 'deploy_to'): #Do not attempt to mount if we don't have sh access return check_volume_task.delay(driver.__class__, driver.provider, driver.identity, instance_id, volume_id).get() mount_task.delay(driver.__class__, driver.provider, driver.identity, instance_id, volume_id, mount_location).get() except Exception, e: raise VolumeMountConflict(instance_id, volume_id)
def unmount_volume(driver, instance_id, volume_id, *args, **kwargs): """ This task-caller will: - verify that volume is attached - raise exceptions that can be handled _prior_ to running async tasks - create an async "task chain" and execute if all pre-conditions are met. """ try: logger.info("UN-Mount ONLY: %s --> %s" % (volume_id, instance_id)) # Only attempt to umount if we have sh access vol = driver.get_volume(volume_id) if not driver._connection.ex_volume_attached_to_instance( vol, instance_id): raise VolumeMountConflict("Cannot unmount volume %s " "-- Not attached to instance %s" % (volume_id, instance_id)) unmount_chain = _get_umount_chain(driver, instance_id, volume_id) unmount_chain.apply_async() return (True, None) except Exception as exc: logger.exception("Exception occurred creating the unmount task") return (False, exc.message)