Blame SOURCES/bz1969953-fence_gce-1-add-proxy-support.patch

0ed125
diff --color -uNr a/agents/gce/fence_gce.py b/agents/gce/fence_gce.py
0ed125
--- a/agents/gce/fence_gce.py	2021-06-11 14:57:01.138390529 +0200
0ed125
+++ b/agents/gce/fence_gce.py	2021-06-11 15:12:45.829855806 +0200
0ed125
@@ -1,6 +1,7 @@
0ed125
 #!@PYTHON@ -tt
0ed125
 
0ed125
 import atexit
0ed125
+import httplib2
0ed125
 import logging
0ed125
 import os
0ed125
 import sys
0ed125
@@ -18,6 +19,7 @@
0ed125
 from fencing import fail_usage, run_delay, all_opt, atexit_handler, check_input, process_input, show_docs, fence_action
0ed125
 try:
0ed125
   import googleapiclient.discovery
0ed125
+  import socks
0ed125
   try:
0ed125
     from google.oauth2.credentials import Credentials as GoogleCredentials
0ed125
   except:
0ed125
@@ -189,13 +191,30 @@
0ed125
 		"required" : "0",
0ed125
 		"order" : 9
0ed125
 	}
0ed125
+	all_opt["proxyhost"] = {
0ed125
+		"getopt" : ":",
0ed125
+		"longopt" : "proxyhost",
0ed125
+		"help" : "--proxyhost=[proxy_host]       The proxy host to use, if one is needed to access the internet (Example: 10.122.0.33)",
0ed125
+		"shortdesc" : "If a proxy is used for internet access, the proxy host should be specified.",
0ed125
+		"required" : "0",
0ed125
+		"order" : 10
0ed125
+	}
0ed125
+	all_opt["proxyport"] = {
0ed125
+		"getopt" : ":",
0ed125
+		"type" : "integer",
0ed125
+		"longopt" : "proxyport",
0ed125
+		"help" : "--proxyport=[proxy_port]       The proxy port to use, if one is needed to access the internet (Example: 3127)",
0ed125
+		"shortdesc" : "If a proxy is used for internet access, the proxy port should be specified.",
0ed125
+		"required" : "0",
0ed125
+		"order" : 11
0ed125
+	}
0ed125
 
0ed125
 
0ed125
 def main():
0ed125
 	conn = None
0ed125
 
0ed125
 	device_opt = ["port", "no_password", "zone", "project", "stackdriver-logging",
0ed125
-		"method", "serviceaccount"]
0ed125
+		"method", "serviceaccount", "proxyhost", "proxyport"]
0ed125
 
0ed125
 	atexit.register(atexit_handler)
0ed125
 
0ed125
@@ -259,7 +278,17 @@
0ed125
 				credentials = GoogleCredentials.get_application_default()
0ed125
 			logging.debug("using application default credentials")
0ed125
 
0ed125
-		conn = googleapiclient.discovery.build('compute', 'v1', credentials=credentials)
0ed125
+		if options.get("--proxyhost") and options.get("--proxyport"):
0ed125
+			proxy_info = httplib2.ProxyInfo(
0ed125
+				proxy_type=socks.PROXY_TYPE_HTTP,
0ed125
+				proxy_host=options.get("--proxyhost"),
0ed125
+				proxy_port=int(options.get("--proxyport")))
0ed125
+			http = credentials.authorize(httplib2.Http(proxy_info=proxy_info))
0ed125
+			conn = googleapiclient.discovery.build(
0ed125
+				'compute', 'v1', http=http, cache_discovery=False)
0ed125
+		else:
0ed125
+			conn = googleapiclient.discovery.build(
0ed125
+				'compute', 'v1', credentials=credentials, cache_discovery=False)
0ed125
 	except Exception as err:
0ed125
 		fail_usage("Failed: Create GCE compute v1 connection: {}".format(str(err)))
0ed125