def _create_snapshot(ioctx, img, snapshot_name):
mirror_info = img.mirror_image_get_info()
- mirror_mode = img.mirror_image_get_mode()
- if (mirror_info['state'] == rbd.RBD_MIRROR_IMAGE_ENABLED and mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT) and mirrorImageSnapshot: # noqa E501 #pylint: disable=line-too-long
+ mirror_mode = None
+ if mirror_info['state'] == rbd.RBD_MIRROR_IMAGE_ENABLED:
+ mirror_mode = img.mirror_image_get_mode()
+
+ if (mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT) and mirrorImageSnapshot:
img.mirror_image_create_snapshot()
else:
img.create_snap(snapshot_name)
def _get_mirror_mode(ioctx, image_name):
with rbd.Image(ioctx, image_name) as img:
- mirror_mode = img.mirror_image_get_mode()
+ mirror_mode = None
mirror_mode_str = 'Disabled'
+ try:
+ mirror_mode = img.mirror_image_get_mode()
+ except rbd.InvalidArgument:
+ # Suppress exception raised when mirroring is disabled
+ pass
+
if mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_JOURNAL:
mirror_mode_str = 'journal'
elif mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT:
with rbd.Image(ioctx, image_name) as img:
stat = img.stat()
mirror_info = img.mirror_image_get_info()
- mirror_mode = img.mirror_image_get_mode()
- if mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_JOURNAL and mirror_info['state'] != rbd.RBD_MIRROR_IMAGE_DISABLED: # noqa E501 #pylint: disable=line-too-long
+ mirror_mode = None
+ if mirror_info['state'] != rbd.RBD_MIRROR_IMAGE_DISABLED:
+ mirror_mode = img.mirror_image_get_mode()
+ else:
+ stat['mirror_mode'] = 'Disabled'
+
+ if mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_JOURNAL:
stat['mirror_mode'] = 'journal'
elif mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT:
stat['mirror_mode'] = 'snapshot'
for scheduled_image in schedule_status['scheduled_images']:
if scheduled_image['image'] == get_image_spec(pool_name, namespace, image_name):
stat['schedule_info'] = scheduled_image
- else:
- stat['mirror_mode'] = 'Disabled'
stat['name'] = image_name
if snap['namespace'] == rbd.RBD_SNAP_NAMESPACE_TYPE_TRASH:
continue
- try:
- snap['mirror_mode'] = MIRROR_IMAGE_MODE(img.mirror_image_get_mode()).name
- except ValueError as ex:
- raise DashboardException(f'Unknown RBD Mirror mode: {ex}')
+ if mirror_mode:
+ snap['mirror_mode'] = mirror_mode
snap['timestamp'] = "{}Z".format(
img.get_snap_timestamp(snap['id']).isoformat())