From: Quentin Smith <quentin@mit.edu>
Date: Mon, 12 Nov 2007 04:18:17 +0000 (-0500)
Subject: Resync get_port.py from disk.
X-Git-Tag: sipb-xen-vnc-server/1~5
X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-vnc-server.git/commitdiff_plain/8ebae0c0aed6651c6f73b9a8ac52d2f2596f6357

Resync get_port.py from disk.

svn path=/trunk/vnc/vnc_server/; revision=232
---

diff --git a/get_port.py b/get_port.py
index ed1fc2f..a7b9413 100644
--- a/get_port.py
+++ b/get_port.py
@@ -5,17 +5,21 @@ sys.path.append('/usr/lib/xen-default/lib/python/')
 import xen.xm
 import xen.xm.XenAPI
 import xen.xend.XendClient
+import time
+import xmlrpclib
 
+prefix = "d_"
 server = xen.xm.XenAPI.Session(xen.xend.XendClient.uri)
 
 def findPort(name):
-    states = server.xend.domains_with_state(True, 'all', 1)
-    for state in states:
-        if dict(state[1:])['name'] == name:
-            for (key,value) in state[1:]:
-                if key == 'device' and value[0] == 'vfb':
-                    location=dict(value[1:]).get('location')
-                    return location
+    try:
+        state = server.xend.domain(prefix + name, True)
+        for (key,value) in state[1:]:
+            if key == 'device' and value[0] == 'vfb':
+                location=dict(value[1:]).get('location')
+                return location
+    except xmlrpclib.Fault:
+        return None
 
 if __name__ == '__main__':
-    print findPort("moo3")
+    print findPort(sys.argv[1])