Blame SOURCES/fence_gce-1-stackdriver-logging-default-method-cycle.patch

21d5fd
From 59ae9d00060da5329d7ca538974498292bbe1d91 Mon Sep 17 00:00:00 2001
21d5fd
From: Helen Koike <helen.koike@collabora.com>
21d5fd
Date: Tue, 26 Jun 2018 10:18:29 -0300
21d5fd
Subject: [PATCH 1/7] fence_gce: add support for stackdriver logging
21d5fd
21d5fd
Add --logging option to enable sending logs to google stackdriver
21d5fd
---
21d5fd
 agents/gce/fence_gce.py           | 65 +++++++++++++++++++++++++++++++++++++--
21d5fd
 tests/data/metadata/fence_gce.xml |  5 +++
21d5fd
 2 files changed, 67 insertions(+), 3 deletions(-)
21d5fd
21d5fd
diff --git a/agents/gce/fence_gce.py b/agents/gce/fence_gce.py
21d5fd
index 3abb5207..3af5bfc8 100644
21d5fd
--- a/agents/gce/fence_gce.py
21d5fd
+++ b/agents/gce/fence_gce.py
21d5fd
@@ -1,12 +1,19 @@
21d5fd
 #!@PYTHON@ -tt
21d5fd
 
21d5fd
 import atexit
21d5fd
+import logging
21d5fd
+import platform
21d5fd
 import sys
21d5fd
+import time
21d5fd
 sys.path.append("@FENCEAGENTSLIBDIR@")
21d5fd
 
21d5fd
 import googleapiclient.discovery
21d5fd
 from fencing import fail_usage, run_delay, all_opt, atexit_handler, check_input, process_input, show_docs, fence_action
21d5fd
 
21d5fd
+
21d5fd
+LOGGER = logging
21d5fd
+
21d5fd
+
21d5fd
 def translate_status(instance_status):
21d5fd
 	"Returns on | off | unknown."
21d5fd
 	if instance_status == "RUNNING":
21d5fd
@@ -27,6 +34,7 @@ def get_nodes_list(conn, options):
21d5fd
 
21d5fd
 	return result
21d5fd
 
21d5fd
+
21d5fd
 def get_power_status(conn, options):
21d5fd
 	try:
21d5fd
 		instance = conn.instances().get(
21d5fd
@@ -38,18 +46,37 @@ def get_power_status(conn, options):
21d5fd
 		fail_usage("Failed: get_power_status: {}".format(str(err)))
21d5fd
 
21d5fd
 
21d5fd
+def wait_for_operation(conn, project, zone, operation):
21d5fd
+	while True:
21d5fd
+		result = conn.zoneOperations().get(
21d5fd
+			project=project,
21d5fd
+			zone=zone,
21d5fd
+			operation=operation['name']).execute()
21d5fd
+		if result['status'] == 'DONE':
21d5fd
+			if 'error' in result:
21d5fd
+				raise Exception(result['error'])
21d5fd
+			return
21d5fd
+		time.sleep(1)
21d5fd
+
21d5fd
+
21d5fd
 def set_power_status(conn, options):
21d5fd
 	try:
21d5fd
 		if options["--action"] == "off":
21d5fd
-			conn.instances().stop(
21d5fd
+			LOGGER.info("Issuing poweroff of %s in zone %s" % (options["--plug"], options["--zone"]))
21d5fd
+			operation = conn.instances().stop(
21d5fd
 					project=options["--project"],
21d5fd
 					zone=options["--zone"],
21d5fd
 					instance=options["--plug"]).execute()
21d5fd
+			wait_for_operation(conn, options["--project"], options["--zone"], operation)
21d5fd
+			LOGGER.info("Poweroff of %s in zone %s complete" % (options["--plug"], options["--zone"]))
21d5fd
 		elif options["--action"] == "on":
21d5fd
-			conn.instances().start(
21d5fd
+			LOGGER.info("Issuing poweron of %s in zone %s" % (options["--plug"], options["--zone"]))
21d5fd
+			operation = conn.instances().start(
21d5fd
 					project=options["--project"],
21d5fd
 					zone=options["--zone"],
21d5fd
 					instance=options["--plug"]).execute()
21d5fd
+			wait_for_operation(conn, options["--project"], options["--zone"], operation)
21d5fd
+			LOGGER.info("Poweron of %s in zone %s complete" % (options["--plug"], options["--zone"]))
21d5fd
 	except Exception as err:
21d5fd
 		fail_usage("Failed: set_power_status: {}".format(str(err)))
21d5fd
 
21d5fd
@@ -71,11 +98,24 @@ def define_new_opts():
21d5fd
 		"required" : "1",
21d5fd
 		"order" : 3
21d5fd
 	}
21d5fd
+	all_opt["logging"] = {
21d5fd
+		"getopt" : ":",
21d5fd
+		"longopt" : "logging",
21d5fd
+		"help" : "--logging=[bool]               Logging, true/false",
21d5fd
+		"shortdesc" : "Stackdriver-logging support.",
21d5fd
+		"longdesc" : "If enabled (set to true), IP failover logs will be posted to stackdriver logging.",
21d5fd
+		"required" : "0",
21d5fd
+		"default" : "false",
21d5fd
+		"order" : 4
21d5fd
+	}
21d5fd
 
21d5fd
 def main():
21d5fd
 	conn = None
21d5fd
+	global LOGGER
21d5fd
+
21d5fd
+	hostname = platform.node()
21d5fd
 
21d5fd
-	device_opt = ["port", "no_password", "zone", "project"]
21d5fd
+	device_opt = ["port", "no_password", "zone", "project", "logging"]
21d5fd
 
21d5fd
 	atexit.register(atexit_handler)
21d5fd
 
21d5fd
@@ -97,6 +137,25 @@ def main():
21d5fd
 
21d5fd
 	run_delay(options)
21d5fd
 
21d5fd
+	# Prepare logging
21d5fd
+	logging_env = options.get('--logging')
21d5fd
+	if logging_env:
21d5fd
+		logging_env = logging_env.lower()
21d5fd
+		if any(x in logging_env for x in ['yes', 'true', 'enabled']):
21d5fd
+			try:
21d5fd
+				import google.cloud.logging.handlers
21d5fd
+				client = google.cloud.logging.Client()
21d5fd
+				handler = google.cloud.logging.handlers.CloudLoggingHandler(client, name=hostname)
21d5fd
+				formatter = logging.Formatter('gcp:stonish "%(message)s"')
21d5fd
+				LOGGER = logging.getLogger(hostname)
21d5fd
+				handler.setFormatter(formatter)
21d5fd
+				LOGGER.addHandler(handler)
21d5fd
+				LOGGER.setLevel(logging.INFO)
21d5fd
+			except ImportError:
21d5fd
+				LOGGER.error('Couldn\'t import google.cloud.logging, '
21d5fd
+					'disabling Stackdriver-logging support')
21d5fd
+
21d5fd
+	# Prepare cli
21d5fd
 	try:
21d5fd
 		credentials = None
21d5fd
 		if tuple(googleapiclient.__version__) < tuple("1.6.0"):
21d5fd
diff --git a/tests/data/metadata/fence_gce.xml b/tests/data/metadata/fence_gce.xml
21d5fd
index 2a147f21..805ecc6b 100644
21d5fd
--- a/tests/data/metadata/fence_gce.xml
21d5fd
+++ b/tests/data/metadata/fence_gce.xml
21d5fd
@@ -30,6 +30,11 @@ For instructions see: https://cloud.google.com/compute/docs/tutorials/python-gui
21d5fd
 		<content type="string"  />
21d5fd
 		<shortdesc lang="en">Project ID.</shortdesc>
21d5fd
 	</parameter>
21d5fd
+	<parameter name="logging" unique="0" required="0">
21d5fd
+		<getopt mixed="--logging=[bool]" />
21d5fd
+		<content type="string" default="false"  />
21d5fd
+		<shortdesc lang="en">Stackdriver-logging support.</shortdesc>
21d5fd
+	</parameter>
21d5fd
 	<parameter name="quiet" unique="0" required="0">
21d5fd
 		<getopt mixed="-q, --quiet" />
21d5fd
 		<content type="boolean"  />
21d5fd
21d5fd
From bb34acd8b0b150599c393d56dd81a7d8185b27d3 Mon Sep 17 00:00:00 2001
21d5fd
From: Helen Koike <helen.koike@collabora.com>
21d5fd
Date: Tue, 26 Jun 2018 10:44:41 -0300
21d5fd
Subject: [PATCH 2/7] fence_gce: set project and zone as not required
21d5fd
21d5fd
Try to retrieve the GCE project if the script is being executed inside a
21d5fd
GCE machine if --project is not provided.
21d5fd
Try to retrieve the zone automatically from GCE if --zone is not
21d5fd
provided.
21d5fd
---
21d5fd
 agents/gce/fence_gce.py           | 63 +++++++++++++++++++++++++++++++++++++--
21d5fd
 tests/data/metadata/fence_gce.xml |  4 +--
21d5fd
 2 files changed, 63 insertions(+), 4 deletions(-)
21d5fd
21d5fd
diff --git a/agents/gce/fence_gce.py b/agents/gce/fence_gce.py
21d5fd
index 3af5bfc8..e53dc5a6 100644
21d5fd
--- a/agents/gce/fence_gce.py
21d5fd
+++ b/agents/gce/fence_gce.py
21d5fd
@@ -12,6 +12,8 @@
21d5fd
 
21d5fd
 
21d5fd
 LOGGER = logging
21d5fd
+METADATA_SERVER = 'http://metadata.google.internal/computeMetadata/v1/'
21d5fd
+METADATA_HEADERS = {'Metadata-Flavor': 'Google'}
21d5fd
 
21d5fd
 
21d5fd
 def translate_status(instance_status):
21d5fd
@@ -81,13 +83,56 @@ def set_power_status(conn, options):
21d5fd
 		fail_usage("Failed: set_power_status: {}".format(str(err)))
21d5fd
 
21d5fd
 
21d5fd
+def get_instance(conn, project, zone, instance):
21d5fd
+	request = conn.instances().get(
21d5fd
+			project=project, zone=zone, instance=instance)
21d5fd
+	return request.execute()
21d5fd
+
21d5fd
+
21d5fd
+def get_zone(conn, project, instance):
21d5fd
+	request = conn.instances().aggregatedList(project=project)
21d5fd
+	while request is not None:
21d5fd
+		response = request.execute()
21d5fd
+		zones = response.get('items', {})
21d5fd
+		for zone in zones.values():
21d5fd
+			for inst in zone.get('instances', []):
21d5fd
+				if inst['name'] == instance:
21d5fd
+					return inst['zone'].split("/")[-1]
21d5fd
+		request = conn.instances().aggregatedList_next(
21d5fd
+				previous_request=request, previous_response=response)
21d5fd
+	raise Exception("Unable to find instance %s" % (instance))
21d5fd
+
21d5fd
+
21d5fd
+def get_metadata(metadata_key, params=None, timeout=None):
21d5fd
+	"""Performs a GET request with the metadata headers.
21d5fd
+
21d5fd
+	Args:
21d5fd
+		metadata_key: string, the metadata to perform a GET request on.
21d5fd
+		params: dictionary, the query parameters in the GET request.
21d5fd
+		timeout: int, timeout in seconds for metadata requests.
21d5fd
+
21d5fd
+	Returns:
21d5fd
+		HTTP response from the GET request.
21d5fd
+
21d5fd
+	Raises:
21d5fd
+		urlerror.HTTPError: raises when the GET request fails.
21d5fd
+	"""
21d5fd
+	timeout = timeout or 60
21d5fd
+	metadata_url = os.path.join(METADATA_SERVER, metadata_key)
21d5fd
+	params = urlparse.urlencode(params or {})
21d5fd
+	url = '%s?%s' % (metadata_url, params)
21d5fd
+	request = urlrequest.Request(url, headers=METADATA_HEADERS)
21d5fd
+	request_opener = urlrequest.build_opener(urlrequest.ProxyHandler({}))
21d5fd
+	return request_opener.open(request, timeout=timeout * 1.1).read()
21d5fd
+
21d5fd
+
21d5fd
 def define_new_opts():
21d5fd
 	all_opt["zone"] = {
21d5fd
 		"getopt" : ":",
21d5fd
 		"longopt" : "zone",
21d5fd
 		"help" : "--zone=[name]                  Zone, e.g. us-central1-b",
21d5fd
 		"shortdesc" : "Zone.",
21d5fd
-		"required" : "1",
21d5fd
+		"required" : "0",
21d5fd
 		"order" : 2
21d5fd
 	}
21d5fd
 	all_opt["project"] = {
21d5fd
@@ -95,7 +140,7 @@ def define_new_opts():
21d5fd
 		"longopt" : "project",
21d5fd
 		"help" : "--project=[name]               Project ID",
21d5fd
 		"shortdesc" : "Project ID.",
21d5fd
-		"required" : "1",
21d5fd
+		"required" : "0",
21d5fd
 		"order" : 3
21d5fd
 	}
21d5fd
 	all_opt["logging"] = {
21d5fd
@@ -109,6 +154,7 @@ def define_new_opts():
21d5fd
 		"order" : 4
21d5fd
 	}
21d5fd
 
21d5fd
+
21d5fd
 def main():
21d5fd
 	conn = None
21d5fd
 	global LOGGER
21d5fd
@@ -165,6 +211,19 @@ def main():
21d5fd
 	except Exception as err:
21d5fd
 		fail_usage("Failed: Create GCE compute v1 connection: {}".format(str(err)))
21d5fd
 
21d5fd
+	# Get project and zone
21d5fd
+	if not options.get("--project"):
21d5fd
+		try:
21d5fd
+			options["--project"] = get_metadata('project/project-id')
21d5fd
+		except Exception as err:
21d5fd
+			fail_usage("Failed retrieving GCE project. Please provide --project option: {}".format(str(err)))
21d5fd
+
21d5fd
+	if not options.get("--zone"):
21d5fd
+		try:
21d5fd
+			options["--zone"] = get_zone(conn, options['--project'], options['--plug'])
21d5fd
+		except Exception as err:
21d5fd
+			fail_usage("Failed retrieving GCE zone. Please provide --zone option: {}".format(str(err)))
21d5fd
+
21d5fd
 	# Operate the fencing device
21d5fd
 	result = fence_action(conn, options, set_power_status, get_power_status, get_nodes_list)
21d5fd
 	sys.exit(result)
21d5fd
diff --git a/tests/data/metadata/fence_gce.xml b/tests/data/metadata/fence_gce.xml
21d5fd
index 805ecc6b..507b8385 100644
21d5fd
--- a/tests/data/metadata/fence_gce.xml
21d5fd
+++ b/tests/data/metadata/fence_gce.xml
21d5fd
@@ -20,12 +20,12 @@ For instructions see: https://cloud.google.com/compute/docs/tutorials/python-gui
21d5fd
 		<content type="string"  />
21d5fd
 		<shortdesc lang="en">Physical plug number on device, UUID or identification of machine</shortdesc>
21d5fd
 	</parameter>
21d5fd
-	<parameter name="zone" unique="0" required="1">
21d5fd
+	<parameter name="zone" unique="0" required="0">
21d5fd
 		<getopt mixed="--zone=[name]" />
21d5fd
 		<content type="string"  />
21d5fd
 		<shortdesc lang="en">Zone.</shortdesc>
21d5fd
 	</parameter>
21d5fd
-	<parameter name="project" unique="0" required="1">
21d5fd
+	<parameter name="project" unique="0" required="0">
21d5fd
 		<getopt mixed="--project=[name]" />
21d5fd
 		<content type="string"  />
21d5fd
 		<shortdesc lang="en">Project ID.</shortdesc>
21d5fd
21d5fd
From 8ae1af8068d1718a861a25bf954e14392384fa55 Mon Sep 17 00:00:00 2001
21d5fd
From: Helen Koike <helen.koike@collabora.com>
21d5fd
Date: Wed, 4 Jul 2018 09:25:46 -0300
21d5fd
Subject: [PATCH 3/7] fence_gce: add power cycle as default method
21d5fd
21d5fd
Add function to power cycle an instance and set cycle as the default
21d5fd
method to reboot.
21d5fd
---
21d5fd
 agents/gce/fence_gce.py           | 21 +++++++++++++++++++--
21d5fd
 tests/data/metadata/fence_gce.xml |  8 ++++++++
21d5fd
 2 files changed, 27 insertions(+), 2 deletions(-)
21d5fd
21d5fd
diff --git a/agents/gce/fence_gce.py b/agents/gce/fence_gce.py
21d5fd
index e53dc5a6..3f77dc24 100644
21d5fd
--- a/agents/gce/fence_gce.py
21d5fd
+++ b/agents/gce/fence_gce.py
21d5fd
@@ -83,6 +83,21 @@ def set_power_status(conn, options):
21d5fd
 		fail_usage("Failed: set_power_status: {}".format(str(err)))
21d5fd
 
21d5fd
 
21d5fd
+def power_cycle(conn, options):
21d5fd
+	try:
21d5fd
+		LOGGER.info('Issuing reset of %s in zone %s' % (options["--plug"], options["--zone"]))
21d5fd
+		operation = conn.instances().reset(
21d5fd
+				project=options["--project"],
21d5fd
+				zone=options["--zone"],
21d5fd
+				instance=options["--plug"]).execute()
21d5fd
+		wait_for_operation(conn, options["--project"], options["--zone"], operation)
21d5fd
+		LOGGER.info('Reset of %s in zone %s complete' % (options["--plug"], options["--zone"]))
21d5fd
+		return True
21d5fd
+	except Exception as err:
21d5fd
+		LOGGER.error("Failed: power_cycle: {}".format(str(err)))
21d5fd
+		return False
21d5fd
+
21d5fd
+
21d5fd
 def get_instance(conn, project, zone, instance):
21d5fd
 	request = conn.instances().get(
21d5fd
 			project=project, zone=zone, instance=instance)
21d5fd
@@ -161,13 +176,15 @@ def main():
21d5fd
 
21d5fd
 	hostname = platform.node()
21d5fd
 
21d5fd
-	device_opt = ["port", "no_password", "zone", "project", "logging"]
21d5fd
+	device_opt = ["port", "no_password", "zone", "project", "logging", "method"]
21d5fd
 
21d5fd
 	atexit.register(atexit_handler)
21d5fd
 
21d5fd
 	define_new_opts()
21d5fd
 
21d5fd
 	all_opt["power_timeout"]["default"] = "60"
21d5fd
+	all_opt["method"]["default"] = "cycle"
21d5fd
+	all_opt["method"]["help"] = "-m, --method=[method]          Method to fence (onoff|cycle) (Default: cycle)"
21d5fd
 
21d5fd
 	options = check_input(device_opt, process_input(device_opt))
21d5fd
 
21d5fd
@@ -225,7 +242,7 @@ def main():
21d5fd
 			fail_usage("Failed retrieving GCE zone. Please provide --zone option: {}".format(str(err)))
21d5fd
 
21d5fd
 	# Operate the fencing device
21d5fd
-	result = fence_action(conn, options, set_power_status, get_power_status, get_nodes_list)
21d5fd
+	result = fence_action(conn, options, set_power_status, get_power_status, get_nodes_list, power_cycle)
21d5fd
 	sys.exit(result)
21d5fd
 
21d5fd
 if __name__ == "__main__":
21d5fd
diff --git a/tests/data/metadata/fence_gce.xml b/tests/data/metadata/fence_gce.xml
21d5fd
index 507b8385..f522550f 100644
21d5fd
--- a/tests/data/metadata/fence_gce.xml
21d5fd
+++ b/tests/data/metadata/fence_gce.xml
21d5fd
@@ -10,6 +10,14 @@ For instructions see: https://cloud.google.com/compute/docs/tutorials/python-gui
21d5fd
 		<content type="string" default="reboot"  />
21d5fd
 		<shortdesc lang="en">Fencing action</shortdesc>
21d5fd
 	</parameter>
21d5fd
+	<parameter name="method" unique="0" required="0">
21d5fd
+		<getopt mixed="-m, --method=[method]" />
21d5fd
+		<content type="select" default="cycle"  >
21d5fd
+			<option value="onoff" />
21d5fd
+			<option value="cycle" />
21d5fd
+		</content>
21d5fd
+		<shortdesc lang="en">Method to fence</shortdesc>
21d5fd
+	</parameter>
21d5fd
 	<parameter name="plug" unique="0" required="1" obsoletes="port">
21d5fd
 		<getopt mixed="-n, --plug=[id]" />
21d5fd
 		<content type="string"  />
21d5fd
21d5fd
From 68644764695b79a3b75826fe009ea7da675677f7 Mon Sep 17 00:00:00 2001
21d5fd
From: Helen Koike <helen.koike@collabora.com>
21d5fd
Date: Thu, 5 Jul 2018 11:04:32 -0300
21d5fd
Subject: [PATCH 4/7] fence_gce: add missing imports to retrieve the project
21d5fd
21d5fd
---
21d5fd
 agents/gce/fence_gce.py | 9 +++++++++
21d5fd
 1 file changed, 9 insertions(+)
21d5fd
21d5fd
diff --git a/agents/gce/fence_gce.py b/agents/gce/fence_gce.py
21d5fd
index 3f77dc24..9b7b5e55 100644
21d5fd
--- a/agents/gce/fence_gce.py
21d5fd
+++ b/agents/gce/fence_gce.py
21d5fd
@@ -2,9 +2,18 @@
21d5fd
 
21d5fd
 import atexit
21d5fd
 import logging
21d5fd
+import os
21d5fd
 import platform
21d5fd
 import sys
21d5fd
 import time
21d5fd
+if sys.version_info >= (3, 0):
21d5fd
+  # Python 3 imports.
21d5fd
+  import urllib.parse as urlparse
21d5fd
+  import urllib.request as urlrequest
21d5fd
+else:
21d5fd
+  # Python 2 imports.
21d5fd
+  import urllib as urlparse
21d5fd
+  import urllib2 as urlrequest
21d5fd
 sys.path.append("@FENCEAGENTSLIBDIR@")
21d5fd
 
21d5fd
 import googleapiclient.discovery
21d5fd
21d5fd
From f8f3f11187341622c26e4e439dfda6a37ad660b0 Mon Sep 17 00:00:00 2001
21d5fd
From: Helen Koike <helen.koike@collabora.com>
21d5fd
Date: Thu, 5 Jul 2018 11:05:32 -0300
21d5fd
Subject: [PATCH 5/7] fence_gce: s/--loging/--stackdriver-logging/
21d5fd
21d5fd
---
21d5fd
 agents/gce/fence_gce.py           | 42 ++++++++++++++++++---------------------
21d5fd
 tests/data/metadata/fence_gce.xml | 11 +++++++---
21d5fd
 2 files changed, 27 insertions(+), 26 deletions(-)
21d5fd
21d5fd
diff --git a/agents/gce/fence_gce.py b/agents/gce/fence_gce.py
21d5fd
index 9b7b5e55..a6befe39 100644
21d5fd
--- a/agents/gce/fence_gce.py
21d5fd
+++ b/agents/gce/fence_gce.py
21d5fd
@@ -167,14 +167,13 @@ def define_new_opts():
21d5fd
 		"required" : "0",
21d5fd
 		"order" : 3
21d5fd
 	}
21d5fd
-	all_opt["logging"] = {
21d5fd
-		"getopt" : ":",
21d5fd
-		"longopt" : "logging",
21d5fd
-		"help" : "--logging=[bool]               Logging, true/false",
21d5fd
+	all_opt["stackdriver-logging"] = {
21d5fd
+		"getopt" : "",
21d5fd
+		"longopt" : "stackdriver-logging",
21d5fd
+		"help" : "--stackdriver-logging		Enable Logging to Stackdriver",
21d5fd
 		"shortdesc" : "Stackdriver-logging support.",
21d5fd
-		"longdesc" : "If enabled (set to true), IP failover logs will be posted to stackdriver logging.",
21d5fd
+		"longdesc" : "If enabled IP failover logs will be posted to stackdriver logging.",
21d5fd
 		"required" : "0",
21d5fd
-		"default" : "false",
21d5fd
 		"order" : 4
21d5fd
 	}
21d5fd
 
21d5fd
@@ -185,7 +184,7 @@ def main():
21d5fd
 
21d5fd
 	hostname = platform.node()
21d5fd
 
21d5fd
-	device_opt = ["port", "no_password", "zone", "project", "logging", "method"]
21d5fd
+	device_opt = ["port", "no_password", "zone", "project", "stackdriver-logging", "method"]
21d5fd
 
21d5fd
 	atexit.register(atexit_handler)
21d5fd
 
21d5fd
@@ -210,22 +209,19 @@ def main():
21d5fd
 	run_delay(options)
21d5fd
 
21d5fd
 	# Prepare logging
21d5fd
-	logging_env = options.get('--logging')
21d5fd
-	if logging_env:
21d5fd
-		logging_env = logging_env.lower()
21d5fd
-		if any(x in logging_env for x in ['yes', 'true', 'enabled']):
21d5fd
-			try:
21d5fd
-				import google.cloud.logging.handlers
21d5fd
-				client = google.cloud.logging.Client()
21d5fd
-				handler = google.cloud.logging.handlers.CloudLoggingHandler(client, name=hostname)
21d5fd
-				formatter = logging.Formatter('gcp:stonish "%(message)s"')
21d5fd
-				LOGGER = logging.getLogger(hostname)
21d5fd
-				handler.setFormatter(formatter)
21d5fd
-				LOGGER.addHandler(handler)
21d5fd
-				LOGGER.setLevel(logging.INFO)
21d5fd
-			except ImportError:
21d5fd
-				LOGGER.error('Couldn\'t import google.cloud.logging, '
21d5fd
-					'disabling Stackdriver-logging support')
21d5fd
+	if options.get('--stackdriver-logging'):
21d5fd
+		try:
21d5fd
+			import google.cloud.logging.handlers
21d5fd
+			client = google.cloud.logging.Client()
21d5fd
+			handler = google.cloud.logging.handlers.CloudLoggingHandler(client, name=hostname)
21d5fd
+			formatter = logging.Formatter('gcp:stonish "%(message)s"')
21d5fd
+			LOGGER = logging.getLogger(hostname)
21d5fd
+			handler.setFormatter(formatter)
21d5fd
+			LOGGER.addHandler(handler)
21d5fd
+			LOGGER.setLevel(logging.INFO)
21d5fd
+		except ImportError:
21d5fd
+			LOGGER.error('Couldn\'t import google.cloud.logging, '
21d5fd
+				'disabling Stackdriver-logging support')
21d5fd
 
21d5fd
 	# Prepare cli
21d5fd
 	try:
21d5fd
diff --git a/tests/data/metadata/fence_gce.xml b/tests/data/metadata/fence_gce.xml
21d5fd
index f522550f..79b82ebb 100644
21d5fd
--- a/tests/data/metadata/fence_gce.xml
21d5fd
+++ b/tests/data/metadata/fence_gce.xml
21d5fd
@@ -38,9 +38,14 @@ For instructions see: https://cloud.google.com/compute/docs/tutorials/python-gui
21d5fd
 		<content type="string"  />
21d5fd
 		<shortdesc lang="en">Project ID.</shortdesc>
21d5fd
 	</parameter>
21d5fd
-	<parameter name="logging" unique="0" required="0">
21d5fd
-		<getopt mixed="--logging=[bool]" />
21d5fd
-		<content type="string" default="false"  />
21d5fd
+	<parameter name="stackdriver-logging" unique="0" required="0" deprecated="1">
21d5fd
+		<getopt mixed="--stackdriver-logging" />
21d5fd
+		<content type="boolean"  />
21d5fd
+		<shortdesc lang="en">Stackdriver-logging support.</shortdesc>
21d5fd
+	</parameter>
21d5fd
+	<parameter name="stackdriver_logging" unique="0" required="0" obsoletes="stackdriver-logging">
21d5fd
+		<getopt mixed="--stackdriver-logging" />
21d5fd
+		<content type="boolean"  />
21d5fd
 		<shortdesc lang="en">Stackdriver-logging support.</shortdesc>
21d5fd
 	</parameter>
21d5fd
 	<parameter name="quiet" unique="0" required="0">
21d5fd
21d5fd
From 9ae0a072424fa982e1d18a2cb661628c38601c3a Mon Sep 17 00:00:00 2001
21d5fd
From: Helen Koike <helen.koike@collabora.com>
21d5fd
Date: Sat, 7 Jul 2018 18:42:01 -0300
21d5fd
Subject: [PATCH 6/7] fence_gce: use root logger for stackdriver
21d5fd
21d5fd
---
21d5fd
 agents/gce/fence_gce.py | 29 +++++++++++++++--------------
21d5fd
 1 file changed, 15 insertions(+), 14 deletions(-)
21d5fd
21d5fd
diff --git a/agents/gce/fence_gce.py b/agents/gce/fence_gce.py
21d5fd
index a6befe39..1d5095ae 100644
21d5fd
--- a/agents/gce/fence_gce.py
21d5fd
+++ b/agents/gce/fence_gce.py
21d5fd
@@ -20,7 +20,6 @@
21d5fd
 from fencing import fail_usage, run_delay, all_opt, atexit_handler, check_input, process_input, show_docs, fence_action
21d5fd
 
21d5fd
 
21d5fd
-LOGGER = logging
21d5fd
 METADATA_SERVER = 'http://metadata.google.internal/computeMetadata/v1/'
21d5fd
 METADATA_HEADERS = {'Metadata-Flavor': 'Google'}
21d5fd
 
21d5fd
@@ -73,37 +72,37 @@ def wait_for_operation(conn, project, zone, operation):
21d5fd
 def set_power_status(conn, options):
21d5fd
 	try:
21d5fd
 		if options["--action"] == "off":
21d5fd
-			LOGGER.info("Issuing poweroff of %s in zone %s" % (options["--plug"], options["--zone"]))
21d5fd
+			logging.info("Issuing poweroff of %s in zone %s" % (options["--plug"], options["--zone"]))
21d5fd
 			operation = conn.instances().stop(
21d5fd
 					project=options["--project"],
21d5fd
 					zone=options["--zone"],
21d5fd
 					instance=options["--plug"]).execute()
21d5fd
 			wait_for_operation(conn, options["--project"], options["--zone"], operation)
21d5fd
-			LOGGER.info("Poweroff of %s in zone %s complete" % (options["--plug"], options["--zone"]))
21d5fd
+			logging.info("Poweroff of %s in zone %s complete" % (options["--plug"], options["--zone"]))
21d5fd
 		elif options["--action"] == "on":
21d5fd
-			LOGGER.info("Issuing poweron of %s in zone %s" % (options["--plug"], options["--zone"]))
21d5fd
+			logging.info("Issuing poweron of %s in zone %s" % (options["--plug"], options["--zone"]))
21d5fd
 			operation = conn.instances().start(
21d5fd
 					project=options["--project"],
21d5fd
 					zone=options["--zone"],
21d5fd
 					instance=options["--plug"]).execute()
21d5fd
 			wait_for_operation(conn, options["--project"], options["--zone"], operation)
21d5fd
-			LOGGER.info("Poweron of %s in zone %s complete" % (options["--plug"], options["--zone"]))
21d5fd
+			logging.info("Poweron of %s in zone %s complete" % (options["--plug"], options["--zone"]))
21d5fd
 	except Exception as err:
21d5fd
 		fail_usage("Failed: set_power_status: {}".format(str(err)))
21d5fd
 
21d5fd
 
21d5fd
 def power_cycle(conn, options):
21d5fd
 	try:
21d5fd
-		LOGGER.info('Issuing reset of %s in zone %s' % (options["--plug"], options["--zone"]))
21d5fd
+		logging.info('Issuing reset of %s in zone %s' % (options["--plug"], options["--zone"]))
21d5fd
 		operation = conn.instances().reset(
21d5fd
 				project=options["--project"],
21d5fd
 				zone=options["--zone"],
21d5fd
 				instance=options["--plug"]).execute()
21d5fd
 		wait_for_operation(conn, options["--project"], options["--zone"], operation)
21d5fd
-		LOGGER.info('Reset of %s in zone %s complete' % (options["--plug"], options["--zone"]))
21d5fd
+		logging.info('Reset of %s in zone %s complete' % (options["--plug"], options["--zone"]))
21d5fd
 		return True
21d5fd
 	except Exception as err:
21d5fd
-		LOGGER.error("Failed: power_cycle: {}".format(str(err)))
21d5fd
+		logging.error("Failed: power_cycle: {}".format(str(err)))
21d5fd
 		return False
21d5fd
 
21d5fd
 
21d5fd
@@ -180,7 +179,6 @@ def define_new_opts():
21d5fd
 
21d5fd
 def main():
21d5fd
 	conn = None
21d5fd
-	global LOGGER
21d5fd
 
21d5fd
 	hostname = platform.node()
21d5fd
 
21d5fd
@@ -209,18 +207,21 @@ def main():
21d5fd
 	run_delay(options)
21d5fd
 
21d5fd
 	# Prepare logging
21d5fd
-	if options.get('--stackdriver-logging'):
21d5fd
+	if options.get('--stackdriver-logging') is not None:
21d5fd
 		try:
21d5fd
 			import google.cloud.logging.handlers
21d5fd
 			client = google.cloud.logging.Client()
21d5fd
 			handler = google.cloud.logging.handlers.CloudLoggingHandler(client, name=hostname)
21d5fd
+			handler.setLevel(logging.INFO)
21d5fd
 			formatter = logging.Formatter('gcp:stonish "%(message)s"')
21d5fd
-			LOGGER = logging.getLogger(hostname)
21d5fd
 			handler.setFormatter(formatter)
21d5fd
-			LOGGER.addHandler(handler)
21d5fd
-			LOGGER.setLevel(logging.INFO)
21d5fd
+			root_logger = logging.getLogger()
21d5fd
+			if options.get('--verbose') is None:
21d5fd
+				root_logger.setLevel(logging.INFO)
21d5fd
+				logging.getLogger("googleapiclient").setLevel(logging.ERROR)
21d5fd
+			root_logger.addHandler(handler)
21d5fd
 		except ImportError:
21d5fd
-			LOGGER.error('Couldn\'t import google.cloud.logging, '
21d5fd
+			logging.error('Couldn\'t import google.cloud.logging, '
21d5fd
 				'disabling Stackdriver-logging support')
21d5fd
 
21d5fd
 	# Prepare cli
21d5fd
21d5fd
From a52e643708908539d6e5fdb5d36a6cea935e4481 Mon Sep 17 00:00:00 2001
21d5fd
From: Helen Koike <helen.koike@collabora.com>
21d5fd
Date: Wed, 11 Jul 2018 17:16:49 -0300
21d5fd
Subject: [PATCH 7/7] fence_gce: minor changes in logging
21d5fd
21d5fd
- Remove hostname (use --plug instead).
21d5fd
- Supress messages from googleapiclient and oauth2client if not error in
21d5fd
non verbose mode.
21d5fd
- s/stonish/stonith
21d5fd
---
21d5fd
 agents/gce/fence_gce.py | 13 ++++++-------
21d5fd
 1 file changed, 6 insertions(+), 7 deletions(-)
21d5fd
21d5fd
diff --git a/agents/gce/fence_gce.py b/agents/gce/fence_gce.py
21d5fd
index 1d5095ae..3eca0139 100644
21d5fd
--- a/agents/gce/fence_gce.py
21d5fd
+++ b/agents/gce/fence_gce.py
21d5fd
@@ -3,7 +3,6 @@
21d5fd
 import atexit
21d5fd
 import logging
21d5fd
 import os
21d5fd
-import platform
21d5fd
 import sys
21d5fd
 import time
21d5fd
 if sys.version_info >= (3, 0):
21d5fd
@@ -180,8 +179,6 @@ def define_new_opts():
21d5fd
 def main():
21d5fd
 	conn = None
21d5fd
 
21d5fd
-	hostname = platform.node()
21d5fd
-
21d5fd
 	device_opt = ["port", "no_password", "zone", "project", "stackdriver-logging", "method"]
21d5fd
 
21d5fd
 	atexit.register(atexit_handler)
21d5fd
@@ -207,18 +204,20 @@ def main():
21d5fd
 	run_delay(options)
21d5fd
 
21d5fd
 	# Prepare logging
21d5fd
-	if options.get('--stackdriver-logging') is not None:
21d5fd
+	if options.get('--verbose') is None:
21d5fd
+		logging.getLogger('googleapiclient').setLevel(logging.ERROR)
21d5fd
+		logging.getLogger('oauth2client').setLevel(logging.ERROR)
21d5fd
+	if options.get('--stackdriver-logging') is not None and options.get('--plug'):
21d5fd
 		try:
21d5fd
 			import google.cloud.logging.handlers
21d5fd
 			client = google.cloud.logging.Client()
21d5fd
-			handler = google.cloud.logging.handlers.CloudLoggingHandler(client, name=hostname)
21d5fd
+			handler = google.cloud.logging.handlers.CloudLoggingHandler(client, name=options['--plug'])
21d5fd
 			handler.setLevel(logging.INFO)
21d5fd
-			formatter = logging.Formatter('gcp:stonish "%(message)s"')
21d5fd
+			formatter = logging.Formatter('gcp:stonith "%(message)s"')
21d5fd
 			handler.setFormatter(formatter)
21d5fd
 			root_logger = logging.getLogger()
21d5fd
 			if options.get('--verbose') is None:
21d5fd
 				root_logger.setLevel(logging.INFO)
21d5fd
-				logging.getLogger("googleapiclient").setLevel(logging.ERROR)
21d5fd
 			root_logger.addHandler(handler)
21d5fd
 		except ImportError:
21d5fd
 			logging.error('Couldn\'t import google.cloud.logging, '