]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-cm-ansible.git/commitdiff
vmlist.py: treat "-h/--host" case outside the normal flow 24/head
authorDan Mick <dan.mick@redhat.com>
Fri, 8 May 2015 21:27:33 +0000 (14:27 -0700)
committerDan Mick <dan.mick@redhat.com>
Fri, 8 May 2015 21:27:33 +0000 (14:27 -0700)
Needlessly complex trying to mix the streams, and no reason for
a separate process when doing only one machine; needed to make
outputfile default to None anyway

Signed-off-by: Dan Mick <dan.mick@redhat.com>
tools/vmlist.py

index cce2e77ebd18009f30bf9e9114a9ee0b33fdf9b2..fa1aa3113708f37647988b00badd65e954c0f49d 100755 (executable)
@@ -90,7 +90,7 @@ class Cfg(object):
 cfg = Cfg(os.path.expanduser(CONFFILE))
 
 
-def list_vms(host, outputfile):
+def list_vms(host, outputfile=None):
     """
     Connect to host and collect lxc-ls and virsh list --all output
     """
@@ -125,7 +125,7 @@ def list_vms(host, outputfile):
         outputfile.seek(0)
 
 
-def list_nova(outputfile):
+def list_nova(outputfile=None):
     if outputfile is None:
         outputfile = sys.stdout
     cloud_user = cfg.get('cloud_user')
@@ -164,12 +164,15 @@ def main():
     args = docopt.docopt(usage)
     cachefile = os.path.expanduser(cfg.get('cachefile'))
 
-    if args['--refresh'] or args['--host']:
+    if args['--host']:
+        list_vms(args['--host'])
+        return 0
+
+    if args['--refresh']:
 
         procs = []
         outfiles = []
-        hosts = [args['--host']] or cfg.get('vm_hosts').split('\n')
-        for host in hosts:
+        for host in cfg.get('vm_hosts').split('\n'):
             outfile = tempfile.NamedTemporaryFile()
             proc = multiprocessing.Process(
                 target=list_vms, args=(host, outfile)
@@ -178,13 +181,12 @@ def main():
             outfiles.append(outfile)
             proc.start()
 
-        if not args['--host']:
-            # one more for nova output
-            outfile = tempfile.NamedTemporaryFile()
-            proc = multiprocessing.Process(target=list_nova, args=(outfile,))
-            procs.append(proc)
-            outfiles.append(outfile)
-            proc.start()
+        # one more for nova output
+        outfile = tempfile.NamedTemporaryFile()
+        proc = multiprocessing.Process(target=list_nova, args=(outfile,))
+        procs.append(proc)
+        outfiles.append(outfile)
+        proc.start()
 
         for proc in procs:
             proc.join()
@@ -194,10 +196,6 @@ def main():
             lines.extend(fil.readlines())
         lines = sorted(lines)
 
-        if args['--host']:
-            sys.stdout.writelines(lines)
-            return 0
-
         with open(os.path.expanduser(cachefile), 'w') as cache:
             cache.write(''.join(lines))