]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume util add a new Device class validator for args
authorAlfredo Deza <adeza@redhat.com>
Thu, 23 Aug 2018 13:13:28 +0000 (09:13 -0400)
committerAndrew Schoen <aschoen@redhat.com>
Wed, 29 Aug 2018 18:42:19 +0000 (13:42 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
(cherry picked from commit 5be2794b7fe42e3a4505ec9f406dd5ae46595bd9)

src/ceph-volume/ceph_volume/util/arg_validators.py

index 3866027ef97eca8838412d2336ae76c2664e6d4a..d0144fc58de30d7301143acff5c740e58d057cc4 100644 (file)
@@ -3,6 +3,7 @@ import os
 from ceph_volume import terminal
 from ceph_volume import decorators
 from ceph_volume.util import disk
+from ceph_volume.util.device import Device
 
 
 class LVPath(object):
@@ -41,6 +42,18 @@ class LVPath(object):
         return string
 
 
+class ValidDevice(object):
+
+    def __call__(self, string):
+        device = Device(string)
+        if not device.exists:
+            raise argparse.ArgumentError(
+                None, "Unable to proceed with non-existing device: %s" % string
+            )
+
+        return device
+
+
 class OSDPath(object):
     """
     Validate path exists and it looks like an OSD directory.