Skip to contentSkip to conversation

RFC: Migration and VBD/SR/VDI creation

PATCH Pascal Bouchareine 1 participant 1 message May 18, 2007

lore
Share & tools
lore
#0 lore raw

Hi,

When migrating a domain, the VDI definition is not recreated building the VBD, hence loosing API access to the VBD location & al ({'VDI' : ''}).

The attached patch is an attempt to recreate the VDI in XendConfig.device_add (in the 'Local' SR, eventually some other) when using an sxp_obj (I guess the SR/VDI is always defined when using a xenapi_cfg).

Is this an acceptable idea ?

I missed a lot of things reading the code, so someone might want to check this is not too horrible and doesn't break anything.

Cheers,
Pascal

Signature · 2 lines
\o/   Pascal Bouchareine - Gandi 
 g    0170393757           15, place de la Nation - 75011 Paris      
tools/python/xen/xend/XendConfig.py +21 -0
diff -r aee991c7723a tools/python/xen/xend/XendConfig.py
@@ -27,6 +27,7 @@ from xen.xend.XendDevices import XendDev
 from xen.xend.XendDevices import XendDevices
 from xen.xend.PrettyPrint import prettyprintstring
 from xen.xend.XendConstants import DOM_STATE_HALTED
+from xen.xend import XendNode
 
 log = logging.getLogger("xend.XendConfig")
 log.setLevel(logging.WARN)
@@ -981,6 +982,26 @@ class XendConfig(dict):
                 dev_uuid = uuid.createString()
             dev_info['uuid'] = dev_uuid
 
+            if dev_type in ('vbd', 'tap') and not dev_info.get('VDI'):
+                xennode = XendNode.instance()
+                sr_name = dev_info.get('SR', 'Local')
+                sr_matching = xennode.get_sr_by_name(sr_name)
+                if len(sr_matching):
+                    sr_ref = sr_matching[0]
+                    sr = xennode.srs[sr_ref]
+                    for vdi_ref in sr.get_vdis():
+                        vdi = sr.get_vdi_by_uuid(vdi_ref)
+                        if vdi.get_location() == dev_info['uname']:
+                            vdi.addVBD(dev_info['uuid'])
+                            dev_info['VDI'] = vdi_ref 
+
+                    if not dev_info.get('VDI'):
+                        vdi_ref = sr.create_vdi({'other_config': 
+                                       {'location':dev_info['uname']}})
+                        vdi = sr.get_vdi_by_uuid(vdi_ref)
+                        vdi.addVBD(dev_info['uuid'])
+                        dev_info['VDI'] = vdi_ref
+
             # store dev references by uuid for certain device types
             target['devices'][dev_uuid] = (dev_type, dev_info)
             if dev_type in ('vif', 'vbd', 'vtpm'):

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel