]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
XenAPINFS: Copy volume to glance
authorMate Lakat <mate.lakat@citrix.com>
Tue, 5 Feb 2013 13:11:50 +0000 (13:11 +0000)
committerMate Lakat <mate.lakat@citrix.com>
Tue, 5 Feb 2013 18:34:15 +0000 (18:34 +0000)
related to blueprint xenapinfs-glance-integration

This patch enables to upload XenAPINFS backed cinder volumes to glance
by using the nova glance plugin.

Change-Id: Ie41aa6871fec691556b82501ce3bfdf50898471d

cinder/volume/drivers/xenapi/lib.py
cinder/volume/drivers/xenapi/sm.py

index 8620d33a628be42389f5b638f56fa105b69165b8..2f309f8be7ab17bc7894bacb9c2e37e8db8d0b49 100644 (file)
@@ -340,6 +340,19 @@ class GlancePluginProxy(XapiPluginProxy):
             sr_path=sr_path,
             auth_token=auth_token)
 
+    def upload_vhd(self, vdi_uuids, image_id, glance_host, glance_port,
+                   glance_use_ssl, sr_path, auth_token, properties):
+        return self.call(
+            'upload_vhd',
+            vdi_uuids=vdi_uuids,
+            image_id=image_id,
+            glance_host=glance_host,
+            glance_port=glance_port,
+            glance_use_ssl=glance_use_ssl,
+            sr_path=sr_path,
+            auth_token=auth_token,
+            properties=properties)
+
 
 class NFSBasedVolumeOperations(object):
     def __init__(self, session_factory):
@@ -437,3 +450,18 @@ class NFSBasedVolumeOperations(object):
             return False
 
         return True
+
+    def use_glance_plugin_to_upload_volume(self, server, serverpath,
+                                           sr_uuid, vdi_uuid, glance_server,
+                                           image_id, auth_token, sr_base_path):
+        self.connect_volume(server, serverpath, sr_uuid, vdi_uuid)
+
+        vdi_uuids = [vdi_uuid]
+        glance_host, glance_port, glance_use_ssl = glance_server
+
+        try:
+            result = self.glance_plugin.upload_vhd(
+                vdi_uuids, image_id, glance_host, glance_port, glance_use_ssl,
+                os.path.join(sr_base_path, sr_uuid), auth_token, dict())
+        finally:
+            self.disconnect_volume(vdi_uuid)
index 042a6271707ae981993c9f7318376ca112ae5765..b152b513af306787ac2ed7c292aeae1e5c12da4a 100644 (file)
@@ -179,4 +179,20 @@ class XenAPINFSDriver(driver.VolumeDriver):
             volume['size'])
 
     def copy_volume_to_image(self, context, volume, image_service, image_meta):
-        raise NotImplementedError()
+        image_id = image_meta['id']
+
+        sr_uuid, vdi_uuid = volume['provider_location'].split('/')
+
+        api_servers = glance.get_api_servers()
+        glance_server = api_servers.next()
+        auth_token = context.auth_token
+
+        self.nfs_ops.use_glance_plugin_to_upload_volume(
+            FLAGS.xenapi_nfs_server,
+            FLAGS.xenapi_nfs_serverpath,
+            sr_uuid,
+            vdi_uuid,
+            glance_server,
+            image_id,
+            auth_token,
+            FLAGS.xenapi_sr_base_path)