initscript: pass complete path to pidfile to status command
[sliver-openvswitch.git] / xenserver / usr_share_vswitch_scripts_vif-on-internal-bridge
1 #!/usr/bin/python
2 #
3 # Script to determine whether a vif is on an internal bridge 
4
5 # Copyright (C) 2009 Nicira Networks, Inc.
6 #
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.
11
12 import sys
13 import XenAPI
14 import xen.lowlevel.xs
15
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)
22     return vif_ref
23
24 # Query XAPI for the information we need using the vif's opaque reference
25 def dump_vif_info(domid, devid, vif_ref):
26     try:
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"])
31
32         if len(net_rec['PIFs']) == 0:
33             sys.stdout.write("true\n")
34         else:
35             sys.stdout.write("false\n")
36        
37     finally:
38         session.xenapi.session.logout()
39
40 if __name__ == '__main__':
41     if (len(sys.argv) != 3):
42         sys.stderr.write("ERROR: %s <domid> <devid>\n" % sys.argv[0])
43         sys.exit(1)
44
45     domid = sys.argv[1]
46     devid = sys.argv[2]
47
48     vif_ref = get_vif_ref(domid, devid)
49     if not vif_ref:
50         sys.stderr.write("ERROR: Could not find interface vif%s.%s\n"
51                 % (domid, devid))
52         sys.exit(1)
53
54     dump_vif_info(domid, devid, vif_ref)
55     sys.exit(0)
56