-
- pool_name, namespace, image_name = parse_image_spec(image_spec)
-
- def _edit(ioctx, image):
- rbd_inst = rbd.RBD()
- # check rename image
- if name and name != image_name:
- rbd_inst.rename(ioctx, image_name, name)
-
- # check resize
- if size and size != image.size():
- image.resize(size)
-
- mirror_image_info = image.mirror_image_get_info()
- if enable_mirror and mirror_image_info['state'] == rbd.RBD_MIRROR_IMAGE_DISABLED:
- RbdMirroringService.enable_image(
- image_name, pool_name, namespace,
- MIRROR_IMAGE_MODE[mirror_mode])
- elif (enable_mirror is False
- and mirror_image_info['state'] == rbd.RBD_MIRROR_IMAGE_ENABLED):
- RbdMirroringService.disable_image(
- image_name, pool_name, namespace)
-
- # check enable/disable features
- if features is not None:
- curr_features = format_bitmask(image.features())
- # check disabled features
- _sort_features(curr_features, enable=False)
- for feature in curr_features:
- if (feature not in features
- and feature in self.ALLOW_DISABLE_FEATURES
- and feature in format_bitmask(image.features())):
- f_bitmask = format_features([feature])
- image.update_features(f_bitmask, False)
- # check enabled features
- _sort_features(features)
- for feature in features:
- if (feature not in curr_features
- and feature in self.ALLOW_ENABLE_FEATURES
- and feature not in format_bitmask(image.features())):
- f_bitmask = format_features([feature])
- image.update_features(f_bitmask, True)
-
- RbdConfiguration(pool_ioctx=ioctx, image_name=image_name).set_configuration(
- configuration)
- if metadata:
- RbdImageMetadataService(image).set_metadata(metadata)
-
- if primary and not mirror_image_info['primary']:
- RbdMirroringService.promote_image(
- image_name, pool_name, namespace, force)
- elif primary is False and mirror_image_info['primary']:
- RbdMirroringService.demote_image(
- image_name, pool_name, namespace)
-
- if resync:
- RbdMirroringService.resync_image(image_name, pool_name, namespace)
-
- if schedule_interval:
- RbdMirroringService.snapshot_schedule_add(image_spec, schedule_interval)
-
- if remove_scheduling:
- RbdMirroringService.snapshot_schedule_remove(image_spec)
-
- return rbd_image_call(pool_name, namespace, image_name, _edit)