Blame SOURCES/bz1285523-1-fence_compute-taggable-instance-support.patch

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