]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
gatherkeys: move get_file() to misc.py
authorSage Weil <sage@inktank.com>
Mon, 11 Mar 2013 23:05:12 +0000 (16:05 -0700)
committerSage Weil <sage@inktank.com>
Mon, 11 Mar 2013 23:05:12 +0000 (16:05 -0700)
Signed-off-by: Sage Weil <sage@inktank.com>
ceph_deploy/gatherkeys.py
ceph_deploy/misc.py [new file with mode: 0644]

index 2f151aec4875c5771446a32a1ef7cfd0e5bf8b22..9c457e9930baac9312f7dea996500de9730e7aea 100644 (file)
@@ -1,44 +1,33 @@
+import os.path
 import argparse
 import logging
-import os.path
 
 from cStringIO import StringIO
 
 from . import exc
 from .cliutil import priority
-
+from . import misc
 
 log = logging.getLogger(__name__)
 
-
-def get_file(path):
-     """
-     Run on mon node, grab a file.
-     """
-     try:
-          with file(path, 'rb') as f:
-               return f.read()
-     except IOError:
-          pass
-
 def fetch_file(args, frompath, topath, hosts):
-     # mon.
-     if os.path.exists(topath):
-          log.debug('Have %s', topath)
-          return True
-     else:
-          for hostname in hosts:
-               log.debug('Checking %s for %s', hostname, frompath)
-               sudo = args.pushy('ssh+sudo:{hostname}'.format(hostname=hostname))
-               get_file_r = sudo.compile(get_file)
-               key = get_file_r(path=frompath.format(hostname=hostname))
-               if key is not None:
-                    log.debug('Got %s key from %s.', topath, hostname)
-                    with file(topath, 'w') as f:
-                         f.write(key)
-                         return True
-     log.warning('Unable to find %s on %s', frompath, hosts)
-     return False
+    # mon.
+    if os.path.exists(topath):
+        log.debug('Have %s', topath)
+        return True
+    else:
+        for hostname in hosts:
+            log.debug('Checking %s for %s', hostname, frompath)
+            sudo = args.pushy('ssh+sudo:{hostname}'.format(hostname=hostname))
+            get_file_r = sudo.compile(misc.get_file)
+            key = get_file_r(path=frompath.format(hostname=hostname))
+            if key is not None:
+                log.debug('Got %s key from %s.', topath, hostname)
+                with file(topath, 'w') as f:
+                    f.write(key)
+                    return True
+    log.warning('Unable to find %s on %s', frompath, hosts)
+    return False
 
 def gatherkeys(args):
      ret = 0
diff --git a/ceph_deploy/misc.py b/ceph_deploy/misc.py
new file mode 100644 (file)
index 0000000..b771fa2
--- /dev/null
@@ -0,0 +1,11 @@
+
+def get_file(path):
+     """
+     Run on mon node, grab a file.
+     """
+     try:
+          with file(path, 'rb') as f:
+               return f.read()
+     except IOError:
+          pass
+