@@ -0,0 +1,1960 @@
+%22%22%22%0Adestroy_cached_images.py%0A%0AThis script is used to clean up Glance images that are cached in the SR. By%0Adefault, this script will only cleanup unused cached images.%0A%0AOptions:%0A%0A    --dry_run - Don't actually destroy the VDIs%0A    --all_cached - Destroy all cached images instead of just unused cached%0A                   images.%0A%22%22%22%0Aimport eventlet%0Aeventlet.monkey_patch()%0A%0Aimport os%0Aimport sys%0A%0A# If ../nova/__init__.py exists, add ../ to Python search path, so that%0A# it will override what happens to be installed in /usr/(local/)lib/python...%0APOSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv%5B0%5D),%0A                                   os.pardir,%0A                                   os.pardir,%0A                                   os.pardir))%0Aif os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'nova', '__init__.py')):%0A    sys.path.insert(0, POSSIBLE_TOPDIR)%0A%0Afrom nova import flags%0Afrom nova.openstack.common import cfg%0Afrom nova.openstack.common import log as logging%0Afrom nova import utils%0Afrom nova.virt.xenapi import driver as xenapi_driver%0Afrom nova.virt.xenapi import vm_utils%0A%0AFLAGS = flags.FLAGS%0Adestroy_opts = %5B%0A    cfg.BoolOpt('all_cached',%0A                default=False,%0A                help='Destroy all cached images instead of just unused cached'%0A                     ' images.'),%0A    cfg.BoolOpt('dry_run',%0A                default=False,%0A                help='Don%5C't actually delete the VDIs.')%0A%5D%0A%0AFLAGS.register_cli_opts(destroy_opts)%0A%0A%0Adef main():%0A    flags.parse_args(sys.argv)%0A    utils.monkey_patch()%0A%0A    xenapi = xenapi_driver.XenAPIDriver()%0A    session = xenapi._session%0A%0A    sr_ref = vm_utils.safe_find_sr(session)%0A    destroyed = vm_utils.destroy_cached_images(%0A            session, sr_ref, all_cached=FLAGS.all_cached,%0A            dry_run=FLAGS.dry_run)%0A%0A    if '--verbose' in sys.argv:%0A        print '%5Cn'.join(destroyed)%0A%0A    print %22Destroyed %25d cached VDIs%22 %25 len(destroyed)%0A%0A%0Aif __name__ == %22__main__%22:%0A    main()%0A

Add script to destroy cached images.