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

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