netdev: Fully handle netdev lifecycle through refcounting.
[sliver-openvswitch.git] / xenserver / usr_share_vswitch_scripts_dump-vif-details
index b0ceb40..3c33751 100755 (executable)
@@ -25,22 +25,22 @@ def get_vif_ref(domid, devid):
 
 # Query XAPI for the information we need using the vif's opaque reference
 def dump_vif_info(domid, devid, vif_ref):
+       session = XenAPI.xapi_local()
+       session.xenapi.login_with_password("root", "")
        try: 
-               session = XenAPI.xapi_local()
-               session.xenapi.login_with_password("root", "")
                vif_rec = session.xenapi.VIF.get_record(vif_ref)
                net_rec = session.xenapi.network.get_record(vif_rec["network"])
-               vm_rec = session.xenapi.VM.get_record(vif_rec["VM"])
+               vm_uuid = session.xenapi.VM.get_uuid(vif_rec["VM"])
 
                # Data to allow vNetManager to associate VIFs with xapi data
-               sys.stdout.write('--add=port.vif%s.%s.net-uuid=%s ' 
-                               % (domid, devid, net_rec["uuid"]))
-               sys.stdout.write('--add=port.vif%s.%s.vif-mac=%s ' 
-                               % (domid, devid, vif_rec["MAC"]))
-               sys.stdout.write('--add=port.vif%s.%s.vif-uuid=%s ' 
-                               % (domid, devid, vif_rec["uuid"]))
-               sys.stdout.write('--add=port.vif%s.%s.vm-uuid=%s ' 
-                               % (domid, devid, vm_rec["uuid"]))
+               vif_info = []
+               vif_info.append(('xs-network-uuid', net_rec["uuid"]))
+               vif_info.append(('xs-vif-mac', vif_rec["MAC"]))
+               vif_info.append(('xs-vif-uuid', vif_rec["uuid"]))
+               vif_info.append(('xs-vm-uuid', vm_uuid))
+               for key, value in vif_info:
+                       print("-- iface-set-external-id vif%s.%s %s %s"
+                             % (domid, devid, key, value))
 
                # vNetManager needs to know the network UUID(s) associated with
                # each datapath.  Normally interface-reconfigure adds them, but
@@ -52,17 +52,22 @@ def dump_vif_info(domid, devid, vif_ref):
                # There may still be a brief delay between the initial
                # ovs-vswitchd connection to vNetManager and setting this
                # configuration variable, but vNetManager can tolerate that.
-               if len(net_rec['PIFs']) == 0:
-                       key = 'bridge.%s.xs-network-uuids' % net_rec['bridge']
-                       value = net_rec['uuid']
-                       sys.stdout.write('--del-match=%s=* ' % key)
-                       sys.stdout.write('--add=%s=%s ' % (key, value))
+               if not net_rec['PIFs']:
+                       bridge = net_rec['bridge']
+
+                       xs_network_uuid = net_rec['uuid']
+                       print("-- br-set-external-id %s %s %s"
+                             % (bridge, "xs-network-uuids", xs_network_uuid))
+
+                       xs_network_name = net_rec['name_label']
+                       print("-- br-set-external-id %s %s %s"
+                             % (bridge, "xs-network-names", xs_network_name))
        finally:
                session.xenapi.session.logout()
        
 if __name__ == '__main__':
-       if (len(sys.argv) != 3):
-               sys.stderr.write("ERROR: %s <domid> <devid>\n")
+       if len(sys.argv) != 3:
+               sys.stderr.write("ERROR: %s <domid> <devid>\n" % sys.argv[0])
                sys.exit(1)
 
        domid = sys.argv[1]
@@ -71,7 +76,7 @@ if __name__ == '__main__':
        vif_ref = get_vif_ref(domid, devid)
        if not vif_ref:
                sys.stderr.write("ERROR: Could not find interface vif%s.%s\n" 
-                               % (domid, devid))
+                                % (domid, devid))
                sys.exit(1)
 
        dump_vif_info(domid, devid, vif_ref)