Blob Blame History Raw
diff -uNr a/fence/agents/compute/fence_compute.py b/fence/agents/compute/fence_compute.py
--- a/fence/agents/compute/fence_compute.py	2016-06-02 13:10:27.846973373 +0200
+++ b/fence/agents/compute/fence_compute.py	2016-06-02 13:11:47.642169455 +0200
@@ -89,7 +89,8 @@
 	# Since the detailed view for all flavors doesn't provide the extra specs,
 	# we need to call each of the flavor to get them.
 	for flavor in flavors:
-		if flavor.get_keys().get(EVACUABLE_TAG).strip().lower() in TRUE_TAGS:
+		tag = flavor.get_keys().get(EVACUABLE_TAG)
+		if tag.strip().lower() in TRUE_TAGS:
 			result.append(flavor.id)
 	return result
 
@@ -98,23 +99,30 @@
 	images = nova.images.list(detailed=True)
 	for image in images:
 		if hasattr(image, 'metadata'):
-			if image.metadata.get(EVACUABLE_TAG).strip.lower() in TRUE_TAGS:
+			tag = image.metadata.get(EVACUABLE_TAG)
+			if tag and tag.strip().lower() in TRUE_TAGS:
 				result.append(image.id)
 	return result
 
 def _host_evacuate(options):
 	result = True
+	images = _get_evacuable_images()
+	flavors = _get_evacuable_flavors()
 	servers = nova.servers.list(search_opts={'host': options["--plug"], 'all_tenants': 1 })
+
 	if options["--instance-filtering"] == "False":
-		logging.debug("Evacuating all images and flavors")
-		evacuables = servers
-	else:
-		logging.debug("Filtering images and flavors")
-		flavors = _get_evacuable_flavors()
-		images = _get_evacuable_images()
+		logging.debug("Not evacuating anything")
+		evacuables = []
+	elif len(flavors) or len(images):
+		logging.debug("Filtering images and flavors: %s %s" % (repr(flavors), repr(images)))
 		# Identify all evacuable servers
+		logging.debug("Checking %s" % repr(servers))
 		evacuables = [server for server in servers
 				if _is_server_evacuable(server, flavors, images)]
+		logging.debug("Evacuating %s" % repr(evacuables))
+	else:
+		logging.debug("Evacuating all images and flavors")
+		evacuables = servers
 
 	if options["--no-shared-storage"] != "False":
 		on_shared_storage = False
@@ -267,10 +275,10 @@
 	all_opt["instance-filtering"] = {
 		"getopt" : "",
 		"longopt" : "instance-filtering",
-		"help" : "--instance-filtering           Only evacuate instances create from images and flavors with evacuable=true",
+		"help" : "--instance-filtering           Allow instances created from images and flavors with evacuable=true to be evacuated (or all if no images/flavors have been tagged)",
 		"required" : "0",
-		"shortdesc" : "Only evacuate flagged instances",
-		"default" : "False",
+		"shortdesc" : "Allow instances to be evacuated",
+		"default" : "True",
 		"order": 5,
 	}
 	all_opt["no-shared-storage"] = {
diff -uNr a/tests/data/metadata/fence_compute.xml b/tests/data/metadata/fence_compute.xml
--- a/tests/data/metadata/fence_compute.xml	2016-06-02 13:10:27.830973534 +0200
+++ b/tests/data/metadata/fence_compute.xml	2016-06-02 13:11:47.642169455 +0200
@@ -50,8 +50,8 @@
 	</parameter>
 	<parameter name="instance-filtering" unique="0" required="0">
 		<getopt mixed="--instance-filtering" />
-		<content type="boolean" default="False"  />
-		<shortdesc lang="en">Only evacuate flagged instances</shortdesc>
+		<content type="boolean" default="True"  />
+		<shortdesc lang="en">Allow instances to be evacuated</shortdesc>
 	</parameter>
 	<parameter name="no-shared-storage" unique="0" required="0">
 		<getopt mixed="--no-shared-storage" />