Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions rbd-target-api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from functools import wraps
from rpm import labelCompare
import rados
import rbd
from nose.tools import eq_ as eq

import werkzeug
from flask import Flask, jsonify, make_response, request
Expand Down Expand Up @@ -948,6 +950,17 @@ def clientlun(client_iqn):
# this is a delete request
if disk in lun_list:
lun_list.remove(disk)

pool_name, image_name = disk.split('.')
with rados.Rados(conffile=settings.config.cephconf) as cluster:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could collapse into a single with:

with rados.Rados(conffile=settings.config.cephconf) as cluster, \
        cluster.open_ioctx(pool_name) as ioctx, \
        rbd.Image(ioctx, image_name) as image:

with cluster.open_ioctx(pool_name) as ioctx:
with rbd.Image(ioctx, image_name) as image:

if len(image.list_lockers()):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: no need, just invoke the line below but wrap it w/ a try/except clause to catch rbd.ImageNotFound and rbd.InvalidArgument.

lock_owners = list(image.lock_get_owners())
eq(1, len(lock_owners))
eq(rbd.RBD_LOCK_MODE_EXCLUSIVE, lock_owners[0]['mode'])
image.lock_break(rbd.RBD_LOCK_MODE_EXCLUSIVE, lock_owners[0]['owner'])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: wrap w/ try/except to avoid race conditions

else:
return jsonify(message="disk not mapped to client"), 400

Expand Down