Hypervisors: use utils.EnsureDirs
authorGuido Trotter <ultrotter@google.com>
Wed, 5 May 2010 14:46:45 +0000 (16:46 +0200)
committerGuido Trotter <ultrotter@google.com>
Fri, 7 May 2010 11:34:35 +0000 (13:34 +0200)
Swap a few os.mkdir calls with utils.EnsureDirs

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Balazs Lecz <leczb@google.com>

lib/hypervisor/hv_chroot.py
lib/hypervisor/hv_fake.py

index 178291d..e9f2317 100644 (file)
@@ -67,11 +67,7 @@ class ChrootManager(hv_base.BaseHypervisor):
 
   def __init__(self):
     hv_base.BaseHypervisor.__init__(self)
-    if not os.path.exists(self._ROOT_DIR):
-      os.mkdir(self._ROOT_DIR)
-    if not os.path.isdir(self._ROOT_DIR):
-      raise HypervisorError("Needed path %s is not a directory" %
-                            self._ROOT_DIR)
+    utils.EnsureDirs([(self._ROOT_DIR, constants.RUN_DIRS_MODE)])
 
   @staticmethod
   def _IsDirLive(path):
index a97bebe..c2990a3 100644 (file)
@@ -46,8 +46,7 @@ class FakeHypervisor(hv_base.BaseHypervisor):
 
   def __init__(self):
     hv_base.BaseHypervisor.__init__(self)
-    if not os.path.exists(self._ROOT_DIR):
-      os.mkdir(self._ROOT_DIR)
+    utils.EnsureDirs([(self._ROOT_DIR, constants.RUN_DIRS_MODE)])
 
   def ListInstances(self):
     """Get the list of running instances.