From: Alfredo Deza Date: Tue, 23 Sep 2014 15:25:52 +0000 (-0400) Subject: create grep functions for remote hosts X-Git-Tag: v1.5.16~8^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3ec4f6063a4cae1fb5db15006618c0026640b1eb;p=ceph-deploy.git create grep functions for remote hosts Signed-off-by: Alfredo Deza --- diff --git a/ceph_deploy/hosts/remotes.py b/ceph_deploy/hosts/remotes.py index d0df06d..26c4100 100644 --- a/ceph_deploy/hosts/remotes.py +++ b/ceph_deploy/hosts/remotes.py @@ -212,6 +212,33 @@ def get_file(path): pass +def object_grep(term, file_object): + for line in file_object.readlines(): + if term in line: + return True + return False + + +def grep(term, file_path): + # A small grep-like function that will search for a word in a file and + # return True if it does and False if it does not. + + # Implemented initially to have a similar behavior as the init system + # detection in Ceph's init scripts:: + + # # detect systemd + # # SYSTEMD=0 + # grep -qs systemd /proc/1/comm && SYSTEMD=1 + + # .. note:: Because we intent to be operating in silent mode, we explicitly + # return ``False`` if the file does not exist. + if not os.path.isfile(file_path): + return False + + with open(file_path) as _file: + return object_grep(term, _file) + + def shortname(): """get remote short hostname""" return socket.gethostname().split('.', 1)[0]