From: Sage Weil Date: Wed, 3 Jul 2013 17:52:29 +0000 (-0700) Subject: ceph-disk: add get_dev_name, path helpers X-Git-Tag: v0.61.7~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=be12811b4cb98ff1c2c691c67af7ad3586c436ff;p=ceph.git ceph-disk: add get_dev_name, path helpers Signed-off-by: Sage Weil (cherry picked from commit e0401591e352ea9653e3276d66aebeb41801eeb3) --- diff --git a/src/ceph-disk b/src/ceph-disk index cb9d510cf973..3f7f9d53bac6 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -198,6 +198,9 @@ def maybe_mkdir(*a, **kw): raise +# a device "name" is something like +# sdb +# cciss!c0d1 def list_all_partitions(): """ Return a list of devices and partitions @@ -220,6 +223,28 @@ def list_all_partitions(): dev_part_list[dev] = [] return dev_part_list +def get_dev_name(path): + """ + get device name from path. e.g., /dev/sda -> sdas, /dev/cciss/c0d1 -> cciss!c0d1 + """ + assert path.startswith('/dev/') + base = path[5:] + return base.replace('/', '!') + +# a device "path" is something like +# /dev/sdb +# /dev/cciss/c0d1 +def get_dev_path(name): + """ + get a path (/dev/...) from a name (cciss!c0d1) + """ + return '/dev/' + name.replace('!', '/') + +def get_dev_relpath(name): + """ + get a relative path to /dev from a name (cciss!c0d1) + """ + return name.replace('!', '/') def list_partitions(disk): """