From d731a04b604fb39ffeb4ba05d42664a15de8508c Mon Sep 17 00:00:00 2001 From: Sulochan Acharya Date: Wed, 5 Aug 2015 14:07:54 +0000 Subject: [PATCH] xapi-tools: fixes cache cleaner script Fixes cache cleaner script by removing import of driver and using session directly to call vm_utils. There is no test included for this. Since this is out of nova tree, adding tests is tracked in 1481705 Closes-Bug: #1481693 Change-Id: I25ee22777baecaf64de63a39d19e8f8f514f70b3 --- tools/xenserver/destroy_cached_images.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/xenserver/destroy_cached_images.py b/tools/xenserver/destroy_cached_images.py index 58394850b412..4b7df3579220 100644 --- a/tools/xenserver/destroy_cached_images.py +++ b/tools/xenserver/destroy_cached_images.py @@ -29,7 +29,7 @@ if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'nova', '__init__.py')): from nova import config from nova import utils -from nova.virt.xenapi import driver as xenapi_driver +from nova.virt.xenapi.client import session from nova.virt.xenapi import vm_utils destroy_opts = [ @@ -45,18 +45,26 @@ destroy_opts = [ CONF = cfg.CONF CONF.register_cli_opts(destroy_opts) +CONF.import_opt('connection_url', 'nova.virt.xenapi.driver', + group='xenserver') +CONF.import_opt('connection_username', 'nova.virt.xenapi.driver', + group='xenserver') +CONF.import_opt('connection_password', 'nova.virt.xenapi.driver', + group='xenserver') + def main(): config.parse_args(sys.argv) utils.monkey_patch() - xenapi = xenapi_driver.XenAPIDriver() - session = xenapi._session + _session = session.XenAPISession(CONF.xenserver.connection_url, + CONF.xenserver.connection_username, + CONF.xenserver.connection_password) - sr_ref = vm_utils.safe_find_sr(session) + sr_ref = vm_utils.safe_find_sr(_session) destroyed = vm_utils.destroy_cached_images( - session, sr_ref, all_cached=CONF.all_cached, - dry_run=CONF.dry_run) + _session, sr_ref, all_cached=CONF.all_cached, + dry_run=CONF.dry_run) if '--verbose' in sys.argv: print '\n'.join(destroyed)