def queue_remove(self, image_spec): image_spec = self.extract_image_spec(image_spec) authorize_request(self.module, image_spec[0], image_spec[1]) self.log.info("queue_remove: {}".format(image_spec)) refs = {TASK_REF_ACTION: TASK_REF_ACTION_REMOVE, TASK_REF_POOL_NAME: image_spec[0], TASK_REF_POOL_NAMESPACE: image_spec[1], TASK_REF_IMAGE_NAME: image_spec[2]} with self.open_ioctx(image_spec) as ioctx: try: with rbd.Image(ioctx, image_spec[2]) as image: refs[TASK_REF_IMAGE_ID] = image.id() snaps = list(image.list_snaps()) except rbd.ImageNotFound: pass task = self.find_task(refs) if task: return 0, task.to_json(), '' if TASK_REF_IMAGE_ID not in refs: raise rbd.ImageNotFound("Image {} does not exist".format( self.format_image_spec(image_spec)), errno=errno.ENOENT) if snaps: raise rbd.ImageBusy("Image {} has snapshots".format( self.format_image_spec(image_spec)), errno=errno.EBUSY) return 0, self.add_task(ioctx, "Removing image {}".format( self.format_image_spec(image_spec)), refs), ''
def lock(self): self.log.info('lock') retry = 3 while retry: try: self.rbdimage.lock_exclusive(self.ceph.CEPH_LOCK_HOST) self.locked_by_me = True except rbd.ImageExists: # This client and cookie already locked this. This is # definitely fine. return except rbd.ImageBusy: # Maybe the same client but different cookie. We're fine with # different cookies - ignore this. Must be same client, though. status = self.lock_status() if status is None: # Someone had the lock but released it in between. # Lets try again retry -= 1 continue if status[1] == self.ceph.CEPH_LOCK_HOST: # That's locked for us already. We just re-use # the existing lock. return # Its locked for some other client. self.log.error('assume-lock-failed', competing=status) raise raise rbd.ImageBusy( 'Could not acquire lock - tried multiple times. ' 'Someone seems to be racing me.')
def queue_remove(self, image_spec): image_spec = self.extract_image_spec(image_spec) self.log.info("queue_remove: {}".format(image_spec)) refs = {TASK_REF_ACTION: TASK_REF_ACTION_REMOVE, TASK_REF_POOL_NAME: image_spec[0], TASK_REF_POOL_NAMESPACE: image_spec[1], TASK_REF_IMAGE_NAME: image_spec[2]} task = self.find_task(refs) if task: return 0, task.to_json(), '' with self.open_ioctx(image_spec) as ioctx: with rbd.Image(ioctx, image_spec[2]) as image: if list(image.list_snaps()): raise rbd.ImageBusy("Image {} has snapshots".format( self.format_image_spec(image_spec)), errno=errno.EBUSY) return 0, self.add_task(ioctx, "Removing image {}".format( self.format_image_spec(image_spec)), refs), ''