3 from ceph_volume import terminal
4 from ceph_volume import decorators
5 from ceph_volume.util import disk
10 A simple validator to ensure that a logical volume is specified like::
14 Or a full path to a device, like ``/dev/sda``
16 Because for LVM it is better to be specific on what group does an lv
20 def __call__(self, string):
22 if string.startswith('/'):
23 if not os.path.exists(string):
24 error = "Argument (device) does not exist: %s" % string
25 raise argparse.ArgumentError(None, error)
29 vg, lv = string.split('/')
31 error = "Logical volume must be specified as 'volume_group/logical_volume' but got: %s" % string
32 raise argparse.ArgumentError(None, error)
35 error = "Didn't specify a volume group like 'volume_group/logical_volume', got: %s" % string
37 error = "Didn't specify a logical volume like 'volume_group/logical_volume', got: %s" % string
40 raise argparse.ArgumentError(None, error)
44 class OSDPath(object):
46 Validate path exists and it looks like an OSD directory.
49 @decorators.needs_root
50 def __call__(self, string):
51 if not os.path.exists(string):
52 error = "Path does not exist: %s" % string
53 raise argparse.ArgumentError(None, error)
55 arg_is_partition = disk.is_partition(string)
57 return os.path.abspath(string)
58 absolute_path = os.path.abspath(string)
59 if not os.path.isdir(absolute_path):
60 error = "Argument is not a directory or device which is required to scan"
61 raise argparse.ArgumentError(None, error)
62 key_files = ['ceph_fsid', 'fsid', 'keyring', 'ready', 'type', 'whoami']
63 dir_files = os.listdir(absolute_path)
64 for key_file in key_files:
65 if key_file not in dir_files:
66 terminal.error('All following files must exist in path: %s' % ' '.join(key_files))
67 error = "Required file (%s) was not found in OSD dir path: %s" % (
71 raise argparse.ArgumentError(None, error)
73 return os.path.abspath(string)