From e88218ee0f4b04c86ed6f611d4566e38427f3075 Mon Sep 17 00:00:00 2001 From: Michael Still Date: Sun, 26 Aug 2012 21:26:50 +1000 Subject: Move ensure_tree to utils Its useful to people other that virt drivers. Change-Id: I721094a1785d7a275f4bfa8994b7b114a6ec07f6 --- nova/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index a14263eaf..f10422935 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -1273,3 +1273,18 @@ class UndoManager(object): LOG.exception(msg, **kwargs) self._rollback() + + +def ensure_tree(path): + """Create a directory (and any ancestor directories required) + + :param path: Directory to create + """ + try: + os.makedirs(path) + except OSError as exc: + if exc.errno == errno.EEXIST: + if not os.path.isdir(path): + raise + else: + raise -- cgit