]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
OpenStack.exists(): Don't list every instance
authorZack Cerza <zack@redhat.com>
Thu, 22 Oct 2015 16:39:36 +0000 (10:39 -0600)
committerZack Cerza <zack@redhat.com>
Thu, 22 Oct 2015 17:58:55 +0000 (11:58 -0600)
Instead of "openstack server list", dumping the entire tentant's list of
instances, use "openstack server show" to show a single instance. While
"list" can accept a "--name" argument to filter, it does not have an
"--id" argument.

Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/openstack/__init__.py

index 4216ac466852522fa5fc86abaaee92985082b0f1..ea9e1705ee6a1203d01b94a72d8c87c93594b406 100644 (file)
@@ -31,6 +31,8 @@ import subprocess
 import tempfile
 import teuthology
 
+from subprocess import CalledProcessError
+
 from teuthology.contextutil import safe_while
 from teuthology.config import config as teuth_config
 from teuthology.orchestra import connection
@@ -226,10 +228,15 @@ class OpenStack(object):
         Return true if the OpenStack name_or_id instance exists,
         false otherwise.
         """
-        servers = json.loads(misc.sh("openstack server list -f json"))
-        for server in servers:
-            if (server['ID'] == name_or_id or server['Name'] == name_or_id):
-                return True
+        try:
+            server = json.loads(
+                misc.sh("openstack server show -f json %s" % id)
+            )
+        except CalledProcessError:
+            return False
+        if (self.get_value(server, 'Name') == name_or_id or
+                self.get_value(server, 'ID') == name_or_id):
+            return True
         return False
 
     @staticmethod