3 # Script to determine whether a vif is on an internal bridge
5 # Copyright (C) 2009 Nicira Networks, Inc.
7 # Copying and distribution of this file, with or without modification,
8 # are permitted in any medium without royalty provided the copyright
9 # notice and this notice are preserved. This file is offered as-is,
10 # without warranty of any kind.
14 import xen.lowlevel.xs
16 # Query XenStore for the opaque reference of this vif
17 def get_vif_ref(domid, devid):
18 xenstore = xen.lowlevel.xs.xs()
19 t = xenstore.transaction_start()
20 vif_ref = xenstore.read(t, '/xapi/%s/private/vif/%s/ref' % (domid, devid))
21 xenstore.transaction_end(t)
24 # Query XAPI for the information we need using the vif's opaque reference
25 def dump_vif_info(domid, devid, vif_ref):
27 session = XenAPI.xapi_local()
28 session.xenapi.login_with_password("root", "")
29 vif_rec = session.xenapi.VIF.get_record(vif_ref)
30 net_rec = session.xenapi.network.get_record(vif_rec["network"])
32 if len(net_rec['PIFs']) == 0:
33 sys.stdout.write("true\n")
35 sys.stdout.write("false\n")
38 session.xenapi.session.logout()
40 if __name__ == '__main__':
41 if (len(sys.argv) != 3):
42 sys.stderr.write("ERROR: %s <domid> <devid>\n" % sys.argv[0])
48 vif_ref = get_vif_ref(domid, devid)
50 sys.stderr.write("ERROR: Could not find interface vif%s.%s\n"
54 dump_vif_info(domid, devid, vif_ref)