summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJosh Kearney <josh@jk0.org>2011-10-10 15:19:25 -0500
committerJosh Kearney <josh@jk0.org>2011-10-10 15:19:25 -0500
commitcf5f055ebb8e7c1ba05e06e71d2a9b13008d21af (patch)
treebaac55251c7c5b5861b0376891a6b95703117ac3 /tools
parent3a4eb1da2f1a159e693ea5d6503c7d50921d6a48 (diff)
downloadnova-cf5f055ebb8e7c1ba05e06e71d2a9b13008d21af.tar.gz
nova-cf5f055ebb8e7c1ba05e06e71d2a9b13008d21af.tar.xz
nova-cf5f055ebb8e7c1ba05e06e71d2a9b13008d21af.zip
Further changes to the cleaner.
Change-Id: Ib11fe18a46e57df3498596a2909879d67e84fdda
Diffstat (limited to 'tools')
-rwxr-xr-xtools/xenserver/vm_vdi_cleaner.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/tools/xenserver/vm_vdi_cleaner.py b/tools/xenserver/vm_vdi_cleaner.py
index dbee01733..24553fd75 100755
--- a/tools/xenserver/vm_vdi_cleaner.py
+++ b/tools/xenserver/vm_vdi_cleaner.py
@@ -27,7 +27,7 @@ from nova import exception
from nova import flags
from nova import utils
-from nova.virt.xenapi import vmops
+from nova.virt import xenapi_conn
flags.DECLARE("resize_confirm_window", "nova.compute.manager")
@@ -130,6 +130,8 @@ def get_instance_id_from_name_label(name_label, template):
def find_orphaned_instances(session, verbose=False):
"""Find and return a list of orphaned instances."""
ctxt = context.get_admin_context()
+ ctxt.read_deleted = True
+
orphaned_instances = []
for vm_rec in _get_applicable_vm_recs(session):
@@ -145,17 +147,23 @@ def find_orphaned_instances(session, verbose=False):
instance = db.api.instance_get(ctxt, instance_id)
except exception.InstanceNotFound:
# NOTE(jk0): Err on the side of caution here. If we don't know
- # anything about the particular instance, print a warning and let
- # the operator handle it manually.
- print >> sys.stderr, "Instance %s not found" % instance_id
+ # anything about the particular instance, ignore it.
+ print_xen_object("INFO: Ignoring VM", vm_rec, indent_level=0,
+ verbose=verbose)
continue
+ # NOTE(jk0): This would be triggered if a VM was deleted but the
+ # actual deletion process failed somewhere along the line.
+ is_active_and_deleting = (instance.vm_state == "active" and
+ instance.task_state == "deleting")
+
# NOTE(jk0): A zombie VM is an instance that is not active and hasn't
# been updated in over the specified period.
is_zombie_vm = (instance.vm_state != "active"
and utils.is_older_than(instance.updated_at,
FLAGS.zombie_instance_updated_at_window))
- if is_zombie_vm:
+
+ if is_active_and_deleting or is_zombie_vm:
orphaned_instances.append(instance)
return orphaned_instances
@@ -163,9 +171,9 @@ def find_orphaned_instances(session, verbose=False):
def cleanup_instance(session, instance):
"""Delete orphaned instances."""
- vmops = VMOps(session)
network_info = None
- vmops.destroy(instance, network_info)
+ connection = xenapi_conn.get_connection(_)
+ connection.destroy(instance, network_info)
def _get_applicable_vm_recs(session):