#!/usr/bin/python
import sys
import glob
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):
    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(sys.argv[1])
