[node-patches] Change in ovirt-node[master]: support persist/unpersist files list
hadong0720 at gmail.com
hadong0720 at gmail.com
Thu Jul 17 08:58:14 UTC 2014
hadong has uploaded a new change for review.
Change subject: support persist/unpersist files list
......................................................................
support persist/unpersist files list
Change-Id: Iccfda8ca9958cee7059778b640b52570352904f1
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1120594
Signed-off-by: hadong <hadong at redhat.com>
---
D scripts/ovirt-config-password
M src/ovirt/node/utils/fs/__init__.py
2 files changed, 43 insertions(+), 32 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/03/30203/1
diff --git a/scripts/ovirt-config-password b/scripts/ovirt-config-password
deleted file mode 120000
index 89f9614..0000000
--- a/scripts/ovirt-config-password
+++ /dev/null
@@ -1 +0,0 @@
-ovirt-node-config-password
\ No newline at end of file
diff --git a/src/ovirt/node/utils/fs/__init__.py b/src/ovirt/node/utils/fs/__init__.py
index a660dd2..552b31b 100644
--- a/src/ovirt/node/utils/fs/__init__.py
+++ b/src/ovirt/node/utils/fs/__init__.py
@@ -387,26 +387,32 @@
def _config_path(self, fn=""):
return os.path.join(self.basedir, fn.strip("/"))
- def persist(self, path):
+ def persist(self, paths):
"""Persist path and bind mount it back to its current location
"""
# TODO: Abort if it is stateless
if not self.is_enabled():
return
- abspath = os.path.abspath(path)
- if os.path.exists(abspath):
- # Check first for symlinks as os.path file type detection follows
- # links and will give the type of the target
- try:
- if os.path.islink(abspath):
- self._persist_symlink(abspath)
- elif os.path.isdir(abspath):
- self._persist_dir(abspath)
- elif os.path.isfile(abspath):
- self._persist_file(abspath)
- except Exception:
- self._logger.error('Failed to persist "%s"', path)
- return -1
+ if isinstance(paths, STRING_TYPE):
+ paths_list = []
+ paths_list.append(paths)
+ else:
+ paths_list = paths
+ for path in paths_list:
+ abspath = os.path.abspath(path)
+ if os.path.exists(abspath):
+ # Check first for symlinks as os.path file type detection
+ # follows links and will give the type of the target
+ try:
+ if os.path.islink(abspath):
+ self._persist_symlink(abspath)
+ elif os.path.isdir(abspath):
+ self._persist_dir(abspath)
+ elif os.path.isfile(abspath):
+ self._persist_file(abspath)
+ except Exception:
+ self._logger.error('Failed to persist "%s"', path)
+ return -1
def _persist_dir(self, abspath):
"""Persist directory and bind mount it back to its current location
@@ -518,26 +524,32 @@
with open(self.path_entries, 'w') as path_entries:
print(filtered, file=path_entries)
- def unpersist(self, path):
+ def unpersist(self, paths):
"""Remove the persistent version of a file and remove the bind mount
"""
if not self.is_enabled():
return
- abspath = os.path.abspath(path)
- if os.path.exists(abspath):
- # Check first for symlinks as os.path file type detection follows
- # links and will give the type of the target
- try:
- if os.path.islink(abspath):
- self._unpersist_symlink(abspath)
- elif os.path.isdir(abspath):
- self._unpersist_dir(abspath)
- elif os.path.isfile(abspath):
- self._unpersist_file(abspath)
- except Exception:
- self._logger.error('Failed to unpersist "%s"', path,
- exc_info=True)
- return -1
+ if isinstance(paths, STRING_TYPE):
+ paths_list = []
+ paths_list.append(paths)
+ else:
+ paths_list = paths
+ for path in paths_list:
+ abspath = os.path.abspath(path)
+ if os.path.exists(abspath):
+ # Check first for symlinks as os.path file type detection
+ # follows links and will give the type of the target
+ try:
+ if os.path.islink(abspath):
+ self._unpersist_symlink(abspath)
+ elif os.path.isdir(abspath):
+ self._unpersist_dir(abspath)
+ elif os.path.isfile(abspath):
+ self._unpersist_file(abspath)
+ except Exception:
+ self._logger.error('Failed to unpersist "%s"', path,
+ exc_info=True)
+ return -1
def _cleanup_tree(self, dirpath):
"""Removes empty directories in the structure. abspath must be a dir"""
--
To view, visit http://gerrit.ovirt.org/30203
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iccfda8ca9958cee7059778b640b52570352904f1
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: hadong <hadong0720 at gmail.com>
More information about the node-patches
mailing list