From 25e5509d0e83c5675768de8b4a1d824494180024 Mon Sep 17 00:00:00 2001 From: Mate Lakat Date: Tue, 5 Feb 2013 13:11:50 +0000 Subject: [PATCH] XenAPINFS: Copy volume to glance 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 | 28 ++++++++++++++++++++++++++++ cinder/volume/drivers/xenapi/sm.py | 18 +++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/cinder/volume/drivers/xenapi/lib.py b/cinder/volume/drivers/xenapi/lib.py index 8620d33a6..2f309f8be 100644 --- a/cinder/volume/drivers/xenapi/lib.py +++ b/cinder/volume/drivers/xenapi/lib.py @@ -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) diff --git a/cinder/volume/drivers/xenapi/sm.py b/cinder/volume/drivers/xenapi/sm.py index 042a62717..b152b513a 100644 --- a/cinder/volume/drivers/xenapi/sm.py +++ b/cinder/volume/drivers/xenapi/sm.py @@ -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) -- 2.45.2