mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
util: fix tracevol.py to work with volumeNamePrefix in storageclass
tarcevol.py works with a fixed volume name prefix "csi-vol-", this could be changed by the storageclass and hence tracevol.py should work with the dynamic value rather than the static. Signed-off-by: Mudit Agarwal <muagarwa@redhat.com>
This commit is contained in:
parent
2ef5729a28
commit
953cfa508a
@ -113,21 +113,22 @@ def format_and_print_tables(arg, pvcs, table_rbd, table_cephfs):
|
||||
pvname = pvcs['spec']['volumeName']
|
||||
pvdata = get_pv_data(arg, pvname)
|
||||
if is_rbd_pv(arg, pvname, pvdata):
|
||||
format_table(arg, pvcs, table_rbd, True)
|
||||
format_table(arg, pvcs, pvdata, table_rbd, True)
|
||||
else:
|
||||
format_table(arg, pvcs, table_cephfs, False)
|
||||
format_table(arg, pvcs, pvdata, table_cephfs, False)
|
||||
else:
|
||||
for pvc in pvcs['items']:
|
||||
pvname = pvc['spec']['volumeName']
|
||||
pvdata = get_pv_data(arg, pvname)
|
||||
if is_rbd_pv(arg, pvname, pvdata):
|
||||
format_table(arg, pvc, table_rbd, True)
|
||||
format_table(arg, pvc, pvdata, table_rbd, True)
|
||||
else:
|
||||
format_table(arg, pvc, table_cephfs, False)
|
||||
format_table(arg, pvc, pvdata, table_cephfs, False)
|
||||
print(table_rbd)
|
||||
print(table_cephfs)
|
||||
|
||||
def format_table(arg, pvc_data, table, is_rbd):
|
||||
#pylint: disable=too-many-locals
|
||||
def format_table(arg, pvc_data, pvdata, table, is_rbd):
|
||||
"""
|
||||
format tables for pvc and image information
|
||||
"""
|
||||
@ -153,15 +154,17 @@ def format_table(arg, pvc_data, table, is_rbd):
|
||||
table.add_row([pvcname, pvname, "", False,
|
||||
False, False])
|
||||
return
|
||||
# get volname prefix
|
||||
volname_prefix = get_volname_prefix(arg, pvdata)
|
||||
# check image/subvolume details present rados omap
|
||||
pv_present, uuid_present = validate_volume_in_rados(arg, image_id, pvname, pool_name, is_rbd)
|
||||
present_in_cluster = False
|
||||
if is_rbd:
|
||||
present_in_cluster = check_image_in_cluster(arg, image_id, pool_name)
|
||||
present_in_cluster = check_image_in_cluster(arg, image_id, pool_name, volname_prefix)
|
||||
else:
|
||||
subvolname = "csi-vol-%s" % image_id
|
||||
subvolname = volname_prefix + image_id
|
||||
present_in_cluster = check_subvol_in_cluster(arg, subvolname)
|
||||
image_name = "csi-vol-%s" % image_id
|
||||
image_name = volname_prefix + image_id
|
||||
table.add_row([pvcname, pvname, image_name, pv_present,
|
||||
uuid_present, present_in_cluster])
|
||||
|
||||
@ -210,11 +213,11 @@ def check_pv_name_in_rados(arg, image_id, pvc_name, pool_name, is_rbd):
|
||||
return False
|
||||
return True
|
||||
|
||||
def check_image_in_cluster(arg, image_uuid, pool_name):
|
||||
def check_image_in_cluster(arg, image_uuid, pool_name, volname_prefix):
|
||||
"""
|
||||
validate pvc information in ceph backend
|
||||
"""
|
||||
image = "csi-vol-%s" % image_uuid
|
||||
image = volname_prefix + image_uuid
|
||||
cmd = ['rbd', 'info', image, "--pool", pool_name]
|
||||
if not arg.userkey:
|
||||
cmd += ["--id", arg.userid, "--key", arg.userkey]
|
||||
@ -513,6 +516,22 @@ def get_pv_data(arg, pvname):
|
||||
sys.exit()
|
||||
return pvdata
|
||||
|
||||
def get_volname_prefix(arg, pvdata):
|
||||
"""
|
||||
Returns volname prefix stored in storage class/pv,
|
||||
defaults to "csi-vol-"
|
||||
"""
|
||||
volname_prefix = "csi-vol-"
|
||||
if not pvdata:
|
||||
if arg.debug:
|
||||
print("failed to get pv data")
|
||||
sys.exit()
|
||||
volume_attr = pvdata['spec']['csi']['volumeAttributes']
|
||||
key = 'volumeNamePrefix'
|
||||
if key in volume_attr.keys():
|
||||
volname_prefix = volume_attr[key]
|
||||
return volname_prefix
|
||||
|
||||
if __name__ == "__main__":
|
||||
ARGS = PARSER.parse_args()
|
||||
if ARGS.command not in ["kubectl", "oc"]:
|
||||
|
Loading…
Reference in New Issue
Block a user