summaryrefslogtreecommitdiffstats
path: root/glustolibs-misc/glustolibs/misc/misc_libs.py
diff options
context:
space:
mode:
Diffstat (limited to 'glustolibs-misc/glustolibs/misc/misc_libs.py')
-rwxr-xr-xglustolibs-misc/glustolibs/misc/misc_libs.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/glustolibs-misc/glustolibs/misc/misc_libs.py b/glustolibs-misc/glustolibs/misc/misc_libs.py
index ee6c74c6d..7b8010cd9 100755
--- a/glustolibs-misc/glustolibs/misc/misc_libs.py
+++ b/glustolibs-misc/glustolibs/misc/misc_libs.py
@@ -590,3 +590,38 @@ def daemon_reload(node):
g.log.error("Failed to reload the daemon")
return False
return True
+
+
+def git_clone_and_compile(hosts, link, dir_name,
+ compile_option='False'):
+ """This function clones a repo and depending
+ on kwargs compiles it.
+ Args:
+ hosts (list|str): List of hosts where the repo needs to be cloned.
+ link (str): Link to the repo that needs to be cloned.
+ dir_name (str): Directory where the repo is to be cloned.
+
+ Kwargs:
+ compile_option (bool): If this option is set to True
+ then the cloned repo will be compiled otherwise
+ the repo is only cloned on the hosts.
+
+ Returns:
+ bool : True on successfull cloning (and compilation)
+ False otherwise.
+ """
+ if isinstance(hosts, str):
+ hosts = [hosts]
+
+ cmd = ("cd /root; git clone %s %s;" % (link, dir_name))
+ if compile_option:
+ cmd = cmd + (("cd /root/%s; make") % dir_name)
+
+ for host in hosts:
+ ret, _, _ = g.run(host, cmd)
+ if ret:
+ g.log.error("Cloning/Compiling repo failed on %s" % host)
+ return False
+ else:
+ g.log.info("Successfully cloned/compiled repo on %s" % host)
+ return True